diff options
author | ssid <ssid@chromium.org> | 2015-08-14 00:53:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-14 07:54:30 +0000 |
commit | 65f8b7693255ae50ac6bdbbf9679bb88dc3733cb (patch) | |
tree | eb19fb50cdb2d69bd4fef48d4b2bf873c52abc74 | |
parent | b842929bb4aac6598c9dad40563f351544804457 (diff) | |
download | chromium_src-65f8b7693255ae50ac6bdbbf9679bb88dc3733cb.zip chromium_src-65f8b7693255ae50ac6bdbbf9679bb88dc3733cb.tar.gz chromium_src-65f8b7693255ae50ac6bdbbf9679bb88dc3733cb.tar.bz2 |
[tracing] Add WebCache memory usage in Blink to chrome://tracing
WebCache stores the web content downloaded from the internet in
memory. This CL adds memory statistics of WebCache to tracing.
BUG=466141
Review URL: https://codereview.chromium.org/1283793004
Cr-Commit-Position: refs/heads/master@{#343350}
5 files changed, 135 insertions, 0 deletions
diff --git a/components/web_cache.gypi b/components/web_cache.gypi index a42e344..56cc898 100644 --- a/components/web_cache.gypi +++ b/components/web_cache.gypi @@ -49,6 +49,8 @@ 'web_cache_common', ], 'sources': [ + 'web_cache/renderer/web_cache_memory_dump_provider.cc', + 'web_cache/renderer/web_cache_memory_dump_provider.h', 'web_cache/renderer/web_cache_render_process_observer.cc', 'web_cache/renderer/web_cache_render_process_observer.h', ], diff --git a/components/web_cache/renderer/BUILD.gn b/components/web_cache/renderer/BUILD.gn index e98abe9..94b4379 100644 --- a/components/web_cache/renderer/BUILD.gn +++ b/components/web_cache/renderer/BUILD.gn @@ -5,6 +5,8 @@ static_library("renderer") { output_name = "web_cache_renderer" sources = [ + "web_cache_memory_dump_provider.cc", + "web_cache_memory_dump_provider.h", "web_cache_render_process_observer.cc", "web_cache_render_process_observer.h", ] 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 0000000..f5f31b8 --- /dev/null +++ b/components/web_cache/renderer/web_cache_memory_dump_provider.cc @@ -0,0 +1,89 @@ +// 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/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 { + +base::LazyInstance<WebCacheMemoryDumpProvider>::Leaky g_wcmdp_instance = + LAZY_INSTANCE_INITIALIZER; + +void DumpResourceStats(const 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); + allocator_dump->AddScalar("purged_size", + base::trace_event::MemoryAllocatorDump::kUnitsBytes, + resource_stat.purgedSize); + allocator_dump->AddScalar("purgeable_size", + base::trace_event::MemoryAllocatorDump::kUnitsBytes, + resource_stat.purgeableSize); +} + +} // namespace + +// static +WebCacheMemoryDumpProvider* WebCacheMemoryDumpProvider::GetInstance() { + return g_wcmdp_instance.Pointer(); +} + +WebCacheMemoryDumpProvider::WebCacheMemoryDumpProvider() {} + +WebCacheMemoryDumpProvider::~WebCacheMemoryDumpProvider() {} + +bool WebCacheMemoryDumpProvider::OnMemoryDump( + const base::trace_event::MemoryDumpArgs& args, + base::trace_event::ProcessMemoryDump* pmd) { + blink::WebCache::UsageStats memory_stats; + blink::WebCache::getUsageStats(&memory_stats); + + const std::string dump_name("web_cache"); + 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); + + return true; +} + +} // namespace web_cache diff --git a/components/web_cache/renderer/web_cache_memory_dump_provider.h b/components/web_cache/renderer/web_cache_memory_dump_provider.h new file mode 100644 index 0000000..75c65ea --- /dev/null +++ b/components/web_cache/renderer/web_cache_memory_dump_provider.h @@ -0,0 +1,33 @@ +// 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. + +#ifndef COMPONENTS_WEB_CACHE_RENDERER_WEB_CACHE_MEMORY_DUMP_PROVIDER_H +#define COMPONENTS_WEB_CACHE_RENDERER_WEB_CACHE_MEMORY_DUMP_PROVIDER_H + +#include "base/lazy_instance.h" +#include "base/trace_event/memory_dump_provider.h" + +namespace web_cache { + +class WebCacheMemoryDumpProvider + : public base::trace_event::MemoryDumpProvider { + public: + static WebCacheMemoryDumpProvider* GetInstance(); + + // base::trace_event::MemoryDumpProvider implementation. + bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, + base::trace_event::ProcessMemoryDump* pmd) override; + + private: + friend struct base::DefaultLazyInstanceTraits<WebCacheMemoryDumpProvider>; + + WebCacheMemoryDumpProvider(); + ~WebCacheMemoryDumpProvider() override; + + DISALLOW_COPY_AND_ASSIGN(WebCacheMemoryDumpProvider); +}; + +} // namespace web_cache + +#endif // COMPONENTS_WEB_CACHE_RENDERER_WEB_CACHE_MEMORY_DUMP_PROVIDER_H diff --git a/components/web_cache/renderer/web_cache_render_process_observer.cc b/components/web_cache/renderer/web_cache_render_process_observer.cc index a273817..c57325b 100644 --- a/components/web_cache/renderer/web_cache_render_process_observer.cc +++ b/components/web_cache/renderer/web_cache_render_process_observer.cc @@ -6,7 +6,10 @@ #include <limits> +#include "base/thread_task_runner_handle.h" +#include "base/trace_event/memory_dump_manager.h" #include "components/web_cache/common/web_cache_messages.h" +#include "components/web_cache/renderer/web_cache_memory_dump_provider.h" #include "third_party/WebKit/public/web/WebCache.h" using blink::WebCache; @@ -53,9 +56,15 @@ void WebCacheRenderProcessObserver::WebKitInitialized() { pending_cache_max_dead_capacity_, pending_cache_capacity_); } + + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( + web_cache::WebCacheMemoryDumpProvider::GetInstance(), + base::ThreadTaskRunnerHandle::Get()); } void WebCacheRenderProcessObserver::OnRenderProcessShutdown() { + base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( + web_cache::WebCacheMemoryDumpProvider::GetInstance()); webkit_initialized_ = false; } |