Web Inspector: Split Profiler domain in protocol into Profiler and HeapProfiler
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2013 13:54:01 +0000 (13:54 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2013 13:54:01 +0000 (13:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108653

Patch by Alexei Filippov <alph@chromium.org> on 2013-02-11
Reviewed by Yury Semikhatsky.

Currently CPU and heap profilers share the same domain 'Profiler' in the protocol.
In fact these two profile types have not too much in common. So put each into its own domain.
It should also help when Profiles panel gets split into several tools.
This is the phase 1 which adds InspectorHeapProfilerAgent but doesn't
change the original InspectorProfilerAgent.

PerformanceTests:

* inspector/heap-snapshot-performance-test.js:
(test.performanceTest.cleanup):

Source/WebCore:

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* inspector/Inspector.json:
* inspector/InspectorAllInOne.cpp:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
* inspector/InspectorHeapProfilerAgent.cpp: Added.
(WebCore):
(WebCore::InspectorHeapProfilerAgent::create):
(WebCore::InspectorHeapProfilerAgent::InspectorHeapProfilerAgent):
(WebCore::InspectorHeapProfilerAgent::~InspectorHeapProfilerAgent):
(WebCore::InspectorHeapProfilerAgent::resetState):
(WebCore::InspectorHeapProfilerAgent::resetFrontendProfiles):
(WebCore::InspectorHeapProfilerAgent::setFrontend):
(WebCore::InspectorHeapProfilerAgent::clearFrontend):
(WebCore::InspectorHeapProfilerAgent::restore):
(WebCore::InspectorHeapProfilerAgent::collectGarbage):
(WebCore::InspectorHeapProfilerAgent::createSnapshotHeader):
(WebCore::InspectorHeapProfilerAgent::hasHeapProfiler):
(WebCore::InspectorHeapProfilerAgent::getProfileHeaders):
(WebCore::InspectorHeapProfilerAgent::getHeapSnapshot):
(WebCore::InspectorHeapProfilerAgent::removeProfile):
(WebCore::InspectorHeapProfilerAgent::takeHeapSnapshot):
(WebCore::InspectorHeapProfilerAgent::getObjectByHeapObjectId):
(WebCore::InspectorHeapProfilerAgent::getHeapObjectId):
(WebCore::InspectorHeapProfilerAgent::reportMemoryUsage):
* inspector/InspectorHeapProfilerAgent.h: Added.
(WebCore):
(InspectorHeapProfilerAgent):
(WebCore::InspectorHeapProfilerAgent::clearProfiles):
* inspector/InspectorInstrumentation.cpp:
(WebCore):
(WebCore::InspectorInstrumentation::didCommitLoadImpl):
* inspector/InstrumentingAgents.h:
(WebCore):
(InstrumentingAgents):
(WebCore::InstrumentingAgents::inspectorHeapProfilerAgent):
(WebCore::InstrumentingAgents::setInspectorHeapProfilerAgent):
* inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::WorkerInspectorController):
* inspector/front-end/HeapSnapshotDataGrids.js:
* inspector/front-end/HeapSnapshotGridNodes.js:
(WebInspector.HeapSnapshotGenericObjectNode.prototype.queryObjectContent):
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapProfileHeader.prototype.startSnapshotTransfer):
(WebInspector.HeapProfileHeader.prototype.saveToFile.onOpen):
(WebInspector.HeapProfileHeader.prototype.saveToFile):
* inspector/front-end/ProfilesPanel.js:
(WebInspector.ProfilesPanel):
(WebInspector.ProfilesPanel.prototype._clearProfiles):
(WebInspector.ProfilesPanel.prototype._garbageCollectButtonClicked):
(WebInspector.ProfilesPanel.prototype._removeProfileHeader):
(WebInspector.ProfilesPanel.prototype._populateProfiles.var):
(WebInspector.ProfilesPanel.prototype._populateProfiles.populateCallback):
(WebInspector.ProfilesPanel.prototype._populateProfiles):
(WebInspector.ProfilesPanel.prototype.takeHeapSnapshot):
(WebInspector.ProfilesPanel.prototype.revealInView):
(WebInspector.HeapProfilerDispatcher):
(WebInspector.HeapProfilerDispatcher.prototype.addProfileHeader):
(WebInspector.HeapProfilerDispatcher.prototype.addHeapSnapshotChunk):
(WebInspector.HeapProfilerDispatcher.prototype.finishHeapSnapshot):
(WebInspector.HeapProfilerDispatcher.prototype.resetProfiles):
(WebInspector.HeapProfilerDispatcher.prototype.reportHeapSnapshotProgress):
* inspector/front-end/TimelinePanel.js:
(WebInspector.TimelinePanel.prototype._garbageCollectButtonClicked):
* inspector/front-end/inspector.js:
(WebInspector.doLoadedDone):

Source/WebKit/chromium:

* src/WebDevToolsAgentImpl.cpp:
(WebKit::WebDevToolsAgent::shouldInterruptForMessage):

LayoutTests:

* inspector-protocol/heap-profiler/resources/heap-snapshot-common.js:
(InspectorTest.takeHeapSnapshot.InspectorTest.eventHandler.string_appeared_here):
(InspectorTest.takeHeapSnapshot):
* inspector-protocol/nmi-webaudio-leak-test.html:
* inspector/profiler/heap-snapshot-get-profile-crash.html:
* inspector/profiler/heap-snapshot-inspect-dom-wrapper.html:
* inspector/profiler/heap-snapshot-loader.html:
* inspector/profiler/heap-snapshot-test.js:
(initialize_HeapSnapshotTest):

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

34 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector-protocol/heap-profiler/resources/heap-snapshot-common.js
LayoutTests/inspector-protocol/nmi-webaudio-leak-test.html
LayoutTests/inspector/profiler/heap-snapshot-get-profile-crash.html
LayoutTests/inspector/profiler/heap-snapshot-inspect-dom-wrapper.html
LayoutTests/inspector/profiler/heap-snapshot-loader.html
LayoutTests/inspector/profiler/heap-snapshot-test.js
PerformanceTests/ChangeLog
PerformanceTests/inspector/heap-snapshot-performance-test.js
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorAllInOne.cpp
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorHeapProfilerAgent.cpp [new file with mode: 0644]
Source/WebCore/inspector/InspectorHeapProfilerAgent.h [new file with mode: 0644]
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InstrumentingAgents.h
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebCore/inspector/front-end/HeapSnapshotDataGrids.js
Source/WebCore/inspector/front-end/HeapSnapshotGridNodes.js
Source/WebCore/inspector/front-end/HeapSnapshotView.js
Source/WebCore/inspector/front-end/ProfilesPanel.js
Source/WebCore/inspector/front-end/TimelinePanel.js
Source/WebCore/inspector/front-end/inspector.js
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp

index a641d1c..b12546d 100644 (file)
@@ -1,3 +1,26 @@
+2013-02-11  Alexei Filippov  <alph@chromium.org>
+
+        Web Inspector: Split Profiler domain in protocol into Profiler and HeapProfiler
+        https://bugs.webkit.org/show_bug.cgi?id=108653
+
+        Reviewed by Yury Semikhatsky.
+
+        Currently CPU and heap profilers share the same domain 'Profiler' in the protocol.
+        In fact these two profile types have not too much in common. So put each into its own domain.
+        It should also help when Profiles panel gets split into several tools.
+        This is the phase 1 which adds InspectorHeapProfilerAgent but doesn't
+        change the original InspectorProfilerAgent.
+
+        * inspector-protocol/heap-profiler/resources/heap-snapshot-common.js:
+        (InspectorTest.takeHeapSnapshot.InspectorTest.eventHandler.string_appeared_here):
+        (InspectorTest.takeHeapSnapshot):
+        * inspector-protocol/nmi-webaudio-leak-test.html:
+        * inspector/profiler/heap-snapshot-get-profile-crash.html:
+        * inspector/profiler/heap-snapshot-inspect-dom-wrapper.html:
+        * inspector/profiler/heap-snapshot-loader.html:
+        * inspector/profiler/heap-snapshot-test.js:
+        (initialize_HeapSnapshotTest):
+
 2013-02-11  Christophe Dumez  <ch.dumez@sisa.samsung.com>
 
         Unreviewed EFL gardening.
index 7b3b9f1..9e98849 100644 (file)
@@ -9,10 +9,10 @@ InspectorTest.importScript("../../../../../Source/WebCore/inspector/front-end/JS
 
 InspectorTest.takeHeapSnapshot = function(callback)
 {
-    InspectorTest.eventHandler["Profiler.addProfileHeader"] = function(messageObject)
+    InspectorTest.eventHandler["HeapProfiler.addProfileHeader"] = function(messageObject)
     {
         var profileId = messageObject["params"]["header"]["uid"];
-        InspectorTest.sendCommand("Profiler.getHeapSnapshot", { "uid": profileId }, didGetHeapSnapshot);
+        InspectorTest.sendCommand("HeapProfiler.getHeapSnapshot", { "uid": profileId }, didGetHeapSnapshot);
 
         function didGetHeapSnapshot(messageObject)
         {
@@ -22,12 +22,12 @@ InspectorTest.takeHeapSnapshot = function(callback)
     }
 
     var chunks = [];
-    InspectorTest.eventHandler["Profiler.addHeapSnapshotChunk"] = function(messageObject)
+    InspectorTest.eventHandler["HeapProfiler.addHeapSnapshotChunk"] = function(messageObject)
     {
         chunks.push(messageObject["params"]["chunk"]);
     }
 
-    InspectorTest.eventHandler["Profiler.finishHeapSnapshot"] = function(messageObject)
+    InspectorTest.eventHandler["HeapProfiler.finishHeapSnapshot"] = function(messageObject)
     {
         var serializedSnapshot = chunks.join("");
         var parsed = JSON.parse(serializedSnapshot);
@@ -35,5 +35,5 @@ InspectorTest.takeHeapSnapshot = function(callback)
         callback(snapshot);
     }
 
-    InspectorTest.sendCommand("Profiler.takeHeapSnapshot", {});
+    InspectorTest.sendCommand("HeapProfiler.takeHeapSnapshot", {});
 }
index 29dc937..b3fc218 100644 (file)
@@ -60,7 +60,7 @@ function test()
 
     function iFrameNavigated(messageObject) {
         InspectorTest.log("PASS: IFrame was navigated to resources/blank.html");
-        InspectorTest.sendCommand('Profiler.collectGarbage', {}, function() { } );
+        InspectorTest.sendCommand('HeapProfiler.collectGarbage', {}, function() { } );
         InspectorTest.log("Action: Run GC and check Page.Audio data size");
         InspectorTest.sendCommand('Memory.getProcessMemoryDistribution', {}, noAudioSharedData);
     }
index 8561bcb..544cb12 100644 (file)
@@ -14,7 +14,7 @@ function test()
                 console.log(errorString);
                 next();
             }
-            ProfilerAgent.getHeapSnapshot(-1, finish);
+            HeapProfilerAgent.getHeapSnapshot(-1, finish);
         }
     ]);
 }
index 38207fb..035fc4c 100644 (file)
@@ -14,7 +14,7 @@ function handleLoad()
 function test()
 {
     WebInspector.showPanel("profiles");
-    ProfilerAgent.takeHeapSnapshot(step0);
+    HeapProfilerAgent.takeHeapSnapshot(step0);
 
     function step0()
     {
@@ -42,7 +42,7 @@ function test()
                 bodyWrapperIds.push(it.node.id);
         }
         for (var i = 0; i < bodyWrapperIds.length; i++)
-            ProfilerAgent.getObjectByHeapObjectId(bodyWrapperIds[i], undefined, didGetObjectByHeapObjectId);
+            HeapProfilerAgent.getObjectByHeapObjectId(bodyWrapperIds[i], undefined, didGetObjectByHeapObjectId);
 
         var resolvedObjectsCount = 0;
         var remoteObjects = [];
@@ -69,7 +69,7 @@ function test()
             if (++didGetOwnPropertiesCount !== remoteObjects.length)
                 return;
 
-            ProfilerAgent.clearProfiles(done);
+            HeapProfilerAgent.clearProfiles(done);
             WebInspector.panels.profiles._reset();
         }
     }
index 940b64b..cd865be 100644 (file)
@@ -17,7 +17,7 @@ function test()
     var partSize = sourceStringified.length >> 3;
 
     function injectMockProfile(overrideGetProfile, callback) {
-        var dispatcher = InspectorBackend._domainDispatchers["Profiler"];
+        var dispatcher = InspectorBackend._domainDispatchers["HeapProfiler"];
         var panel = WebInspector.panels.profiles;
         panel._reset();
 
@@ -39,12 +39,12 @@ function test()
         function snapshotLoaded()
         {
             if (overrideGetProfile)
-                InspectorTest.override(ProfilerAgent, "getHeapSnapshot", getHeapSnapshotMock);
+                InspectorTest.override(HeapProfilerAgent, "getHeapSnapshot", getHeapSnapshotMock);
             callback(profileHeader);
         }
         InspectorTest.addSniffer(profileHeader, "_snapshotReceived", snapshotLoaded);
 
-        InspectorTest.override(ProfilerAgent, "getHeapSnapshot", getHeapSnapshotMock);
+        InspectorTest.override(HeapProfilerAgent, "getHeapSnapshot", getHeapSnapshotMock);
         panel.showProfile(profileHeader);
     }
 
index 15554d2..cbd6663 100644 (file)
@@ -172,7 +172,7 @@ InspectorTest.startProfilerTest = function(callback)
     function profilerEnabled()
     {
         InspectorTest.addResult("Profiler was enabled.");
-        // We mock out ProfilerAgent -- as DRT runs in single-process mode, Inspector
+        // We mock out HeapProfilerAgent -- as DRT runs in single-process mode, Inspector
         // and test share the same heap. Taking a snapshot takes too long for a test,
         // so we provide synthetic snapshots.
         InspectorTest._panelReset = InspectorTest.override(WebInspector.panels.profiles, "_reset", function(){}, true);
@@ -735,7 +735,7 @@ InspectorTest.takeAndOpenSnapshot = function(generator, callback)
         WebInspector.panels.profiles._addHeapSnapshotChunk(uid, JSON.stringify(snapshot));
         WebInspector.panels.profiles._finishHeapSnapshot(uid);
     }
-    InspectorTest.override(ProfilerAgent, "getHeapSnapshot", pushGeneratedSnapshot);
+    InspectorTest.override(HeapProfilerAgent, "getHeapSnapshot", pushGeneratedSnapshot);
     InspectorTest._takeAndOpenSnapshotCallback = callback;
     WebInspector.panels.profiles.addProfileHeader(profile);
     WebInspector.panels.profiles.showProfile(profile);
index 194034d..808c90d 100644 (file)
@@ -1,3 +1,19 @@
+2013-02-11  Alexei Filippov  <alph@chromium.org>
+
+        Web Inspector: Split Profiler domain in protocol into Profiler and HeapProfiler
+        https://bugs.webkit.org/show_bug.cgi?id=108653
+
+        Reviewed by Yury Semikhatsky.
+
+        Currently CPU and heap profilers share the same domain 'Profiler' in the protocol.
+        In fact these two profile types have not too much in common. So put each into its own domain.
+        It should also help when Profiles panel gets split into several tools.
+        This is the phase 1 which adds InspectorHeapProfilerAgent but doesn't
+        change the original InspectorProfilerAgent.
+
+        * inspector/heap-snapshot-performance-test.js:
+        (test.performanceTest.cleanup):
+
 2013-02-05  Dominik Röttsches  <dominik.rottsches@intel.com>
 
         Add a performance test for arabic line breaking
index 9c39582..ad947b8 100644 (file)
@@ -27,7 +27,7 @@ function test()
         var testName = /([^\/]+)\.html$/.exec(WebInspector.inspectedPageURL)[1];
         var fullTimerCookie = timer.start("full-summary-snapshot-time");
         var backendTimerCookie = timer.start("take-snapshot");
-        ProfilerAgent.takeHeapSnapshot(step0);
+        HeapProfilerAgent.takeHeapSnapshot(step0);
 
         function step0()
         {
@@ -59,7 +59,7 @@ function test()
             timer.finish(changeViewTimerCookie);
             timer.finish(fullTimerCookie);
             clearTimerCookie = timer.start("clear-snapshot");
-            ProfilerAgent.clearProfiles(done);
+            HeapProfilerAgent.clearProfiles(done);
             WebInspector.panels.profiles._reset();
         }
 
index 08d1565..03e08ef 100644 (file)
@@ -1641,6 +1641,7 @@ set(WebCore_SOURCES
     inspector/InspectorFileSystemAgent.cpp
     inspector/InspectorFrontendClientLocal.cpp
     inspector/InspectorFrontendHost.cpp
+    inspector/InspectorHeapProfilerAgent.cpp
     inspector/InspectorHistory.cpp
     inspector/InspectorIndexedDBAgent.cpp
     inspector/InspectorInputAgent.cpp
index c177d04..b1133cd 100644 (file)
@@ -1,3 +1,90 @@
+2013-02-11  Alexei Filippov  <alph@chromium.org>
+
+        Web Inspector: Split Profiler domain in protocol into Profiler and HeapProfiler
+        https://bugs.webkit.org/show_bug.cgi?id=108653
+
+        Reviewed by Yury Semikhatsky.
+
+        Currently CPU and heap profilers share the same domain 'Profiler' in the protocol.
+        In fact these two profile types have not too much in common. So put each into its own domain.
+        It should also help when Profiles panel gets split into several tools.
+        This is the phase 1 which adds InspectorHeapProfilerAgent but doesn't
+        change the original InspectorProfilerAgent.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * WebCore.xcodeproj/project.pbxproj:
+        * inspector/Inspector.json:
+        * inspector/InspectorAllInOne.cpp:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        * inspector/InspectorHeapProfilerAgent.cpp: Added.
+        (WebCore):
+        (WebCore::InspectorHeapProfilerAgent::create):
+        (WebCore::InspectorHeapProfilerAgent::InspectorHeapProfilerAgent):
+        (WebCore::InspectorHeapProfilerAgent::~InspectorHeapProfilerAgent):
+        (WebCore::InspectorHeapProfilerAgent::resetState):
+        (WebCore::InspectorHeapProfilerAgent::resetFrontendProfiles):
+        (WebCore::InspectorHeapProfilerAgent::setFrontend):
+        (WebCore::InspectorHeapProfilerAgent::clearFrontend):
+        (WebCore::InspectorHeapProfilerAgent::restore):
+        (WebCore::InspectorHeapProfilerAgent::collectGarbage):
+        (WebCore::InspectorHeapProfilerAgent::createSnapshotHeader):
+        (WebCore::InspectorHeapProfilerAgent::hasHeapProfiler):
+        (WebCore::InspectorHeapProfilerAgent::getProfileHeaders):
+        (WebCore::InspectorHeapProfilerAgent::getHeapSnapshot):
+        (WebCore::InspectorHeapProfilerAgent::removeProfile):
+        (WebCore::InspectorHeapProfilerAgent::takeHeapSnapshot):
+        (WebCore::InspectorHeapProfilerAgent::getObjectByHeapObjectId):
+        (WebCore::InspectorHeapProfilerAgent::getHeapObjectId):
+        (WebCore::InspectorHeapProfilerAgent::reportMemoryUsage):
+        * inspector/InspectorHeapProfilerAgent.h: Added.
+        (WebCore):
+        (InspectorHeapProfilerAgent):
+        (WebCore::InspectorHeapProfilerAgent::clearProfiles):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore):
+        (WebCore::InspectorInstrumentation::didCommitLoadImpl):
+        * inspector/InstrumentingAgents.h:
+        (WebCore):
+        (InstrumentingAgents):
+        (WebCore::InstrumentingAgents::inspectorHeapProfilerAgent):
+        (WebCore::InstrumentingAgents::setInspectorHeapProfilerAgent):
+        * inspector/WorkerInspectorController.cpp:
+        (WebCore::WorkerInspectorController::WorkerInspectorController):
+        * inspector/front-end/HeapSnapshotDataGrids.js:
+        * inspector/front-end/HeapSnapshotGridNodes.js:
+        (WebInspector.HeapSnapshotGenericObjectNode.prototype.queryObjectContent):
+        * inspector/front-end/HeapSnapshotView.js:
+        (WebInspector.HeapProfileHeader.prototype.startSnapshotTransfer):
+        (WebInspector.HeapProfileHeader.prototype.saveToFile.onOpen):
+        (WebInspector.HeapProfileHeader.prototype.saveToFile):
+        * inspector/front-end/ProfilesPanel.js:
+        (WebInspector.ProfilesPanel):
+        (WebInspector.ProfilesPanel.prototype._clearProfiles):
+        (WebInspector.ProfilesPanel.prototype._garbageCollectButtonClicked):
+        (WebInspector.ProfilesPanel.prototype._removeProfileHeader):
+        (WebInspector.ProfilesPanel.prototype._populateProfiles.var):
+        (WebInspector.ProfilesPanel.prototype._populateProfiles.populateCallback):
+        (WebInspector.ProfilesPanel.prototype._populateProfiles):
+        (WebInspector.ProfilesPanel.prototype.takeHeapSnapshot):
+        (WebInspector.ProfilesPanel.prototype.revealInView):
+        (WebInspector.HeapProfilerDispatcher):
+        (WebInspector.HeapProfilerDispatcher.prototype.addProfileHeader):
+        (WebInspector.HeapProfilerDispatcher.prototype.addHeapSnapshotChunk):
+        (WebInspector.HeapProfilerDispatcher.prototype.finishHeapSnapshot):
+        (WebInspector.HeapProfilerDispatcher.prototype.resetProfiles):
+        (WebInspector.HeapProfilerDispatcher.prototype.reportHeapSnapshotProgress):
+        * inspector/front-end/TimelinePanel.js:
+        (WebInspector.TimelinePanel.prototype._garbageCollectButtonClicked):
+        * inspector/front-end/inspector.js:
+        (WebInspector.doLoadedDone):
+
 2013-02-11  Mike West  <mkwst@chromium.org>
 
         Use IGNORE_EXCEPTION for Editor::countMatchesForText's ignored exceptions.
index 725643b..197e82e 100644 (file)
@@ -3833,6 +3833,8 @@ webcore_sources += \
        Source/WebCore/inspector/InspectorFrontendClientLocal.h \
        Source/WebCore/inspector/InspectorFrontendHost.cpp \
        Source/WebCore/inspector/InspectorFrontendHost.h \
+       Source/WebCore/inspector/InspectorHeapProfilerAgent.cpp \
+       Source/WebCore/inspector/InspectorHeapProfilerAgent.h \
        Source/WebCore/inspector/InspectorHistory.cpp \
        Source/WebCore/inspector/InspectorHistory.h \
        Source/WebCore/inspector/InspectorIndexedDBAgent.h \
index 97cdd0b..cea3095 100644 (file)
@@ -799,6 +799,7 @@ SOURCES += \
     inspector/InspectorDOMStorageResource.cpp \
     inspector/InspectorFrontendClientLocal.cpp \
     inspector/InspectorFrontendHost.cpp \
+    inspector/InspectorHeapProfilerAgent.cpp \
     inspector/InspectorHistory.cpp \
     inspector/InspectorInputAgent.cpp \
     inspector/InspectorInstrumentation.cpp \
@@ -1992,6 +1993,7 @@ HEADERS += \
     inspector/InspectorFrontendClient.h \
     inspector/InspectorFrontendClientLocal.h \
     inspector/InspectorFrontendHost.h \
+    inspector/InspectorHeapProfilerAgent.h \
     inspector/InspectorHistory.h \
     inspector/InspectorInstrumentation.h \
     inspector/InspectorLayerTreeAgent.h \
index 2885f07..2a4fc09 100644 (file)
             'inspector/InspectorFrontendClientLocal.cpp',
             'inspector/InspectorFrontendHost.cpp',
             'inspector/InspectorFrontendHost.h',
+            'inspector/InspectorHeapProfilerAgent.cpp',
+            'inspector/InspectorHeapProfilerAgent.h',
             'inspector/InspectorHistory.cpp',
             'inspector/InspectorHistory.h',
             'inspector/InspectorIndexedDBAgent.cpp',
index 3ec67eb..cf0b535 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\inspector\InspectorHeapProfilerAgent.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Production|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath="..\inspector\InspectorHeapProfilerAgent.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\inspector\InspectorHistory.cpp"
                                >
                                <FileConfiguration
index 2a2f369..a4b2faa 100644 (file)
     <ClCompile Include="..\inspector\InspectorFrontendHost.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     </ClCompile>
+    <ClCompile Include="..\inspector\InspectorHeapProfilerAgent.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="..\inspector\InspectorHistory.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     </ClCompile>
     <ClInclude Include="..\inspector\InspectorFrontendClient.h" />
     <ClInclude Include="..\inspector\InspectorFrontendClientLocal.h" />
     <ClInclude Include="..\inspector\InspectorFrontendHost.h" />
+    <ClInclude Include="..\inspector\InspectorHeapProfilerAgent.h" />
     <ClInclude Include="..\inspector\InspectorHistory.h" />
     <ClInclude Include="..\inspector\InspectorIndexedDBAgent.h" />
     <ClInclude Include="..\inspector\InspectorInputAgent.h" />
index 9ad8ade..c3aded8 100644 (file)
     <ClCompile Include="..\inspector\InspectorFrontendHost.cpp">
       <Filter>inspector</Filter>
     </ClCompile>
+    <ClCompile Include="..\inspector\InspectorHeapProfilerAgent.cpp">
+      <Filter>inspector</Filter>
+    </ClCompile>
     <ClCompile Include="..\inspector\InspectorHistory.cpp">
       <Filter>inspector</Filter>
     </ClCompile>
     <ClInclude Include="..\inspector\InspectorFrontendHost.h">
       <Filter>inspector</Filter>
     </ClInclude>
+    <ClInclude Include="..\inspector\InspectorHeapProfilerAgent.h">
+      <Filter>inspector</Filter>
+    </ClInclude>
     <ClInclude Include="..\inspector\InspectorHistory.h">
       <Filter>inspector</Filter>
     </ClInclude>
index 16a78e0..9538081 100644 (file)
                9BF9A8811648DD2F001C6B23 /* JSHTMLFormControlsCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BF9A87F1648DD2F001C6B23 /* JSHTMLFormControlsCollection.h */; };
                9F0D6B2E121BFEBA006C0288 /* InspectorProfilerAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9F0D6B2C121BFEBA006C0288 /* InspectorProfilerAgent.cpp */; };
                9F0D6B2F121BFEBA006C0288 /* InspectorProfilerAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F0D6B2D121BFEBA006C0288 /* InspectorProfilerAgent.h */; };
+               5112935F3D54B4B52FAF973F /* InspectorHeapProfilerAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511293613D6DB4B52FAF973F /* InspectorHeapProfilerAgent.cpp */; };
+               511293603D60B4B52FAF973F /* InspectorHeapProfilerAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 511293623D85B4B52FAF973F /* InspectorHeapProfilerAgent.h */; };
                9F3B947E12241758005304E7 /* ScriptHeapSnapshot.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F3B947D12241758005304E7 /* ScriptHeapSnapshot.h */; };
                9F6FC1961122E82A00E80196 /* ScriptDebugServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9F6FC1941122E82A00E80196 /* ScriptDebugServer.cpp */; };
                9F6FC1971122E82A00E80196 /* ScriptDebugServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F6FC1951122E82A00E80196 /* ScriptDebugServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9BF9A87F1648DD2F001C6B23 /* JSHTMLFormControlsCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLFormControlsCollection.h; sourceTree = "<group>"; };
                9F0D6B2C121BFEBA006C0288 /* InspectorProfilerAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorProfilerAgent.cpp; sourceTree = "<group>"; };
                9F0D6B2D121BFEBA006C0288 /* InspectorProfilerAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorProfilerAgent.h; sourceTree = "<group>"; };
+               511293613D6DB4B52FAF973F /* InspectorHeapProfilerAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorHeapProfilerAgent.cpp; sourceTree = "<group>"; };
+               511293623D85B4B52FAF973F /* InspectorHeapProfilerAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorHeapProfilerAgent.h; sourceTree = "<group>"; };
                9F3B947D12241758005304E7 /* ScriptHeapSnapshot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptHeapSnapshot.h; sourceTree = "<group>"; };
                9F6FC1941122E82A00E80196 /* ScriptDebugServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptDebugServer.cpp; sourceTree = "<group>"; };
                9F6FC1951122E82A00E80196 /* ScriptDebugServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptDebugServer.h; sourceTree = "<group>"; };
                                7A0E770B10C00A8800A0276E /* InspectorFrontendHost.cpp */,
                                7A0E770C10C00A8800A0276E /* InspectorFrontendHost.h */,
                                7A0E770D10C00A8800A0276E /* InspectorFrontendHost.idl */,
+                               511293613D6DB4B52FAF973F /* InspectorHeapProfilerAgent.cpp */,
+                               511293623D85B4B52FAF973F /* InspectorHeapProfilerAgent.h */,
                                7A54857D14E02D51006AE05A /* InspectorHistory.cpp */,
                                7A54857E14E02D51006AE05A /* InspectorHistory.h */,
                                7ACD88D114C08BD60084EDD2 /* InspectorIndexedDBAgent.cpp */,
                                F344C7141125B82C00F26EEE /* InspectorFrontendClient.h in Headers */,
                                F344C75311294D9D00F26EEE /* InspectorFrontendClientLocal.h in Headers */,
                                7A0E770F10C00A8800A0276E /* InspectorFrontendHost.h in Headers */,
+                               511293603D60B4B52FAF973F /* InspectorHeapProfilerAgent.h in Headers */,
                                7A54858014E02D51006AE05A /* InspectorHistory.h in Headers */,
                                7ACD88D414C08BD60084EDD2 /* InspectorIndexedDBAgent.h in Headers */,
                                4D273CFA1669420800259CA1 /* InspectorInputAgent.h in Headers */,
                                4F4F5FFB11CBD2E100A186BF /* InspectorFrontend.cpp in Sources */,
                                F344C75811294FF600F26EEE /* InspectorFrontendClientLocal.cpp in Sources */,
                                7A0E770E10C00A8800A0276E /* InspectorFrontendHost.cpp in Sources */,
+                               5112935F3D54B4B52FAF973F /* InspectorHeapProfilerAgent.cpp in Sources */,
                                7A54857F14E02D51006AE05A /* InspectorHistory.cpp in Sources */,
                                7ACD88D314C08BD60084EDD2 /* InspectorIndexedDBAgent.cpp in Sources */,
                                4D273CF91669420800259CA1 /* InspectorInputAgent.cpp in Sources */,
index 1414f64..540d2ba 100644 (file)
         ]
     },
     {
+        "domain": "HeapProfiler",
+        "hidden": true,
+        "types": [
+            {
+                "id": "ProfileHeader",
+                "type": "object",
+                "description": "Profile header.",
+                "properties": [
+                    { "name": "title", "type": "string", "description": "Profile title." },
+                    { "name": "uid", "type": "integer", "description": "Unique identifier of the profile." },
+                    { "name": "maxJSObjectId", "type": "integer", "optional": true, "description": "Last seen JS object Id." }
+                ]
+            },
+            {
+                "id": "HeapSnapshotObjectId",
+                "type": "string",
+                "description": "Heap snashot object id."
+            }
+        ],
+        "commands": [
+            {
+                "name": "hasHeapProfiler",
+                "returns": [
+                    { "name": "result", "type": "boolean" }
+                ]
+            },
+            {
+                "name": "getProfileHeaders",
+                "returns": [
+                    { "name": "headers", "type": "array", "items": { "$ref": "ProfileHeader"} }
+                ]
+            },
+            {
+                "name": "getHeapSnapshot",
+                "parameters": [
+                    { "name": "uid", "type": "integer" }
+                ]
+            },
+            {
+                "name": "removeProfile",
+                "parameters": [
+                    { "name": "uid", "type": "integer" }
+                ]
+            },
+            {
+                "name": "clearProfiles"
+            },
+            {
+                "name": "takeHeapSnapshot",
+                "parameters": [
+                    { "name": "reportProgress", "type": "boolean", "optional": true, "description": "If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken." }
+                ]
+            },
+            {
+                "name": "collectGarbage"
+            },
+            {
+                "name": "getObjectByHeapObjectId",
+                "parameters": [
+                    { "name": "objectId", "$ref": "HeapSnapshotObjectId" },
+                    { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }
+                ],
+                "returns": [
+                    { "name": "result", "$ref": "Runtime.RemoteObject", "description": "Evaluation result." }
+                ]
+            },
+            {
+                "name": "getHeapObjectId",
+                "parameters": [
+                    { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "description": "Identifier of the object to get heap object id for." }
+                ],
+                "returns": [
+                    { "name": "heapSnapshotObjectId", "$ref": "HeapSnapshotObjectId", "description": "Id of the heap snapshot object corresponding to the passed remote object id." }
+                ]
+            }
+        ],
+        "events": [
+            {
+                "name": "addProfileHeader",
+                "parameters": [
+                    { "name": "header", "$ref": "ProfileHeader" }
+                ]
+            },
+            {
+                "name": "addHeapSnapshotChunk",
+                "parameters": [
+                    { "name": "uid", "type": "integer" },
+                    { "name": "chunk", "type": "string" }
+                ]
+            },
+            {
+                "name": "finishHeapSnapshot",
+                "parameters": [
+                    { "name": "uid", "type": "integer" }
+                ]
+            },
+            {
+                "name": "resetProfiles"
+            },
+            {
+                "name": "reportHeapSnapshotProgress",
+                "parameters": [
+                    { "name": "done", "type": "integer" },
+                    { "name": "total", "type": "integer" }
+                ]
+            }
+        ]
+    },
+    {
         "domain": "Worker",
         "hidden": true,
         "types": [],
index 9c9ff20..67cea46 100644 (file)
@@ -56,6 +56,7 @@
 #include "InspectorFileSystemAgent.cpp"
 #include "InspectorFrontendClientLocal.cpp"
 #include "InspectorFrontendHost.cpp"
+#include "InspectorHeapProfilerAgent.cpp"
 #include "InspectorHistory.cpp"
 #include "InspectorIndexedDBAgent.cpp"
 #include "InspectorInputAgent.cpp"
index f3da808..df50d0e 100644 (file)
@@ -54,6 +54,7 @@
 #include "InspectorFileSystemAgent.h"
 #include "InspectorFrontend.h"
 #include "InspectorFrontendClient.h"
+#include "InspectorHeapProfilerAgent.h"
 #include "InspectorIndexedDBAgent.h"
 #include "InspectorInputAgent.h"
 #include "InspectorInstrumentation.h"
@@ -152,6 +153,9 @@ InspectorController::InspectorController(Page* page, InspectorClient* inspectorC
     OwnPtr<InspectorProfilerAgent> profilerAgentPtr(InspectorProfilerAgent::create(m_instrumentingAgents.get(), consoleAgent, page, m_state.get(), m_injectedScriptManager.get()));
     m_profilerAgent = profilerAgentPtr.get();
     m_agents.append(profilerAgentPtr.release());
+
+    m_agents.append(InspectorHeapProfilerAgent::create(m_instrumentingAgents.get(), m_state.get(), m_injectedScriptManager.get()));
+
 #endif
 
 #if ENABLE(WORKERS)
diff --git a/Source/WebCore/inspector/InspectorHeapProfilerAgent.cpp b/Source/WebCore/inspector/InspectorHeapProfilerAgent.cpp
new file mode 100644 (file)
index 0000000..f65b344
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
+
+#include "InspectorHeapProfilerAgent.h"
+
+#include "InjectedScript.h"
+#include "InjectedScriptHost.h"
+#include "InstrumentingAgents.h"
+#include "ScriptProfiler.h"
+#include "WebCoreMemoryInstrumentation.h"
+
+namespace WebCore {
+
+static const char* const UserInitiatedProfileName = "org.webkit.profiles.user-initiated";
+static const char* const HeapProfileType = "HEAP";
+
+PassOwnPtr<InspectorHeapProfilerAgent> InspectorHeapProfilerAgent::create(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* inspectorState, InjectedScriptManager* injectedScriptManager)
+{
+    return adoptPtr(new InspectorHeapProfilerAgent(instrumentingAgents, inspectorState, injectedScriptManager));
+}
+
+InspectorHeapProfilerAgent::InspectorHeapProfilerAgent(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* inspectorState, InjectedScriptManager* injectedScriptManager)
+    : InspectorBaseAgent<InspectorHeapProfilerAgent>("HeapProfiler", instrumentingAgents, inspectorState)
+    , m_injectedScriptManager(injectedScriptManager)
+    , m_frontend(0)
+    , m_headersRequested(false)
+    , m_nextUserInitiatedHeapSnapshotNumber(1)
+{
+    m_instrumentingAgents->setInspectorHeapProfilerAgent(this);
+}
+
+InspectorHeapProfilerAgent::~InspectorHeapProfilerAgent()
+{
+    m_instrumentingAgents->setInspectorHeapProfilerAgent(0);
+}
+
+void InspectorHeapProfilerAgent::resetState()
+{
+    m_snapshots.clear();
+    m_nextUserInitiatedHeapSnapshotNumber = 1;
+    resetFrontendProfiles();
+    m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects();
+}
+
+void InspectorHeapProfilerAgent::resetFrontendProfiles()
+{
+    if (m_headersRequested && m_frontend && m_snapshots.isEmpty())
+        m_frontend->resetProfiles();
+}
+
+void InspectorHeapProfilerAgent::setFrontend(InspectorFrontend* frontend)
+{
+    m_frontend = frontend->heapprofiler();
+}
+
+void InspectorHeapProfilerAgent::clearFrontend()
+{
+    m_headersRequested = false;
+    m_frontend = 0;
+}
+
+void InspectorHeapProfilerAgent::restore()
+{
+    // Revisit this.
+    m_headersRequested = true;
+    resetFrontendProfiles();
+}
+
+void InspectorHeapProfilerAgent::collectGarbage(WebCore::ErrorString*)
+{
+    ScriptProfiler::collectGarbage();
+}
+
+PassRefPtr<TypeBuilder::HeapProfiler::ProfileHeader> InspectorHeapProfilerAgent::createSnapshotHeader(const ScriptHeapSnapshot& snapshot)
+{
+    RefPtr<TypeBuilder::HeapProfiler::ProfileHeader> header = TypeBuilder::HeapProfiler::ProfileHeader::create()
+        .setUid(snapshot.uid())
+        .setTitle(snapshot.title());
+    header->setMaxJSObjectId(snapshot.maxSnapshotJSObjectId());
+    return header.release();
+}
+
+void InspectorHeapProfilerAgent::hasHeapProfiler(ErrorString*, bool* result)
+{
+    *result = ScriptProfiler::hasHeapProfiler();
+}
+
+void InspectorHeapProfilerAgent::getProfileHeaders(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::HeapProfiler::ProfileHeader> >& headers)
+{
+    m_headersRequested = true;
+    headers = TypeBuilder::Array<TypeBuilder::HeapProfiler::ProfileHeader>::create();
+
+    IdToHeapSnapshotMap::iterator snapshotsEnd = m_snapshots.end();
+    for (IdToHeapSnapshotMap::iterator it = m_snapshots.begin(); it != snapshotsEnd; ++it)
+        headers->addItem(createSnapshotHeader(*it->value));
+}
+
+void InspectorHeapProfilerAgent::getHeapSnapshot(ErrorString* errorString, int rawUid)
+{
+    class OutputStream : public ScriptHeapSnapshot::OutputStream {
+    public:
+        OutputStream(InspectorFrontend::HeapProfiler* frontend, unsigned uid)
+            : m_frontend(frontend), m_uid(uid) { }
+        void Write(const String& chunk) { m_frontend->addHeapSnapshotChunk(m_uid, chunk); }
+        void Close() { m_frontend->finishHeapSnapshot(m_uid); }
+    private:
+        InspectorFrontend::HeapProfiler* m_frontend;
+        int m_uid;
+    };
+
+    unsigned uid = static_cast<unsigned>(rawUid);
+    IdToHeapSnapshotMap::iterator it = m_snapshots.find(uid);
+    if (it == m_snapshots.end()) {
+        *errorString = "Profile wasn't found";
+        return;
+    }
+    RefPtr<ScriptHeapSnapshot> snapshot = it->value;
+    if (m_frontend) {
+        OutputStream stream(m_frontend, uid);
+        snapshot->writeJSON(&stream);
+    }
+}
+
+void InspectorHeapProfilerAgent::removeProfile(ErrorString*, int rawUid)
+{
+    unsigned uid = static_cast<unsigned>(rawUid);
+    if (m_snapshots.contains(uid))
+        m_snapshots.remove(uid);
+}
+
+void InspectorHeapProfilerAgent::takeHeapSnapshot(ErrorString*, const bool* reportProgress)
+{
+    class HeapSnapshotProgress: public ScriptProfiler::HeapSnapshotProgress {
+    public:
+        explicit HeapSnapshotProgress(InspectorFrontend::HeapProfiler* frontend)
+            : m_frontend(frontend) { }
+        void Start(int totalWork)
+        {
+            m_totalWork = totalWork;
+        }
+        void Worked(int workDone)
+        {
+            if (m_frontend)
+                m_frontend->reportHeapSnapshotProgress(workDone, m_totalWork);
+        }
+        void Done() { }
+        bool isCanceled() { return false; }
+    private:
+        InspectorFrontend::HeapProfiler* m_frontend;
+        int m_totalWork;
+    };
+
+    String title = makeString(UserInitiatedProfileName, '.', String::number(m_nextUserInitiatedHeapSnapshotNumber));
+    ++m_nextUserInitiatedHeapSnapshotNumber;
+
+    HeapSnapshotProgress progress(reportProgress && *reportProgress ? m_frontend : 0);
+    RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title, &progress);
+    if (snapshot) {
+        m_snapshots.add(snapshot->uid(), snapshot);
+        if (m_frontend)
+            m_frontend->addProfileHeader(createSnapshotHeader(*snapshot));
+    }
+}
+
+void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result)
+{
+    bool ok;
+    unsigned id = heapSnapshotObjectId.toUInt(&ok);
+    if (!ok) {
+        *error = "Invalid heap snapshot object id";
+        return;
+    }
+    ScriptObject heapObject = ScriptProfiler::objectByHeapObjectId(id);
+    if (heapObject.hasNoValue()) {
+        *error = "Object is not available";
+        return;
+    }
+    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(heapObject.scriptState());
+    if (injectedScript.hasNoValue()) {
+        *error = "Object is not available. Inspected context is gone";
+        return;
+    }
+    result = injectedScript.wrapObject(heapObject, objectGroup ? *objectGroup : "");
+    if (!result)
+        *error = "Failed to wrap object";
+}
+
+void InspectorHeapProfilerAgent::getHeapObjectId(ErrorString* errorString, const String& objectId, String* heapSnapshotObjectId)
+{
+    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(objectId);
+    if (injectedScript.hasNoValue()) {
+        *errorString = "Inspected context has gone";
+        return;
+    }
+    ScriptValue value = injectedScript.findObjectById(objectId);
+    if (value.hasNoValue() || value.isUndefined()) {
+        *errorString = "Object with given id not found";
+        return;
+    }
+    unsigned id = ScriptProfiler::getHeapObjectId(value);
+    *heapSnapshotObjectId = String::number(id);
+}
+
+void InspectorHeapProfilerAgent::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorProfilerAgent);
+    InspectorBaseAgent<InspectorHeapProfilerAgent>::reportMemoryUsage(memoryObjectInfo);
+    info.addMember(m_injectedScriptManager, "injectedScriptManager");
+    info.addWeakPointer(m_frontend);
+    info.addMember(m_snapshots, "snapshots");
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
diff --git a/Source/WebCore/inspector/InspectorHeapProfilerAgent.h b/Source/WebCore/inspector/InspectorHeapProfilerAgent.h
new file mode 100644 (file)
index 0000000..6d78294
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InspectorHeapProfilerAgent_h
+#define InspectorHeapProfilerAgent_h
+
+#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
+
+#include "InspectorBaseAgent.h"
+#include "InspectorFrontend.h"
+#include <wtf/Forward.h>
+#include <wtf/HashMap.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class InjectedScriptManager;
+class ScriptHeapSnapshot;
+class ScriptProfile;
+
+typedef String ErrorString;
+
+class InspectorHeapProfilerAgent : public InspectorBaseAgent<InspectorHeapProfilerAgent>, public InspectorBackendDispatcher::HeapProfilerCommandHandler {
+    WTF_MAKE_NONCOPYABLE(InspectorHeapProfilerAgent); WTF_MAKE_FAST_ALLOCATED;
+public:
+    static PassOwnPtr<InspectorHeapProfilerAgent> create(InstrumentingAgents*, InspectorCompositeState*, InjectedScriptManager*);
+    virtual ~InspectorHeapProfilerAgent();
+
+    virtual void collectGarbage(ErrorString*);
+    virtual void clearProfiles(ErrorString*) { resetState(); }
+    void resetState();
+
+    virtual void hasHeapProfiler(ErrorString*, bool*);
+
+    virtual void getProfileHeaders(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::HeapProfiler::ProfileHeader> >&);
+    virtual void getHeapSnapshot(ErrorString*, int uid);
+    virtual void removeProfile(ErrorString*, int uid);
+
+    virtual void setFrontend(InspectorFrontend*);
+    virtual void clearFrontend();
+    virtual void restore();
+
+    virtual void takeHeapSnapshot(ErrorString*, const bool* reportProgress);
+
+    virtual void getObjectByHeapObjectId(ErrorString*, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result);
+    virtual void getHeapObjectId(ErrorString*, const String& objectId, String* heapSnapshotObjectId);
+
+    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
+
+private:
+    InspectorHeapProfilerAgent(InstrumentingAgents*, InspectorCompositeState*, InjectedScriptManager*);
+
+    typedef HashMap<unsigned, RefPtr<ScriptHeapSnapshot> > IdToHeapSnapshotMap;
+
+    void resetFrontendProfiles();
+
+    PassRefPtr<TypeBuilder::HeapProfiler::ProfileHeader> createSnapshotHeader(const ScriptHeapSnapshot&);
+
+    InjectedScriptManager* m_injectedScriptManager;
+    InspectorFrontend::HeapProfiler* m_frontend;
+    bool m_headersRequested;
+    unsigned m_nextUserInitiatedHeapSnapshotNumber;
+    IdToHeapSnapshotMap m_snapshots;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
+
+#endif // !defined(InspectorHeapProfilerAgent_h)
index a1f501d..a30d15f 100644 (file)
@@ -56,6 +56,7 @@
 #include "InspectorDOMAgent.h"
 #include "InspectorDOMStorageAgent.h"
 #include "InspectorDebuggerAgent.h"
+#include "InspectorHeapProfilerAgent.h"
 #include "InspectorLayerTreeAgent.h"
 #include "InspectorPageAgent.h"
 #include "InspectorProfilerAgent.h"
@@ -924,6 +925,8 @@ void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents* instrument
 #if ENABLE(JAVASCRIPT_DEBUGGER) && USE(JSC)
         if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent())
             profilerAgent->resetState();
+        if (InspectorHeapProfilerAgent* heapProfilerAgent = instrumentingAgents->inspectorHeapProfilerAgent())
+            heapProfilerAgent->resetState();
 #endif
         if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
             cssAgent->reset();
index 2a8287e..cd8a2d9 100644 (file)
@@ -49,6 +49,7 @@ class InspectorDOMStorageAgent;
 class InspectorDatabaseAgent;
 class InspectorDebuggerAgent;
 class InspectorFileSystemAgent;
+class InspectorHeapProfilerAgent;
 class InspectorLayerTreeAgent;
 class InspectorPageAgent;
 class InspectorProfilerAgent;
@@ -127,6 +128,9 @@ public:
 
     InspectorProfilerAgent* inspectorProfilerAgent() const { return m_inspectorProfilerAgent; }
     void setInspectorProfilerAgent(InspectorProfilerAgent* agent) { m_inspectorProfilerAgent = agent; }
+
+    InspectorHeapProfilerAgent* inspectorHeapProfilerAgent() const { return m_inspectorHeapProfilerAgent; }
+    void setInspectorHeapProfilerAgent(InspectorHeapProfilerAgent* agent) { m_inspectorHeapProfilerAgent = agent; }
 #endif
 
 #if ENABLE(WORKERS)
@@ -170,6 +174,7 @@ private:
     PageDebuggerAgent* m_pageDebuggerAgent;
     InspectorDOMDebuggerAgent* m_inspectorDOMDebuggerAgent;
     InspectorProfilerAgent* m_inspectorProfilerAgent;
+    InspectorHeapProfilerAgent* m_inspectorHeapProfilerAgent;
 #endif
 #if ENABLE(WORKERS)
     InspectorWorkerAgent* m_inspectorWorkerAgent;
index 9c75c93..7004ae9 100644 (file)
@@ -41,6 +41,7 @@
 #include "InspectorConsoleAgent.h"
 #include "InspectorFrontend.h"
 #include "InspectorFrontendChannel.h"
+#include "InspectorHeapProfilerAgent.h"
 #include "InspectorProfilerAgent.h"
 #include "InspectorState.h"
 #include "InspectorStateClient.h"
@@ -110,6 +111,7 @@ WorkerInspectorController::WorkerInspectorController(WorkerContext* workerContex
     m_agents.append(debuggerAgent.release());
 
     m_agents.append(InspectorProfilerAgent::create(m_instrumentingAgents.get(), consoleAgent.get(), workerContext, m_state.get(), m_injectedScriptManager.get()));
+    m_agents.append(InspectorHeapProfilerAgent::create(m_instrumentingAgents.get(), m_state.get(), m_injectedScriptManager.get()));
 #endif
     m_agents.append(InspectorTimelineAgent::create(m_instrumentingAgents.get(), 0, m_state.get(), InspectorTimelineAgent::WorkerInspector, 0));
     m_agents.append(consoleAgent.release());
index 11b349a..de38bc6 100644 (file)
@@ -134,7 +134,7 @@ WebInspector.HeapSnapshotSortableDataGrid.prototype = {
     },
 
     /**
-     * @param {ProfilerAgent.HeapSnapshotObjectId} heapSnapshotObjectId
+     * @param {HeapProfilerAgent.HeapSnapshotObjectId} heapSnapshotObjectId
      */
     highlightObjectByHeapSnapshotId: function(heapSnapshotObjectId)
     {
@@ -528,7 +528,7 @@ WebInspector.HeapSnapshotConstructorsDataGrid.prototype = {
 
     /**
      * @override
-     * @param {ProfilerAgent.HeapSnapshotObjectId} id
+     * @param {HeapProfilerAgent.HeapSnapshotObjectId} id
      */
     highlightObjectByHeapSnapshotId: function(id)
     {
@@ -734,7 +734,7 @@ WebInspector.HeapSnapshotDominatorsDataGrid.prototype = {
 
     /**
      * @override
-     * @param {ProfilerAgent.HeapSnapshotObjectId} id
+     * @param {HeapProfilerAgent.HeapSnapshotObjectId} id
      */
     highlightObjectByHeapSnapshotId: function(id)
     {
index f2941c7..c9e400b 100644 (file)
@@ -465,7 +465,7 @@ WebInspector.HeapSnapshotGenericObjectNode.prototype = {
                 else
                     callback(WebInspector.RemoteObject.fromPrimitiveValue(WebInspector.UIString("Not available")));
             }
-            ProfilerAgent.getObjectByHeapObjectId(String(this.snapshotNodeId), objectGroupName, formatResult);
+            HeapProfilerAgent.getObjectByHeapObjectId(String(this.snapshotNodeId), objectGroupName, formatResult);
         }
     },
 
index df98db1..1720e9a 100644 (file)
@@ -801,7 +801,7 @@ WebInspector.HeapSnapshotProfileType.prototype = {
 
     /**
      * @override
-     * @param {ProfilerAgent.ProfileHeader} profile
+     * @param {HeapProfilerAgent.ProfileHeader} profile
      * @return {WebInspector.ProfileHeader}
      */
     createProfile: function(profile)
@@ -879,7 +879,7 @@ WebInspector.HeapProfileHeader.prototype = {
 
     startSnapshotTransfer: function()
     {
-        ProfilerAgent.getHeapSnapshot(this.uid);
+        HeapProfilerAgent.getHeapSnapshot(this.uid);
     },
 
     snapshotConstructorName: function()
@@ -986,7 +986,7 @@ WebInspector.HeapProfileHeader.prototype = {
             this._receiver = fileOutputStream;
             this._savedChunks = 0;
             this._updateTransferProgress(0, this._totalNumberOfChunks);
-            ProfilerAgent.getHeapSnapshot(this.uid);
+            HeapProfilerAgent.getHeapSnapshot(this.uid);
         }
         this._savingToFile = true;
         this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".heapsnapshot";
index 5b418de..b916a6e 100644 (file)
@@ -306,6 +306,7 @@ WebInspector.ProfilesPanel = function()
         this._registerProfileType(new WebInspector.CanvasProfileType());
 
     InspectorBackend.registerProfilerDispatcher(new WebInspector.ProfilerDispatcher(this));
+    InspectorBackend.registerHeapProfilerDispatcher(new WebInspector.HeapProfilerDispatcher(this));
     InspectorBackend.registerMemoryDispatcher(new WebInspector.MemoryDispatcher(this));
 
     this._createFileSelectorElement();
@@ -467,12 +468,13 @@ WebInspector.ProfilesPanel.prototype = {
     _clearProfiles: function()
     {
         ProfilerAgent.clearProfiles();
+        HeapProfilerAgent.clearProfiles();
         this._reset();
     },
 
     _garbageCollectButtonClicked: function()
     {
-        ProfilerAgent.collectGarbage();
+        HeapProfilerAgent.collectGarbage();
     },
 
     /**
@@ -625,8 +627,12 @@ WebInspector.ProfilesPanel.prototype = {
 
         sidebarParent.removeChild(profile._profilesTreeElement);
 
-        if (!profile.isTemporary)
-            ProfilerAgent.removeProfile(profile.profileType().id, profile.uid);
+        if (!profile.isTemporary) {
+            if (profile.profileType().id == WebInspector.HeapSnapshotProfileType.TypeId)
+                HeapProfilerAgent.removeProfile(profile.uid);
+            else
+                ProfilerAgent.removeProfile(profile.profileType().id, profile.uid);
+        }
 
         // No other item will be selected if there aren't any other profiles, so
         // make sure that view gets cleared when the last profile is removed.
@@ -684,7 +690,7 @@ WebInspector.ProfilesPanel.prototype = {
     },
 
     /**
-     * @param {ProfilerAgent.HeapSnapshotObjectId} snapshotObjectId
+     * @param {HeapProfilerAgent.HeapSnapshotObjectId} snapshotObjectId
      * @param {string} viewName
      */
     showObject: function(snapshotObjectId, viewName)
@@ -1087,22 +1093,24 @@ WebInspector.ProfilesPanel.prototype = {
             return;
 
         /**
+         * @param {?string} type
          * @param {?string} error
          * @param {Array.<ProfilerAgent.ProfileHeader>} profileHeaders
          */
-        function populateCallback(error, profileHeaders) {
+        function populateCallback(type, error, profileHeaders) {
             if (error)
                 return;
             profileHeaders.sort(function(a, b) { return a.uid - b.uid; });
             var profileHeadersLength = profileHeaders.length;
             for (var i = 0; i < profileHeadersLength; ++i) {
                 var profileHeader = profileHeaders[i];
-                var profileType = this.getProfileType(profileHeader.typeId);
+                var profileType = this.getProfileType(type || profileHeader.typeId);
                 this.addProfileHeader(profileType.createProfile(profileHeader));
             }
         }
 
-        ProfilerAgent.getProfileHeaders(populateCallback.bind(this));
+        ProfilerAgent.getProfileHeaders(populateCallback.bind(this, null));
+        HeapProfilerAgent.getProfileHeaders(populateCallback.bind(this, WebInspector.HeapSnapshotProfileType.TypeId));
 
         this._profilesWereRequested = true;
     },
@@ -1164,7 +1172,7 @@ WebInspector.ProfilesPanel.prototype = {
         function done() {
             this._launcherView.profileFinished();
         }
-        ProfilerAgent.takeHeapSnapshot(true, done.bind(this));
+        HeapProfilerAgent.takeHeapSnapshot(true, done.bind(this));
         WebInspector.userMetrics.ProfilesHeapProfileTaken.record();
     },
 
@@ -1203,7 +1211,7 @@ WebInspector.ProfilesPanel.prototype = {
 
         function revealInView(viewName)
         {
-            ProfilerAgent.getHeapObjectId(objectId, didReceiveHeapObjectId.bind(this, viewName));
+            HeapProfilerAgent.getHeapObjectId(objectId, didReceiveHeapObjectId.bind(this, viewName));
         }
 
         function didReceiveHeapObjectId(viewName, error, result)
@@ -1316,6 +1324,64 @@ WebInspector.ProfilerDispatcher.prototype = {
 
 /**
  * @constructor
+ * @implements {HeapProfilerAgent.Dispatcher}
+ * @param {WebInspector.ProfilesPanel} profilesPanel
+ */
+WebInspector.HeapProfilerDispatcher = function(profilesPanel)
+{
+    this._profilesPanel = profilesPanel;
+}
+
+WebInspector.HeapProfilerDispatcher.prototype = {
+    /**
+     * @param {HeapProfilerAgent.ProfileHeader} profile
+     */
+    addProfileHeader: function(profile)
+    {
+        var profileType = this._profilesPanel.getProfileType(WebInspector.HeapSnapshotProfileType.TypeId);
+        this._profilesPanel.addProfileHeader(profileType.createProfile(profile));
+    },
+
+    /**
+     * @override
+     * @param {number} uid
+     * @param {string} chunk
+     */
+    addHeapSnapshotChunk: function(uid, chunk)
+    {
+        this._profilesPanel._addHeapSnapshotChunk(uid, chunk);
+    },
+
+    /**
+     * @override
+     * @param {number} uid
+     */
+    finishHeapSnapshot: function(uid)
+    {
+        this._profilesPanel._finishHeapSnapshot(uid);
+    },
+
+    /**
+     * @override
+     */
+    resetProfiles: function()
+    {
+        this._profilesPanel._reset();
+    },
+
+    /**
+     * @override
+     * @param {number} done
+     * @param {number} total
+     */
+    reportHeapSnapshotProgress: function(done, total)
+    {
+        this._profilesPanel._reportHeapSnapshotProgress(done, total);
+    }
+}
+
+/**
+ * @constructor
  * @extends {WebInspector.SidebarTreeElement}
  * @param {!WebInspector.ProfileHeader} profile
  * @param {string} titleFormat
index a33beee..f1b32ea 100644 (file)
@@ -580,7 +580,7 @@ WebInspector.TimelinePanel.prototype = {
 
     _garbageCollectButtonClicked: function()
     {
-        ProfilerAgent.collectGarbage();
+        HeapProfilerAgent.collectGarbage();
     },
 
     _glueParentButtonClicked: function()
index e38c35c..1dc8a24 100644 (file)
@@ -368,7 +368,7 @@ WebInspector.doLoadedDone = function()
     DebuggerAgent.supportsSeparateScriptCompilationAndExecution(WebInspector._initializeCapability.bind(WebInspector, "separateScriptCompilationAndExecutionEnabled", null));
     ProfilerAgent.causesRecompilation(WebInspector._initializeCapability.bind(WebInspector, "profilerCausesRecompilation", null));
     ProfilerAgent.isSampling(WebInspector._initializeCapability.bind(WebInspector, "samplingCPUProfiler", null));
-    ProfilerAgent.hasHeapProfiler(WebInspector._initializeCapability.bind(WebInspector, "heapProfilerPresent", null));
+    HeapProfilerAgent.hasHeapProfiler(WebInspector._initializeCapability.bind(WebInspector, "heapProfilerPresent", null));
     TimelineAgent.supportsFrameInstrumentation(WebInspector._initializeCapability.bind(WebInspector, "timelineSupportsFrameInstrumentation", null));
     TimelineAgent.canMonitorMainThread(WebInspector._initializeCapability.bind(WebInspector, "timelineCanMonitorMainThread", null));
     PageAgent.canShowDebugBorders(WebInspector._initializeCapability.bind(WebInspector, "canShowDebugBorders", null));
index 9f67f03..2743e7a 100644 (file)
@@ -1,3 +1,19 @@
+2013-02-11  Alexei Filippov  <alph@chromium.org>
+
+        Web Inspector: Split Profiler domain in protocol into Profiler and HeapProfiler
+        https://bugs.webkit.org/show_bug.cgi?id=108653
+
+        Reviewed by Yury Semikhatsky.
+
+        Currently CPU and heap profilers share the same domain 'Profiler' in the protocol.
+        In fact these two profile types have not too much in common. So put each into its own domain.
+        It should also help when Profiles panel gets split into several tools.
+        This is the phase 1 which adds InspectorHeapProfilerAgent but doesn't
+        change the original InspectorProfilerAgent.
+
+        * src/WebDevToolsAgentImpl.cpp:
+        (WebKit::WebDevToolsAgent::shouldInterruptForMessage):
+
 2013-02-11  Abhishek Arya  <inferno@chromium.org>
 
         Add ASSERT_WITH_SECURITY_IMPLICATION to detect out of bounds access
index 4ea460a..6083d96 100644 (file)
@@ -778,7 +778,7 @@ bool WebDevToolsAgent::shouldInterruptForMessage(const WebString& message)
         || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_startCmd]
         || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_stopCmd]
         || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_getCPUProfileCmd]
-        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kProfiler_getHeapSnapshotCmd];
+        || commandName == InspectorBackendDispatcher::commandNames[InspectorBackendDispatcher::kHeapProfiler_getHeapSnapshotCmd];
 }
 
 void WebDevToolsAgent::processPendingMessages()