Title: [140823] trunk/Source/WebCore
Revision
140823
Author
[email protected]
Date
2013-01-25 06:37:24 -0800 (Fri, 25 Jan 2013)

Log Message

Refactor InspectorMemoryAgent: memory data as a map.

https://bugs.webkit.org/show_bug.cgi?id=107938

Patch by Marja Hölttä <[email protected]> on 2013-01-25
Reviewed by Yury Semikhatsky.

No new tests (no functional changes, only refactoring).

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::getProcessMemoryDistribution):
(WebCore):
* inspector/InspectorController.h:
(WebCore):
(InspectorController):
* inspector/InspectorMemoryAgent.cpp:
(WebCore::addPlatformComponentsInfo):
(WebCore):
(WebCore::addMemoryInstrumentationDebugData):
(WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
(WebCore::InspectorMemoryAgent::reportMemoryUsage):
(WebCore::InspectorMemoryAgent::getProcessMemoryDistributionAsMap):
* inspector/InspectorMemoryAgent.h:
(InspectorMemoryAgent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (140822 => 140823)


--- trunk/Source/WebCore/ChangeLog	2013-01-25 14:30:37 UTC (rev 140822)
+++ trunk/Source/WebCore/ChangeLog	2013-01-25 14:37:24 UTC (rev 140823)
@@ -1,3 +1,30 @@
+2013-01-25  Marja Hölttä  <[email protected]>
+
+        Refactor InspectorMemoryAgent: memory data as a map.
+
+        https://bugs.webkit.org/show_bug.cgi?id=107938
+
+        Reviewed by Yury Semikhatsky.
+
+        No new tests (no functional changes, only refactoring).
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::getProcessMemoryDistribution):
+        (WebCore):
+        * inspector/InspectorController.h:
+        (WebCore):
+        (InspectorController):
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore::addPlatformComponentsInfo):
+        (WebCore):
+        (WebCore::addMemoryInstrumentationDebugData):
+        (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
+        (WebCore::InspectorMemoryAgent::reportMemoryUsage):
+        (WebCore::InspectorMemoryAgent::getProcessMemoryDistributionAsMap):
+        * inspector/InspectorMemoryAgent.h:
+        (InspectorMemoryAgent):
+
 2013-01-25  Huang Dongsung  <[email protected]>
 
         [Texmap] Refactor code related to debug border and repaint count.

Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (140822 => 140823)


--- trunk/Source/WebCore/inspector/InspectorController.cpp	2013-01-25 14:30:37 UTC (rev 140822)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp	2013-01-25 14:37:24 UTC (rev 140823)
@@ -119,7 +119,11 @@
     OwnPtr<InspectorDOMStorageAgent> domStorageAgentPtr(InspectorDOMStorageAgent::create(m_instrumentingAgents.get(), m_state.get()));
     InspectorDOMStorageAgent* domStorageAgent = domStorageAgentPtr.get();
     m_agents.append(domStorageAgentPtr.release());
-    m_agents.append(InspectorMemoryAgent::create(m_instrumentingAgents.get(), inspectorClient, m_state.get(), m_page));
+
+    OwnPtr<InspectorMemoryAgent> memoryAgentPtr(InspectorMemoryAgent::create(m_instrumentingAgents.get(), inspectorClient, m_state.get(), m_page));
+    m_memoryAgent = memoryAgentPtr.get();
+    m_agents.append(memoryAgentPtr.release());
+
     m_agents.append(InspectorTimelineAgent::create(m_instrumentingAgents.get(), pageAgent, m_state.get(), InspectorTimelineAgent::PageInspector,
        inspectorClient));
     m_agents.append(InspectorApplicationCacheAgent::create(m_instrumentingAgents.get(), m_state.get(), pageAgent));
@@ -438,6 +442,14 @@
 #endif
 }
 
+HashMap<String, size_t> InspectorController::processMemoryDistribution() const
+{
+    HashMap<String, size_t> memoryInfo;
+    RefPtr<InspectorObject> graph;
+    m_memoryAgent->getProcessMemoryDistributionAsMap(false, graph, &memoryInfo);
+    return memoryInfo;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR)

Modified: trunk/Source/WebCore/inspector/InspectorController.h (140822 => 140823)


--- trunk/Source/WebCore/inspector/InspectorController.h	2013-01-25 14:30:37 UTC (rev 140822)
+++ trunk/Source/WebCore/inspector/InspectorController.h	2013-01-25 14:37:24 UTC (rev 140823)
@@ -56,6 +56,7 @@
 class InspectorFrontend;
 class InspectorFrontendChannel;
 class InspectorFrontendClient;
+class InspectorMemoryAgent;
 class InspectorOverlay;
 class InspectorPageAgent;
 class InspectorProfilerAgent;
@@ -124,6 +125,8 @@
     void willProcessTask();
     void didProcessTask();
 
+    HashMap<String, size_t> processMemoryDistribution() const;
+
 private:
     InspectorController(Page*, InspectorClient*);
 
@@ -139,6 +142,7 @@
     InspectorDOMAgent* m_domAgent;
     InspectorResourceAgent* m_resourceAgent;
     InspectorPageAgent* m_pageAgent;
+    InspectorMemoryAgent* m_memoryAgent;
 #if ENABLE(_javascript__DEBUGGER)
     InspectorDebuggerAgent* m_debuggerAgent;
     InspectorDOMDebuggerAgent* m_domDebuggerAgent;

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (140822 => 140823)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2013-01-25 14:30:37 UTC (rev 140822)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2013-01-25 14:37:24 UTC (rev 140823)
@@ -81,11 +81,11 @@
 
 class MemoryUsageStatsGenerator {
 public:
-    MemoryUsageStatsGenerator(MemoryInstrumentationClientImpl* client) : m_client(client) { }
+    MemoryUsageStatsGenerator() { }
 
-    void dump(InspectorMemoryBlocks* children)
+    void dump(const TypeNameToSizeMap& sizesMap, InspectorMemoryBlocks* children)
     {
-        m_sizesMap = m_client->sizesMap();
+        m_sizesMap = sizesMap;
 
         // FIXME: We filter out Rendering type because the coverage is not good enough at the moment
         // and report RenderArena size instead.
@@ -109,7 +109,6 @@
         while (index < objectTypes.size())
             index = buildObjectForIndex(index, objectTypes, children);
 
-        addMemoryInstrumentationDebugData(children);
     }
 
 private:
@@ -147,21 +146,6 @@
         return index;
     }
 
-    void addMemoryInstrumentationDebugData(InspectorMemoryBlocks* children)
-    {
-        if (m_client->checkInstrumentedObjects()) {
-            RefPtr<InspectorMemoryBlock> totalInstrumented = InspectorMemoryBlock::create().setName("InstrumentedObjectsCount");
-            totalInstrumented->setSize(m_client->totalCountedObjects());
-
-            RefPtr<InspectorMemoryBlock> incorrectlyInstrumented = InspectorMemoryBlock::create().setName("InstrumentedButNotAllocatedObjectsCount");
-            incorrectlyInstrumented->setSize(m_client->totalObjectsNotInAllocatedSet());
-
-            children->addItem(totalInstrumented);
-            children->addItem(incorrectlyInstrumented);
-        }
-    }
-
-    MemoryInstrumentationClientImpl* m_client;
     TypeNameToSizeMap m_sizesMap;
 };
 
@@ -527,21 +511,52 @@
     domTreesIterator.visitMemoryCache();
 }
 
-static void addPlatformComponentsInfo(PassRefPtr<InspectorMemoryBlocks> children)
+static void addPlatformComponentsInfo(TypeNameToSizeMap* memoryInfo)
 {
     Vector<MemoryUsageSupport::ComponentInfo> components;
     MemoryUsageSupport::memoryUsageByComponents(components);
-    for (Vector<MemoryUsageSupport::ComponentInfo>::iterator it = components.begin(); it != components.end(); ++it) {
-        RefPtr<InspectorMemoryBlock> block = InspectorMemoryBlock::create().setName(it->m_name);
-        block->setSize(it->m_sizeInBytes);
-        children->addItem(block);
+    for (Vector<MemoryUsageSupport::ComponentInfo>::iterator it = components.begin(); it != components.end(); ++it)
+        memoryInfo->add(it->m_name, it->m_sizeInBytes);
+}
+
+static void addMemoryInstrumentationDebugData(MemoryInstrumentationClientImpl* client, TypeNameToSizeMap* memoryInfo)
+{
+    if (client->checkInstrumentedObjects()) {
+        memoryInfo->add("InstrumentedObjectsCount", client->totalCountedObjects());
+        memoryInfo->add("InstrumentedButNotAllocatedObjectsCount", client->totalObjectsNotInAllocatedSet());
     }
 }
 
 void InspectorMemoryAgent::getProcessMemoryDistribution(ErrorString*, const bool* reportGraph, RefPtr<InspectorMemoryBlock>& processMemory, RefPtr<InspectorObject>& graph)
 {
+    TypeNameToSizeMap memoryInfo;
+    getProcessMemoryDistributionAsMap(reportGraph && *reportGraph, graph, &memoryInfo);
+
+    MemoryUsageStatsGenerator statsGenerator;
+    RefPtr<InspectorMemoryBlocks> children = InspectorMemoryBlocks::create();
+    statsGenerator.dump(memoryInfo, children.get());
+
+    processMemory = InspectorMemoryBlock::create().setName(WebCoreMemoryTypes::ProcessPrivateMemory);
+    processMemory->setChildren(children);
+
+    size_t privateBytes = 0;
+    size_t sharedBytes = 0;
+    MemoryUsageSupport::processMemorySizesInBytes(&privateBytes, &sharedBytes);
+    processMemory->setSize(privateBytes);
+}
+
+void InspectorMemoryAgent::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Inspector);
+    InspectorBaseAgent<InspectorMemoryAgent>::reportMemoryUsage(memoryObjectInfo);
+    info.addWeakPointer(m_inspectorClient);
+    info.addMember(m_page);
+}
+
+void InspectorMemoryAgent::getProcessMemoryDistributionAsMap(bool reportGraph, RefPtr<InspectorObject>& graph, TypeNameToSizeMap* memoryInfo)
+{
     OwnPtr<HeapGraphSerializer> graphSerializer;
-    if (reportGraph && *reportGraph)
+    if (reportGraph)
         graphSerializer = adoptPtr(new HeapGraphSerializer());
     MemoryInstrumentationClientImpl memoryInstrumentationClient(graphSerializer.get());
     m_inspectorClient->getAllocatedObjects(memoryInstrumentationClient.allocatedObjects());
@@ -554,9 +569,6 @@
     PlatformMemoryInstrumentation::reportStaticMembersMemoryUsage(&memoryInstrumentation);
     WebCoreMemoryInstrumentation::reportStaticMembersMemoryUsage(&memoryInstrumentation);
 
-    RefPtr<InspectorMemoryBlocks> children = InspectorMemoryBlocks::create();
-    addPlatformComponentsInfo(children);
-
     memoryInstrumentation.addRootObject(this);
     memoryInstrumentation.addRootObject(memoryInstrumentation);
     memoryInstrumentation.addRootObject(memoryInstrumentationClient);
@@ -567,26 +579,11 @@
 
     m_inspectorClient->dumpUncountedAllocatedObjects(memoryInstrumentationClient.countedObjects());
 
-    MemoryUsageStatsGenerator statsGenerator(&memoryInstrumentationClient);
-    statsGenerator.dump(children.get());
-
-    processMemory = InspectorMemoryBlock::create().setName(WebCoreMemoryTypes::ProcessPrivateMemory);
-    processMemory->setChildren(children);
-
-    size_t privateBytes = 0;
-    size_t sharedBytes = 0;
-    MemoryUsageSupport::processMemorySizesInBytes(&privateBytes, &sharedBytes);
-    processMemory->setSize(privateBytes);
+    *memoryInfo = memoryInstrumentationClient.sizesMap();
+    addPlatformComponentsInfo(memoryInfo);
+    addMemoryInstrumentationDebugData(&memoryInstrumentationClient, memoryInfo);
 }
 
-void InspectorMemoryAgent::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
-{
-    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Inspector);
-    InspectorBaseAgent<InspectorMemoryAgent>::reportMemoryUsage(memoryObjectInfo);
-    info.addWeakPointer(m_inspectorClient);
-    info.addMember(m_page);
-}
-
 InspectorMemoryAgent::InspectorMemoryAgent(InstrumentingAgents* instrumentingAgents, InspectorClient* client, InspectorCompositeState* state, Page* page)
     : InspectorBaseAgent<InspectorMemoryAgent>("Memory", instrumentingAgents, state)
     , m_inspectorClient(client)

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.h (140822 => 140823)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.h	2013-01-25 14:30:37 UTC (rev 140822)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.h	2013-01-25 14:37:24 UTC (rev 140823)
@@ -63,6 +63,8 @@
 
     virtual void reportMemoryUsage(MemoryObjectInfo*) const;
 
+    void getProcessMemoryDistributionAsMap(bool reportGraph, RefPtr<InspectorObject>& graph, HashMap<String, size_t>* memoryInfo);
+
 private:
     InspectorMemoryAgent(InstrumentingAgents*, InspectorClient*, InspectorCompositeState*, Page*);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to