Index: third_party/WebKit/Source/web/WebCacheMemoryDumpProvider.cpp |
diff --git a/third_party/WebKit/Source/web/WebCacheMemoryDumpProvider.cpp b/third_party/WebKit/Source/web/WebCacheMemoryDumpProvider.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9dee7552b1b553f57802e29c03fb5a33ac00b8a7 |
--- /dev/null |
+++ b/third_party/WebKit/Source/web/WebCacheMemoryDumpProvider.cpp |
@@ -0,0 +1,97 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "web/WebCacheMemoryDumpProvider.h" |
+ |
+#include "public/platform/Platform.h" |
+#include "public/platform/WebMemoryAllocatorDump.h" |
+#include "public/platform/WebProcessMemoryDump.h" |
+#include "public/web/WebCache.h" |
+#include "wtf/MainThread.h" |
+#include <inttypes.h> |
+ |
+namespace blink { |
+ |
+namespace { |
+ |
+using namespace WTF; |
+ |
+WebCacheMemoryDumpProvider* gWebCacheMemoryDumpProvider; |
+ |
+// TODO(ssid): Expose the AddSuballocation method to WebMemoryDumpProvider. |
+void AddSuballocation(WebProcessMemoryDump* memoryDump, const WebMemoryAllocatorDumpGuid& sourceGuid, const char* target) |
+{ |
+ String dumpName = String::format("%s/__%" PRIX64, target, sourceGuid); |
+ WebMemoryAllocatorDump* targetChildDump = memoryDump->createMemoryAllocatorDump(dumpName); |
+ memoryDump->AddOwnershipEdge(sourceGuid, targetChildDump->guid()); |
+} |
+ |
+void DumpResourceStats(const WebCache::ResourceTypeStat& resourceStat, const String& resourceName, WebProcessMemoryDump* memoryDump) |
+{ |
+ WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDump(resourceName); |
+ allocatorDump->AddScalar("count", "objects", resourceStat.count); |
+ allocatorDump->AddScalar("live_size", "bytes", resourceStat.liveSize); |
+ allocatorDump->AddScalar("purged_size", "bytes", resourceStat.purgedSize); |
+ allocatorDump->AddScalar("purgeable_size", "bytes", resourceStat.purgeableSize); |
+ |
+ const String objectsName = resourceName + "/raw_objects"; |
+ WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump(objectsName); |
+ objectsDump->AddScalar("size", "bytes", resourceStat.size - resourceStat.decodedSize); |
+ |
+ AddSuballocation(memoryDump, objectsDump->guid(), Partitions::allocatorPoolNameForTracing()); |
+ |
+ // Decoded images are dumped by skia cache, which takes ownership of the resources. |
+ if (!resourceName.contains("images") && resourceStat.decodedSize > 0) { |
+ const String decodedName = resourceName + "/decoded"; |
+ WebMemoryAllocatorDump* decodedDump = memoryDump->createMemoryAllocatorDump(decodedName); |
+ decodedDump->AddScalar("size", "bytes", resourceStat.decodedSize); |
+ |
+ AddSuballocation(memoryDump, decodedDump->guid(), Partitions::allocatorPoolNameForTracing()); |
+ } |
+} |
+ |
+} // namespace |
+ |
+void WebCacheMemoryDumpProvider::initialize() |
+{ |
+ ASSERT(isMainThread()); |
+ if (!gWebCacheMemoryDumpProvider) |
+ gWebCacheMemoryDumpProvider = new WebCacheMemoryDumpProvider(); |
+} |
+ |
+bool WebCacheMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump) |
+{ |
+ WebCache::UsageStats memoryStats; |
+ WebCache::getUsageStats(&memoryStats); |
+ |
+ String dumpName("web_cache"); |
+ WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDump(dumpName); |
+ |
+ allocatorDump->AddScalar("live_size", "bytes", memoryStats.liveSize); |
+ allocatorDump->AddScalar("dead_size", "bytes", memoryStats.deadSize); |
+ |
+ WebCache::ResourceTypeStats resourceStats; |
+ WebCache::getResourceTypeStats(&resourceStats); |
+ DumpResourceStats(resourceStats.images, dumpName + "/images", memoryDump); |
+ DumpResourceStats(resourceStats.cssStyleSheets, dumpName + "/css_style_sheets", memoryDump); |
+ DumpResourceStats(resourceStats.scripts, dumpName + "/scripts", memoryDump); |
+ DumpResourceStats(resourceStats.xslStyleSheets, dumpName + "/xsl_style_sheets", memoryDump); |
+ DumpResourceStats(resourceStats.fonts, dumpName + "/fonts", memoryDump); |
+ DumpResourceStats(resourceStats.other, dumpName + "/other", memoryDump); |
+ |
+ return true; |
+} |
+ |
+WebCacheMemoryDumpProvider::WebCacheMemoryDumpProvider() |
+{ |
+ Platform::current()->registerMemoryDumpProvider(this); |
+} |
+ |
+WebCacheMemoryDumpProvider::~WebCacheMemoryDumpProvider() |
+{ |
+ Platform::current()->unregisterMemoryDumpProvider(this); |
+} |
+ |
+} // namespace blink |