Gather memory cache statistics in WebProcess::getWebCoreStatistics().
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2011 20:39:46 +0000 (20:39 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2011 20:39:46 +0000 (20:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67160

Reviewed by Darin Adler.

Encode and decode webCoreCacheStatistics data member in StatisticsData.
* Shared/StatisticsData.cpp:
(WebKit::StatisticsData::encode):
(WebKit::StatisticsData::decode):
* Shared/StatisticsData.h:

Convert the cache statistics data into an ImmutableArray and return it in WebContext::didGetWebCoreStatistics().
* UIProcess/WebContext.cpp:
(WebKit::WebContext::didGetWebCoreStatistics):

Store memory cache statistics into the StatisticsData object.
* WebProcess/WebProcess.cpp:
(WebKit::getWebCoreMemoryCacheStatistics):
(WebKit::WebProcess::getWebCoreStatistics):

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/StatisticsData.cpp
Source/WebKit2/Shared/StatisticsData.h
Source/WebKit2/UIProcess/WebContext.cpp
Source/WebKit2/WebProcess/WebProcess.cpp

index 9c2043e..06d96be 100644 (file)
@@ -1,3 +1,25 @@
+2011-09-01  Ada Chan  <adachan@apple.com>
+
+        Gather memory cache statistics in WebProcess::getWebCoreStatistics().
+        https://bugs.webkit.org/show_bug.cgi?id=67160
+
+        Reviewed by Darin Adler.
+
+        Encode and decode webCoreCacheStatistics data member in StatisticsData.
+        * Shared/StatisticsData.cpp:
+        (WebKit::StatisticsData::encode):
+        (WebKit::StatisticsData::decode):
+        * Shared/StatisticsData.h:
+
+        Convert the cache statistics data into an ImmutableArray and return it in WebContext::didGetWebCoreStatistics().
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::didGetWebCoreStatistics):
+
+        Store memory cache statistics into the StatisticsData object.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::getWebCoreMemoryCacheStatistics):
+        (WebKit::WebProcess::getWebCoreStatistics):
+
 2011-09-01  Tim Horton  <timothy_horton@apple.com>
 
         REGRESSION: Rendering artifacts on a rotated, pattern filled shape
index a1a5a38..59fef7a 100644 (file)
@@ -35,6 +35,7 @@ void StatisticsData::encode(CoreIPC::ArgumentEncoder* encoder) const
     encoder->encode(statisticsNumbers);
     encoder->encode(javaScriptProtectedObjectTypeCounts);
     encoder->encode(javaScriptObjectTypeCounts);
+    encoder->encode(webCoreCacheStatistics);
 }
 
 bool StatisticsData::decode(CoreIPC::ArgumentDecoder* decoder, StatisticsData& statisticsData)
@@ -45,6 +46,8 @@ bool StatisticsData::decode(CoreIPC::ArgumentDecoder* decoder, StatisticsData& s
         return false;
     if (!decoder->decode(statisticsData.javaScriptObjectTypeCounts))
         return false;
+    if (!decoder->decode(statisticsData.webCoreCacheStatistics))
+        return false;
 
     return true;
 }
index 61ffcd3..2c82c28 100644 (file)
@@ -29,6 +29,7 @@
 #include "ArgumentDecoder.h"
 #include "ArgumentEncoder.h"
 #include <wtf/HashMap.h>
+#include <wtf/Vector.h>
 #include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
 
@@ -41,6 +42,7 @@ struct StatisticsData {
     HashMap<String, uint64_t> statisticsNumbers;
     HashMap<String, uint64_t> javaScriptProtectedObjectTypeCounts;
     HashMap<String, uint64_t> javaScriptObjectTypeCounts;    
+    Vector<HashMap<String, uint64_t> > webCoreCacheStatistics;
     
     StatisticsData();
 };
index fab1fd2..01dd4c1 100644 (file)
@@ -820,6 +820,12 @@ void WebContext::didGetWebCoreStatistics(const StatisticsData& statisticsData, u
     statistics->set("JavaScriptProtectedObjectTypeCounts", createDictionaryFromHashMap(statisticsData.javaScriptProtectedObjectTypeCounts).get());
     statistics->set("JavaScriptObjectTypeCounts", createDictionaryFromHashMap(statisticsData.javaScriptObjectTypeCounts).get());
     
+    size_t cacheStatisticsCount = statisticsData.webCoreCacheStatistics.size();
+    Vector<RefPtr<APIObject> > cacheStatisticsVector(cacheStatisticsCount);
+    for (size_t i = 0; i < cacheStatisticsCount; ++i)
+        cacheStatisticsVector[i] = createDictionaryFromHashMap(statisticsData.webCoreCacheStatistics[i]);
+    statistics->set("WebCoreCacheStatistics", ImmutableArray::adopt(cacheStatisticsVector).get());
+    
     callback->performCallbackWithReturnValue(statistics.get());
 }
     
index 9c231a9..431ea9e 100644 (file)
@@ -833,6 +833,82 @@ static void fromCountedSetToHashMap(TypeCountSet* countedSet, HashMap<String, ui
         map.set(it->first, it->second);
 }
 
+static void getWebCoreMemoryCacheStatistics(Vector<HashMap<String, uint64_t> >& result)
+{
+    DEFINE_STATIC_LOCAL(String, imagesString, ("Images"));
+    DEFINE_STATIC_LOCAL(String, cssString, ("CSS"));
+    DEFINE_STATIC_LOCAL(String, xslString, ("XSL"));
+    DEFINE_STATIC_LOCAL(String, javaScriptString, ("JavaScript"));
+    
+    MemoryCache::Statistics memoryCacheStatistics = memoryCache()->getStatistics();
+    
+    HashMap<String, uint64_t> counts;
+    counts.set(imagesString, memoryCacheStatistics.images.count);
+    counts.set(cssString, memoryCacheStatistics.cssStyleSheets.count);
+#if ENABLE(XSLT)
+    counts.set(xslString, memoryCacheStatistics.xslStyleSheets.count);
+#else
+    counts.set(xslString, 0);
+#endif
+    counts.set(javaScriptString, memoryCacheStatistics.scripts.count);
+    result.append(counts);
+    
+    HashMap<String, uint64_t> sizes;
+    sizes.set(imagesString, memoryCacheStatistics.images.size);
+    sizes.set(cssString, memoryCacheStatistics.cssStyleSheets.size);
+#if ENABLE(XSLT)
+    sizes.set(xslString, memoryCacheStatistics.xslStyleSheets.size);
+#else
+    sizes.set(xslString, 0);
+#endif
+    sizes.set(javaScriptString, memoryCacheStatistics.scripts.size);
+    result.append(sizes);
+    
+    HashMap<String, uint64_t> liveSizes;
+    liveSizes.set(imagesString, memoryCacheStatistics.images.liveSize);
+    liveSizes.set(cssString, memoryCacheStatistics.cssStyleSheets.liveSize);
+#if ENABLE(XSLT)
+    liveSizes.set(xslString, memoryCacheStatistics.xslStyleSheets.liveSize);
+#else
+    liveSizes.set(xslString, 0);
+#endif
+    liveSizes.set(javaScriptString, memoryCacheStatistics.scripts.liveSize);
+    result.append(liveSizes);
+    
+    HashMap<String, uint64_t> decodedSizes;
+    decodedSizes.set(imagesString, memoryCacheStatistics.images.decodedSize);
+    decodedSizes.set(cssString, memoryCacheStatistics.cssStyleSheets.decodedSize);
+#if ENABLE(XSLT)
+    decodedSizes.set(xslString, memoryCacheStatistics.xslStyleSheets.decodedSize);
+#else
+    decodedSizes.set(xslString, 0);
+#endif
+    decodedSizes.set(javaScriptString, memoryCacheStatistics.scripts.decodedSize);
+    result.append(decodedSizes);
+    
+    HashMap<String, uint64_t> purgeableSizes;
+    purgeableSizes.set(imagesString, memoryCacheStatistics.images.purgeableSize);
+    purgeableSizes.set(cssString, memoryCacheStatistics.cssStyleSheets.purgeableSize);
+#if ENABLE(XSLT)
+    purgeableSizes.set(xslString, memoryCacheStatistics.xslStyleSheets.purgeableSize);
+#else
+    purgeableSizes.set(xslString, 0);
+#endif
+    purgeableSizes.set(javaScriptString, memoryCacheStatistics.scripts.purgeableSize);
+    result.append(purgeableSizes);
+    
+    HashMap<String, uint64_t> purgedSizes;
+    purgedSizes.set(imagesString, memoryCacheStatistics.images.purgedSize);
+    purgedSizes.set(cssString, memoryCacheStatistics.cssStyleSheets.purgedSize);
+#if ENABLE(XSLT)
+    purgedSizes.set(xslString, memoryCacheStatistics.xslStyleSheets.purgedSize);
+#else
+    purgedSizes.set(xslString, 0);
+#endif
+    purgedSizes.set(javaScriptString, memoryCacheStatistics.scripts.purgedSize);
+    result.append(purgedSizes);
+}
+
 void WebProcess::getWebCoreStatistics(uint64_t callbackID)
 {
     StatisticsData data;
@@ -874,7 +950,8 @@ void WebProcess::getWebCoreStatistics(uint64_t callbackID)
     // Gather glyph page statistics.
     data.statisticsNumbers.set("GlyphPageCount", GlyphPageTreeNode::treeGlyphPageCount());
     
-    // FIXME: Gather WebCore cache statistics.
+    // Get WebCore memory cache statistics
+    getWebCoreMemoryCacheStatistics(data.webCoreCacheStatistics);
     
     m_connection->send(Messages::WebContext::DidGetWebCoreStatistics(data, callbackID), 0);
 }