Web Inspector: expose MemoryCache statistics in the inspector protocol
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Jun 2012 09:03:20 +0000 (09:03 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Jun 2012 09:03:20 +0000 (09:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87984

Reviewed by Pavel Feldman.

Added MemoryCache statistics to Memory.getProcessMemoryDistribution command
result. Corresponding sector is added to the memory pie-chart.

* inspector/InspectorMemoryAgent.cpp:
(MemoryBlockName):
(WebCore):
(WebCore::addMemoryBlockFor):
(WebCore::memoryCacheInfo):
(WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
* inspector/front-end/NativeMemorySnapshotView.js:
(WebInspector.MemoryBlockViewProperties._initialize):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorMemoryAgent.cpp
Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js

index ca6a863..1f7b13b 100644 (file)
@@ -1,5 +1,24 @@
 2012-05-31  Yury Semikhatsky  <yurys@chromium.org>
 
+        Web Inspector: expose MemoryCache statistics in the inspector protocol
+        https://bugs.webkit.org/show_bug.cgi?id=87984
+
+        Reviewed by Pavel Feldman.
+
+        Added MemoryCache statistics to Memory.getProcessMemoryDistribution command
+        result. Corresponding sector is added to the memory pie-chart.
+
+        * inspector/InspectorMemoryAgent.cpp:
+        (MemoryBlockName):
+        (WebCore):
+        (WebCore::addMemoryBlockFor):
+        (WebCore::memoryCacheInfo):
+        (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
+        * inspector/front-end/NativeMemorySnapshotView.js:
+        (WebInspector.MemoryBlockViewProperties._initialize):
+
+2012-05-31  Yury Semikhatsky  <yurys@chromium.org>
+
         Web Inspector: add RenderArena sizes to the memory pie-chart
         https://bugs.webkit.org/show_bug.cgi?id=87971
 
index 42c8de9..6095641 100644 (file)
@@ -43,6 +43,7 @@
 #include "InspectorState.h"
 #include "InspectorValues.h"
 #include "InstrumentingAgents.h"
+#include "MemoryCache.h"
 #include "MemoryUsageSupport.h"
 #include "Node.h"
 #include "Page.h"
@@ -57,12 +58,22 @@ using WebCore::TypeBuilder::Memory::ListenerCount;
 using WebCore::TypeBuilder::Memory::NodeCount;
 using WebCore::TypeBuilder::Memory::StringStatistics;
 
+// Use a type alias instead of 'using' here which would cause a conflict on Mac.
+typedef WebCore::TypeBuilder::Memory::MemoryBlock InspectorMemoryBlock;
+
 namespace WebCore {
 
 namespace MemoryBlockName {
 static const char jsHeapAllocated[] = "JSHeapAllocated";
 static const char jsHeapUsed[] = "JSHeapUsed";
+static const char memoryCache[] = "MemoryCache";
 static const char processPrivateMemory[] = "ProcessPrivateMemory";
+
+static const char cachedImages[] = "CachedImages";
+static const char cachedCssStyleSheets[] = "CachedCssStyleSheets";
+static const char cachedScripts[] = "CachedScripts";
+static const char cachedXslStyleSheets[] = "CachedXslStyleSheets";
+static const char cachedFonts[] = "CachedFonts";
 static const char renderTreeUsed[] = "RenderTreeUsed";
 static const char renderTreeAllocated[] = "RenderTreeAllocated";
 }
@@ -317,18 +328,18 @@ void InspectorMemoryAgent::getDOMNodeCount(ErrorString*, RefPtr<TypeBuilder::Arr
     strings = counterVisitor.strings();
 }
 
-static PassRefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> jsHeapInfo()
+static PassRefPtr<InspectorMemoryBlock> jsHeapInfo()
 {
     size_t usedJSHeapSize;
     size_t totalJSHeapSize;
     size_t jsHeapSizeLimit;
     ScriptGCEvent::getHeapSize(usedJSHeapSize, totalJSHeapSize, jsHeapSizeLimit);
 
-    RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> jsHeapAllocated = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::jsHeapAllocated);
+    RefPtr<InspectorMemoryBlock> jsHeapAllocated = InspectorMemoryBlock::create().setName(MemoryBlockName::jsHeapAllocated);
     jsHeapAllocated->setSize(static_cast<int>(totalJSHeapSize));
 
-    RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
-    RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> jsHeapUsed = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::jsHeapUsed);
+    RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
+    RefPtr<InspectorMemoryBlock> jsHeapUsed = InspectorMemoryBlock::create().setName(MemoryBlockName::jsHeapUsed);
     jsHeapUsed->setSize(static_cast<int>(usedJSHeapSize));
     children->addItem(jsHeapUsed);
 
@@ -336,15 +347,15 @@ static PassRefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> jsHeapInfo()
     return jsHeapAllocated.release();
 }
 
-static PassRefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> renderTreeInfo(Page* page)
+static PassRefPtr<InspectorMemoryBlock> renderTreeInfo(Page* page)
 {
     ArenaSize arenaSize = page->renderTreeSize();
 
-    RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> renderTreeAllocated = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::renderTreeAllocated);
+    RefPtr<InspectorMemoryBlock> renderTreeAllocated = InspectorMemoryBlock::create().setName(MemoryBlockName::renderTreeAllocated);
     renderTreeAllocated->setSize(static_cast<int>(arenaSize.allocated));
 
-    RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
-    RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> renderTreeUsed = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::renderTreeUsed);
+    RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
+    RefPtr<InspectorMemoryBlock> renderTreeUsed = InspectorMemoryBlock::create().setName(MemoryBlockName::renderTreeUsed);
     renderTreeUsed->setSize(static_cast<int>(arenaSize.treeSize));
     children->addItem(renderTreeUsed);
 
@@ -352,16 +363,45 @@ static PassRefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> renderTreeInfo(Page
     return renderTreeAllocated.release();
 }
 
-void InspectorMemoryAgent::getProcessMemoryDistribution(ErrorString*, RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock>& processMemory)
+static void addMemoryBlockFor(TypeBuilder::Array<InspectorMemoryBlock>* array, const MemoryCache::TypeStatistic& statistic, const char* name)
+{
+    RefPtr<InspectorMemoryBlock> result = InspectorMemoryBlock::create().setName(name);
+    result->setSize(statistic.size);
+    array->addItem(result);
+}
+
+static PassRefPtr<InspectorMemoryBlock> memoryCacheInfo()
+{
+    MemoryCache::Statistics stats = memoryCache()->getStatistics();
+    int totalSize = stats.images.size +
+                    stats.cssStyleSheets.size +
+                    stats.scripts.size +
+                    stats.xslStyleSheets.size +
+                    stats.fonts.size;
+    RefPtr<InspectorMemoryBlock> memoryCacheStats = InspectorMemoryBlock::create().setName(MemoryBlockName::memoryCache);
+    memoryCacheStats->setSize(totalSize);
+
+    RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
+    addMemoryBlockFor(children.get(), stats.images, MemoryBlockName::cachedImages);
+    addMemoryBlockFor(children.get(), stats.cssStyleSheets, MemoryBlockName::cachedCssStyleSheets);
+    addMemoryBlockFor(children.get(), stats.scripts, MemoryBlockName::cachedScripts);
+    addMemoryBlockFor(children.get(), stats.xslStyleSheets, MemoryBlockName::cachedXslStyleSheets);
+    addMemoryBlockFor(children.get(), stats.fonts, MemoryBlockName::cachedFonts);
+    memoryCacheStats->setChildren(children);
+    return memoryCacheStats.release();
+}
+
+void InspectorMemoryAgent::getProcessMemoryDistribution(ErrorString*, RefPtr<InspectorMemoryBlock>& processMemory)
 {
     size_t privateBytes = 0;
     size_t sharedBytes = 0;
     MemoryUsageSupport::processMemorySizesInBytes(&privateBytes, &sharedBytes);
-    processMemory = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::processPrivateMemory);
+    processMemory = InspectorMemoryBlock::create().setName(MemoryBlockName::processPrivateMemory);
     processMemory->setSize(static_cast<int>(privateBytes));
 
-    RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
+    RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
     children->addItem(jsHeapInfo());
+    children->addItem(memoryCacheInfo());
     children->addItem(renderTreeInfo(m_page)); // TODO: collect for all pages?
     processMemory->setChildren(children);
 }
index 6b85f4a..697225c 100644 (file)
@@ -201,6 +201,7 @@ WebInspector.MemoryBlockViewProperties._initialize = function()
     addBlock("rgba(240, 240, 250, 0.8)", "ProcessPrivateMemory", "Total");
     addBlock("rgba(250, 200, 200, 0.8)", "JSHeapAllocated", "JavaScript heap");
     addBlock("rgba(200, 250, 200, 0.8)", "JSHeapUsed", "Used JavaScript heap");
+    addBlock("rgba(200, 170, 200, 0.8)", "MemoryCache", "Memory cache resources");
     addBlock("rgba(250, 250, 150, 0.8)", "RenderTreeAllocated", "Render tree");
     addBlock("rgba(200, 150, 150, 0.8)", "RenderTreeUsed", "Render tree used");
 }