Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Unified Diff: components/web_cache/browser/web_cache_manager.cc

Issue 1283793004: [tracing] Add WebCache memory usage in Blink to chrome://tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unregister. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/web_cache/browser/web_cache_manager.cc
diff --git a/components/web_cache/browser/web_cache_manager.cc b/components/web_cache/browser/web_cache_manager.cc
index dfed012ebfb81e38fb1f7ea75ede142e6263b1c5..1b05a76c03d84209f789adffab654eabefce56c7 100644
--- a/components/web_cache/browser/web_cache_manager.cc
+++ b/components/web_cache/browser/web_cache_manager.cc
@@ -8,16 +8,22 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
+#include "base/format_macros.h"
#include "base/location.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram_macros.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/single_thread_task_runner.h"
+#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/thread_task_runner_handle.h"
#include "base/time/time.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 "components/web_cache/common/web_cache_messages.h"
+#include "content/common/child_process_host_impl.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
@@ -66,9 +72,13 @@ WebCacheManager::WebCacheManager()
content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllBrowserContextsAndSources());
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
+ this);
}
WebCacheManager::~WebCacheManager() {
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
+ this);
}
void WebCacheManager::Add(int renderer_id) {
@@ -177,6 +187,56 @@ void WebCacheManager::Observe(int type,
}
}
+bool WebCacheManager::OnMemoryDump(
+ const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ std::set<int>::const_iterator active_renderers_iter =
+ active_renderers_.begin();
+ while (active_renderers_iter != active_renderers_.end()) {
+ DumpUsageStats(*active_renderers_iter, pmd);
+ ++active_renderers_iter;
+ }
+
+ std::set<int>::const_iterator inactive_renderers_iter =
+ inactive_renderers_.begin();
+ while (inactive_renderers_iter != inactive_renderers_.end()) {
+ DumpUsageStats(*inactive_renderers_iter, pmd);
+ ++inactive_renderers_iter;
+ }
+
+ return true;
+}
+
+void WebCacheManager::DumpUsageStats(
+ int renderer_id,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ StatsMap::iterator stats = stats_.find(renderer_id);
+ if (stats == stats_.end())
+ return;
+ uint64 child_tracing_id =
+ content::ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(
ssid 2015/08/11 17:40:01 This causes a DEPS addition to component which is
+ renderer_id);
+ std::string dump_name = base::StringPrintf(
+ "web_cache/renderer_%lu", static_cast<unsigned long>(child_tracing_id));
+ base::trace_event::MemoryAllocatorDump* allocator_dump =
+ pmd->CreateAllocatorDump(dump_name);
+ allocator_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ stats->second.liveSize + stats->second.deadSize);
+
+ allocator_dump->AddScalar("live_size",
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ stats->second.liveSize);
+ allocator_dump->AddScalar("dead_size",
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ stats->second.deadSize);
+
+ auto shared_guid = base::trace_event::MemoryAllocatorDumpGuid(
+ base::StringPrintf("web-cache-x-process/%" PRIx64, child_tracing_id));
+ pmd->CreateSharedGlobalAllocatorDump(shared_guid);
+ pmd->AddOwnershipEdge(allocator_dump->guid(), shared_guid);
+}
+
// static
size_t WebCacheManager::GetDefaultGlobalSizeLimit() {
return GetDefaultCacheSize();

Powered by Google App Engine
This is Rietveld 408576698