Title: [118357] trunk/Source
Revision
118357
Author
[email protected]
Date
2012-05-24 06:01:53 -0700 (Thu, 24 May 2012)

Log Message

Web Inspector: add a command to InspectorMemoryAgent for getting process memory break down
https://bugs.webkit.org/show_bug.cgi?id=87263

Reviewed by Pavel Feldman.

Source/WebCore:

Introduced new protocol command Memory.getProcessMemoryDistribution which returns
memory distribution for the inspected process. Currently only JS allocated and used
heap size is included.

* inspector/Inspector.json:
* inspector/InspectorMemoryAgent.cpp:
(WebCore::jsHeapInfo):
(WebCore):
(WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
* inspector/InspectorMemoryAgent.h:
(InspectorMemoryAgent):
* platform/chromium/PlatformSupport.h:
(PlatformSupport):

Source/WebKit/chromium:

Added an API for retrieving render process private and shared memory in bytes.

* public/platform/WebKitPlatformSupport.h:
(WebKitPlatformSupport):
(WebKit::WebKitPlatformSupport::getProcessMemorySize):
* src/PlatformSupport.cpp:
(WebCore::PlatformSupport::getProcessMemorySize):
(WebCore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (118356 => 118357)


--- trunk/Source/WebCore/ChangeLog	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebCore/ChangeLog	2012-05-24 13:01:53 UTC (rev 118357)
@@ -1,3 +1,24 @@
+2012-05-23  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: add a command to InspectorMemoryAgent for getting process memory break down
+        https://bugs.webkit.org/show_bug.cgi?id=87263
+
+        Reviewed by Pavel Feldman.
+
+        Introduced new protocol command Memory.getProcessMemoryDistribution which returns
+        memory distribution for the inspected process. Currently only JS allocated and used
+        heap size is included.
+
+        * inspector/Inspector.json:
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore::jsHeapInfo):
+        (WebCore):
+        (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
+        * inspector/InspectorMemoryAgent.h:
+        (InspectorMemoryAgent):
+        * platform/chromium/PlatformSupport.h:
+        (PlatformSupport):
+
 2012-05-24  Nikolas Zimmermann  <[email protected]>
 
         SVGZoomAndPan constants are missing from window object

Modified: trunk/Source/WebCore/inspector/Inspector.json (118356 => 118357)


--- trunk/Source/WebCore/inspector/Inspector.json	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebCore/inspector/Inspector.json	2012-05-24 13:01:53 UTC (rev 118357)
@@ -87,6 +87,15 @@
                     { "name": "nodeCount", "type": "array", "items": { "$ref": "NodeCount" }},
                     { "name": "listenerCount", "type": "array", "items": { "$ref": "ListenerCount" }}
                 ]
+            },
+            {
+                "id": "MemoryBlock",
+                "type": "object",
+                "properties": [
+                    { "name": "size", "type": "integer", "optional":true, "description": "Size of the block in bytes if available" },
+                    { "name": "name", "type": "string", "description": "Unique name used to identify the component that allocated this block" },
+                    { "name": "children", "type": "array", "optional": true, "items": { "$ref": "MemoryBlock" }}
+                ]
             }
         ],
         "commands": [
@@ -96,6 +105,12 @@
                     { "name": "domGroups", "type": "array", "items": { "$ref": "DOMGroup" }},
                     { "name": "strings", "$ref": "StringStatistics" }
                 ]
+            },
+            {
+                "name": "getProcessMemoryDistribution",
+                "returns": [
+                    { "name": "distribution", "$ref": "MemoryBlock", "description": "An object describing all memory allocated by the process"}
+                ]
             }
         ]
     },

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (118356 => 118357)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2012-05-24 13:01:53 UTC (rev 118357)
@@ -45,6 +45,10 @@
 #include "InstrumentingAgents.h"
 #include "Node.h"
 #include "Page.h"
+#if PLATFORM(CHROMIUM)
+#include "PlatformSupport.h"
+#endif
+#include "ScriptGCEvent.h"
 #include "ScriptProfiler.h"
 #include "StyledElement.h"
 #include <wtf/HashSet.h>
@@ -52,11 +56,18 @@
 
 using WebCore::TypeBuilder::Memory::DOMGroup;
 using WebCore::TypeBuilder::Memory::ListenerCount;
+using WebCore::TypeBuilder::Memory::MemoryBlock;
 using WebCore::TypeBuilder::Memory::NodeCount;
 using WebCore::TypeBuilder::Memory::StringStatistics;
 
 namespace WebCore {
 
+namespace MemoryBlockName {
+static const char totalJsHeap[] = "TotalJSHeap";
+static const char processPrivateMemory[] = "ProcessPrivateMemory";
+static const char usedJsHeap[] = "UsedJSHeap";
+}
+
 namespace {
 
 String nodeName(Node* node)
@@ -307,6 +318,40 @@
     strings = counterVisitor.strings();
 }
 
+static PassRefPtr<MemoryBlock> jsHeapInfo()
+{
+    size_t usedJSHeapSize;
+    size_t totalJSHeapSize;
+    size_t jsHeapSizeLimit;
+    ScriptGCEvent::getHeapSize(usedJSHeapSize, totalJSHeapSize, jsHeapSizeLimit);
+
+    RefPtr<MemoryBlock> totalJsHeap = MemoryBlock::create().setName(MemoryBlockName::totalJsHeap);
+    totalJsHeap->setSize(totalJSHeapSize);
+
+    RefPtr<TypeBuilder::Array<MemoryBlock> > children = TypeBuilder::Array<MemoryBlock>::create();
+    RefPtr<MemoryBlock> usedJsHeap = MemoryBlock::create().setName(MemoryBlockName::usedJsHeap);
+    usedJsHeap->setSize(usedJSHeapSize);
+    children->addItem(usedJsHeap);
+
+    totalJsHeap->setChildren(children);
+    return totalJsHeap.release();
+}
+
+void InspectorMemoryAgent::getProcessMemoryDistribution(ErrorString*, RefPtr<MemoryBlock>& processMemory)
+{
+    size_t privateBytes = 0;
+#if PLATFORM(CHROMIUM)
+    size_t sharedBytes = 0;
+    PlatformSupport::getProcessMemorySize(&privateBytes, &sharedBytes);
+#endif
+    processMemory = MemoryBlock::create().setName(MemoryBlockName::processPrivateMemory);
+    processMemory->setSize(privateBytes);
+
+    RefPtr<TypeBuilder::Array<MemoryBlock> > children = TypeBuilder::Array<MemoryBlock>::create();
+    children->addItem(jsHeapInfo());
+    processMemory->setChildren(children);
+}
+
 InspectorMemoryAgent::InspectorMemoryAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page, InspectorDOMAgent* domAgent)
     : InspectorBaseAgent<InspectorMemoryAgent>("Memory", instrumentingAgents, state)
     , m_page(page)

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.h (118356 => 118357)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.h	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.h	2012-05-24 13:01:53 UTC (rev 118357)
@@ -56,10 +56,11 @@
     {
         return adoptPtr(new InspectorMemoryAgent(instrumentingAgents, state, page, domAgent));
     }
+    virtual ~InspectorMemoryAgent();
 
-    void getDOMNodeCount(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Memory::DOMGroup> >& domGroups, RefPtr<TypeBuilder::Memory::StringStatistics>& strings);
+    virtual void getDOMNodeCount(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Memory::DOMGroup> >& domGroups, RefPtr<TypeBuilder::Memory::StringStatistics>& strings);
+    virtual void getProcessMemoryDistribution(ErrorString*, RefPtr<TypeBuilder::Memory::MemoryBlock>& processMemory);
 
-    ~InspectorMemoryAgent();
 
 private:
     InspectorMemoryAgent(InstrumentingAgents*, InspectorState*, Page*, InspectorDOMAgent* domAgent);

Modified: trunk/Source/WebCore/inspector/InspectorTimelineAgent.cpp (118356 => 118357)


--- trunk/Source/WebCore/inspector/InspectorTimelineAgent.cpp	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebCore/inspector/InspectorTimelineAgent.cpp	2012-05-24 13:01:53 UTC (rev 118357)
@@ -56,7 +56,7 @@
 static const char includeMemoryDetails[] = "includeMemoryDetails";
 }
 
-// Must be kept in sync with TimelineAgent.js
+// Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineModel.js
 namespace TimelineRecordType {
 static const char EventDispatch[] = "EventDispatch";
 static const char BeginFrame[] = "BeginFrame";

Modified: trunk/Source/WebCore/platform/chromium/PlatformSupport.h (118356 => 118357)


--- trunk/Source/WebCore/platform/chromium/PlatformSupport.h	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebCore/platform/chromium/PlatformSupport.h	2012-05-24 13:01:53 UTC (rev 118357)
@@ -213,6 +213,10 @@
     static void setSharedTimerFiredFunction(void (*func)());
     static void setSharedTimerFireInterval(double);
 
+    // Returns private and shared usage, in bytes. Private bytes is the amount of
+    // memory currently allocated to this process that cannot be shared. Returns
+    // false on platform specific error conditions.
+    static bool getProcessMemorySize(size_t* privateBytes, size_t* sharedBytes);
     // Theming ------------------------------------------------------------
 #if OS(WINDOWS)
     static void paintButton(

Modified: trunk/Source/WebKit/chromium/ChangeLog (118356 => 118357)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-05-24 13:01:53 UTC (rev 118357)
@@ -1,3 +1,19 @@
+2012-05-23  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: add a command to InspectorMemoryAgent for getting process memory break down
+        https://bugs.webkit.org/show_bug.cgi?id=87263
+
+        Reviewed by Pavel Feldman.
+
+        Added an API for retrieving render process private and shared memory in bytes.
+
+        * public/platform/WebKitPlatformSupport.h:
+        (WebKitPlatformSupport):
+        (WebKit::WebKitPlatformSupport::getProcessMemorySize):
+        * src/PlatformSupport.cpp:
+        (WebCore::PlatformSupport::getProcessMemorySize):
+        (WebCore):
+
 2012-05-24  Hironori Bono  <[email protected]>
 
         Enable grammar checking on Chromium when we paste text.

Modified: trunk/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h (118356 => 118357)


--- trunk/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h	2012-05-24 13:01:53 UTC (rev 118357)
@@ -128,6 +128,10 @@
 
     virtual WebSharedWorkerRepository* sharedWorkerRepository() { return 0; }
 
+    // Returns private and shared usage, in bytes. Private bytes is the amount of
+    // memory currently allocated to this process that cannot be shared. Returns
+    // false on platform specific error conditions.
+    virtual bool getProcessMemorySize(size_t* privateBytes, size_t* sharedBytes) { return false; }
 
 protected:
     ~WebKitPlatformSupport() { }

Modified: trunk/Source/WebKit/chromium/src/PlatformSupport.cpp (118356 => 118357)


--- trunk/Source/WebKit/chromium/src/PlatformSupport.cpp	2012-05-24 13:00:54 UTC (rev 118356)
+++ trunk/Source/WebKit/chromium/src/PlatformSupport.cpp	2012-05-24 13:01:53 UTC (rev 118357)
@@ -837,6 +837,11 @@
     webFrame->client()->didExhaustMemoryAvailableForScript(webFrame);
 }
 
+bool PlatformSupport::getProcessMemorySize(size_t* privateBytes, size_t* sharedBytes)
+{
+    return webKitPlatformSupport()->getProcessMemorySize(privateBytes, sharedBytes);
+}
+
 int PlatformSupport::screenHorizontalDPI(Widget* widget)
 {
     WebWidgetClient* client = toWebWidgetClient(widget);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to