Web Inspector: Add Heap domain start/stop tracking commands
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Mar 2016 02:06:45 +0000 (02:06 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Mar 2016 02:06:45 +0000 (02:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155190

Reviewed by Brian Burg.

Source/JavaScriptCore:

* inspector/agents/InspectorHeapAgent.cpp:
(Inspector::InspectorHeapAgent::willDestroyFrontendAndBackend):
(Inspector::InspectorHeapAgent::startTracking):
(Inspector::InspectorHeapAgent::stopTracking):
* inspector/agents/InspectorHeapAgent.h:
* inspector/protocol/Heap.json:

Source/WebInspectorUI:

* UserInterface/Protocol/HeapObserver.js:
(WebInspector.HeapObserver.prototype.trackingStart):
(WebInspector.HeapObserver.prototype.trackingComplete):
To be used when we have a HeapAllocationsInstrument and timeline.

LayoutTests:

* inspector/heap/tracking-expected.txt: Added.
* inspector/heap/tracking.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197826 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/heap/tracking-expected.txt [new file with mode: 0644]
LayoutTests/inspector/heap/tracking.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.h
Source/JavaScriptCore/inspector/protocol/Heap.json
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Protocol/HeapObserver.js

index 610f077..f97c98a 100644 (file)
@@ -1,5 +1,15 @@
 2016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Add Heap domain start/stop tracking commands
+        https://bugs.webkit.org/show_bug.cgi?id=155190
+
+        Reviewed by Brian Burg.
+
+        * inspector/heap/tracking-expected.txt: Added.
+        * inspector/heap/tracking.html: Added.
+
+2016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Add a way to create a Heap Snapshot
         https://bugs.webkit.org/show_bug.cgi?id=155188
 
diff --git a/LayoutTests/inspector/heap/tracking-expected.txt b/LayoutTests/inspector/heap/tracking-expected.txt
new file mode 100644 (file)
index 0000000..27d049f
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that Heap.startTracking and Heap.stopTracking trigger trackingStart and trackingComplete events with expected data.
+
+
+== Running test suite: Heap.startTracking and Heap.stopTracking
+-- Running test case: StartAndStopTrackingIncludeSnapshots
+Heap.trackingStart
+PASS: Should have a timestamp when starting.
+PASS: Should have snapshotData when starting.
+Heap.trackingComplete
+PASS: Should have a timestamp when stopping.
+PASS: Should have snapshotData when stopping.
+
diff --git a/LayoutTests/inspector/heap/tracking.html b/LayoutTests/inspector/heap/tracking.html
new file mode 100644 (file)
index 0000000..205b3cb
--- /dev/null
@@ -0,0 +1,38 @@
+<!doctype html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
+<script>
+function test()
+{
+    let suite = ProtocolTest.createAsyncSuite("Heap.startTracking and Heap.stopTracking");
+
+    suite.addTestCase({
+        name: "StartAndStopTrackingIncludeSnapshots",
+        test: function(resolve, reject) {
+            InspectorProtocol.awaitEvent({event: "Heap.trackingStart"}).then((messageObject) => {
+                ProtocolTest.log("Heap.trackingStart");
+                ProtocolTest.expectThat(typeof messageObject.params.timestamp === "number", "Should have a timestamp when starting.");
+                ProtocolTest.expectThat(typeof messageObject.params.snapshotData === "string", "Should have snapshotData when starting.");
+                InspectorProtocol.sendCommand("Heap.stopTracking", {});
+            });
+
+            InspectorProtocol.awaitEvent({event: "Heap.trackingComplete"}).then((messageObject) => {
+                ProtocolTest.log("Heap.trackingComplete");
+                ProtocolTest.expectThat(typeof messageObject.params.timestamp === "number", "Should have a timestamp when stopping.");
+                ProtocolTest.expectThat(typeof messageObject.params.snapshotData === "string", "Should have snapshotData when stopping.");
+                resolve();
+            });
+
+            InspectorProtocol.sendCommand("Heap.startTracking", {});
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests that Heap.startTracking and Heap.stopTracking trigger trackingStart and trackingComplete events with expected data.</p>
+</body>
+</html>
index 0a7a856..352b891 100644 (file)
@@ -1,5 +1,19 @@
 2016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Add Heap domain start/stop tracking commands
+        https://bugs.webkit.org/show_bug.cgi?id=155190
+
+        Reviewed by Brian Burg.
+
+        * inspector/agents/InspectorHeapAgent.cpp:
+        (Inspector::InspectorHeapAgent::willDestroyFrontendAndBackend):
+        (Inspector::InspectorHeapAgent::startTracking):
+        (Inspector::InspectorHeapAgent::stopTracking):
+        * inspector/agents/InspectorHeapAgent.h:
+        * inspector/protocol/Heap.json:
+
+2016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Add a way to create a Heap Snapshot
         https://bugs.webkit.org/show_bug.cgi?id=155188
 
index 5bc3c24..6b49ea1 100644 (file)
@@ -56,6 +56,7 @@ void InspectorHeapAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDis
 void InspectorHeapAgent::willDestroyFrontendAndBackend(DisconnectReason)
 {
     ErrorString ignored;
+    stopTracking(ignored);
     disable(ignored);
 }
 
@@ -109,6 +110,34 @@ void InspectorHeapAgent::snapshot(ErrorString&, double* timestamp, String* snaps
     });
 }
 
+void InspectorHeapAgent::startTracking(ErrorString& errorString)
+{
+    if (m_tracking)
+        return;
+
+    m_tracking = true;
+
+    double timestamp;
+    String snapshotData;
+    snapshot(errorString, &timestamp, &snapshotData);
+
+    m_frontendDispatcher->trackingStart(timestamp, snapshotData);
+}
+
+void InspectorHeapAgent::stopTracking(ErrorString& errorString)
+{
+    if (!m_tracking)
+        return;
+
+    m_tracking = false;
+
+    double timestamp;
+    String snapshotData;
+    snapshot(errorString, &timestamp, &snapshotData);
+
+    m_frontendDispatcher->trackingComplete(timestamp, snapshotData);
+}
+
 static Inspector::Protocol::Heap::GarbageCollection::Type protocolTypeForHeapOperation(HeapOperation operation)
 {
     switch (operation) {
index e3d8a7d..4ba61f1 100644 (file)
@@ -52,6 +52,8 @@ public:
     void disable(ErrorString&) override;
     void gc(ErrorString&) override;
     void snapshot(ErrorString&, double* timestamp, String* snapshotData) override;
+    void startTracking(ErrorString&) override;
+    void stopTracking(ErrorString&) override;
 
     // HeapObserver
     void willGarbageCollect() override;
@@ -65,6 +67,7 @@ private:
     InspectorEnvironment& m_environment;
 
     bool m_enabled { false };
+    bool m_tracking { false };
     double m_gcStartTime { NAN };
 };
 
index 0e2bae7..28c8aa3 100644 (file)
                 { "name": "timestamp", "type": "number" },
                 { "name": "snapshotData", "$ref": "HeapSnapshotData" }
             ]
+        },
+        {
+            "name": "startTracking",
+            "description": "Start tracking heap changes. This will produce a `trackingStart` event."
+        },
+        {
+            "name": "stopTracking",
+            "description": "Stop tracking heap changes. This will produce a `trackingComplete` event."
         }
     ],
     "events": [
             "parameters": [
                 { "name": "collection", "type": "GarbageCollection" }
             ]
+        },
+        {
+            "name": "trackingStart",
+            "description": "Tracking started.",
+            "parameters": [
+                { "name": "timestamp", "type": "number" },
+                { "name": "snapshotData", "$ref": "HeapSnapshotData", "description": "Snapshot at the start of tracking." }
+            ]
+        },
+        {
+            "name": "trackingComplete",
+            "description": "Tracking stopped.",
+            "parameters": [
+                { "name": "timestamp", "type": "number" },
+                { "name": "snapshotData", "$ref": "HeapSnapshotData", "description": "Snapshot at the end of tracking." }
+            ]
         }
     ]
 }
index 22ede4f..55588b3 100644 (file)
@@ -1,5 +1,17 @@
 2016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Add Heap domain start/stop tracking commands
+        https://bugs.webkit.org/show_bug.cgi?id=155190
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Protocol/HeapObserver.js:
+        (WebInspector.HeapObserver.prototype.trackingStart):
+        (WebInspector.HeapObserver.prototype.trackingComplete):
+        To be used when we have a HeapAllocationsInstrument and timeline.
+
+2016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Make debugging Test.html easier
         https://bugs.webkit.org/show_bug.cgi?id=155207
 
index f04b300..38839f2 100644 (file)
@@ -31,4 +31,18 @@ WebInspector.HeapObserver = class HeapObserver
     {
         WebInspector.heapManager.garbageCollected(collection);
     }
+
+    trackingStart(timestamp, snapshotData)
+    {
+        let payload = JSON.parse(snapshotData);
+        let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+        // FIXME: Heap Allocations Timeline.
+    }
+
+    trackingComplete(timestamp, snapshotData)
+    {
+        let payload = JSON.parse(snapshotData);
+        let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+        // FIXME: Heap Allocations Timeline.
+    }
 };