| Index: components/web_cache/renderer/web_cache_memory_dump_provider.cc
|
| diff --git a/components/web_cache/renderer/web_cache_memory_dump_provider.cc b/components/web_cache/renderer/web_cache_memory_dump_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..228a8cfbf83ced808c4f82f3027b73a746fa9131
|
| --- /dev/null
|
| +++ b/components/web_cache/renderer/web_cache_memory_dump_provider.cc
|
| @@ -0,0 +1,96 @@
|
| +// 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 "components/web_cache/renderer/web_cache_memory_dump_provider.h"
|
| +
|
| +#include "base/format_macros.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/trace_event/memory_allocator_dump.h"
|
| +#include "base/trace_event/memory_dump_manager.h"
|
| +#include "base/trace_event/process_memory_dump.h"
|
| +#include "third_party/WebKit/public/web/WebCache.h"
|
| +
|
| +namespace web_cache {
|
| +namespace {
|
| +
|
| +void DumpResourceStats(blink::WebCache::ResourceTypeStat resource_stat,
|
| + const std::string resource_name,
|
| + base::trace_event::ProcessMemoryDump* pmd) {
|
| + base::trace_event::MemoryAllocatorDump* allocator_dump =
|
| + pmd->CreateAllocatorDump(resource_name);
|
| + allocator_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
|
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes,
|
| + resource_stat.size);
|
| + allocator_dump->AddScalar(
|
| + base::trace_event::MemoryAllocatorDump::kNameObjectsCount,
|
| + base::trace_event::MemoryAllocatorDump::kUnitsObjects,
|
| + resource_stat.count);
|
| + allocator_dump->AddScalar("live_size",
|
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes,
|
| + resource_stat.liveSize);
|
| + allocator_dump->AddScalar("decoded_size",
|
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes,
|
| + resource_stat.decodedSize);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +WebCacheMemoryDumpProvider* WebCacheMemoryDumpProvider::GetInstance() {
|
| + return Singleton<WebCacheMemoryDumpProvider,
|
| + LeakySingletonTraits<WebCacheMemoryDumpProvider>>::get();
|
| +}
|
| +
|
| +WebCacheMemoryDumpProvider::WebCacheMemoryDumpProvider() {}
|
| +
|
| +WebCacheMemoryDumpProvider::~WebCacheMemoryDumpProvider() {}
|
| +
|
| +bool WebCacheMemoryDumpProvider::OnMemoryDump(
|
| + const base::trace_event::MemoryDumpArgs& args,
|
| + base::trace_event::ProcessMemoryDump* pmd) {
|
| + blink::WebCache::UsageStats memory_stats = {0};
|
| + blink::WebCache::getUsageStats(&memory_stats);
|
| +
|
| + uint64 tracing_process_id =
|
| + base::trace_event::MemoryDumpManager::GetInstance()
|
| + ->GetTracingProcessId();
|
| + std::string dump_name =
|
| + base::StringPrintf("web_cache/renderer_%" PRIx64, tracing_process_id);
|
| + base::trace_event::MemoryAllocatorDump* allocator_dump =
|
| + pmd->CreateAllocatorDump(dump_name);
|
| + allocator_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
|
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes,
|
| + memory_stats.liveSize + memory_stats.deadSize);
|
| +
|
| + allocator_dump->AddScalar("live_size",
|
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes,
|
| + memory_stats.liveSize);
|
| + allocator_dump->AddScalar("dead_size",
|
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes,
|
| + memory_stats.deadSize);
|
| +
|
| + blink::WebCache::ResourceTypeStats resource_stats;
|
| + blink::WebCache::getResourceTypeStats(&resource_stats);
|
| + DumpResourceStats(resource_stats.images, dump_name + "/images", pmd);
|
| + DumpResourceStats(resource_stats.cssStyleSheets,
|
| + dump_name + "/css_style_sheets", pmd);
|
| + DumpResourceStats(resource_stats.scripts, dump_name + "/scripts", pmd);
|
| + DumpResourceStats(resource_stats.xslStyleSheets,
|
| + dump_name + "/xsl_style_sheets", pmd);
|
| + DumpResourceStats(resource_stats.fonts, dump_name + "/fonts", pmd);
|
| + DumpResourceStats(resource_stats.other, dump_name + "/other", pmd);
|
| +
|
| + auto shared_guid = base::trace_event::MemoryAllocatorDumpGuid(
|
| + base::StringPrintf("web-cache-x-process/%" PRIx64, tracing_process_id));
|
| + pmd->CreateSharedGlobalAllocatorDump(shared_guid);
|
| +
|
| + // By creating an edge with a higher |importance| (w.r.t. browser-side dumps)
|
| + // the tracing UI will account the effective size of the allocation to the
|
| + // child.
|
| + const int kImportance = 2;
|
| + pmd->AddOwnershipEdge(allocator_dump->guid(), shared_guid, kImportance);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace web_cache
|
|
|