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

Side by Side Diff: components/web_cache/renderer/web_cache_memory_dump_provider.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: Nits. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/web_cache/renderer/web_cache_memory_dump_provider.h"
6
7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/memory_allocator_dump.h"
10 #include "base/trace_event/memory_dump_manager.h"
11 #include "base/trace_event/process_memory_dump.h"
12 #include "third_party/WebKit/public/web/WebCache.h"
13
14 namespace web_cache {
15 namespace {
16
17 void DumpResourceStats(blink::WebCache::ResourceTypeStat resource_stat,
18 const std::string resource_name,
19 base::trace_event::ProcessMemoryDump* pmd) {
20 base::trace_event::MemoryAllocatorDump* allocator_dump =
21 pmd->CreateAllocatorDump(resource_name);
22 allocator_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
23 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
24 resource_stat.size);
25 allocator_dump->AddScalar(
26 base::trace_event::MemoryAllocatorDump::kNameObjectsCount,
27 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
28 resource_stat.count);
29 allocator_dump->AddScalar("live_size",
30 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
31 resource_stat.liveSize);
32 allocator_dump->AddScalar("decoded_size",
33 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
34 resource_stat.decodedSize);
35 }
36
37 } // namespace
38
39 // static
40 WebCacheMemoryDumpProvider* WebCacheMemoryDumpProvider::GetInstance() {
41 return Singleton<WebCacheMemoryDumpProvider,
42 LeakySingletonTraits<WebCacheMemoryDumpProvider>>::get();
43 }
44
45 WebCacheMemoryDumpProvider::WebCacheMemoryDumpProvider() {}
46
47 WebCacheMemoryDumpProvider::~WebCacheMemoryDumpProvider() {}
48
49 bool WebCacheMemoryDumpProvider::OnMemoryDump(
50 const base::trace_event::MemoryDumpArgs& args,
51 base::trace_event::ProcessMemoryDump* pmd) {
52 blink::WebCache::UsageStats memory_stats = {0};
53 blink::WebCache::getUsageStats(&memory_stats);
54
55 uint64 tracing_process_id =
56 base::trace_event::MemoryDumpManager::GetInstance()
57 ->GetTracingProcessId();
58 std::string dump_name =
59 base::StringPrintf("web_cache/renderer_%" PRIx64, tracing_process_id);
60 base::trace_event::MemoryAllocatorDump* allocator_dump =
61 pmd->CreateAllocatorDump(dump_name);
62
63 allocator_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
64 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
65 memory_stats.liveSize + memory_stats.deadSize);
66 allocator_dump->AddScalar("live_size",
67 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
68 memory_stats.liveSize);
69 allocator_dump->AddScalar("dead_size",
70 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
71 memory_stats.deadSize);
72
73 blink::WebCache::ResourceTypeStats resource_stats;
74 blink::WebCache::getResourceTypeStats(&resource_stats);
75 DumpResourceStats(resource_stats.images, dump_name + "/images", pmd);
76 DumpResourceStats(resource_stats.cssStyleSheets,
77 dump_name + "/css_style_sheets", pmd);
78 DumpResourceStats(resource_stats.scripts, dump_name + "/scripts", pmd);
79 DumpResourceStats(resource_stats.xslStyleSheets,
80 dump_name + "/xsl_style_sheets", pmd);
81 DumpResourceStats(resource_stats.fonts, dump_name + "/fonts", pmd);
82 DumpResourceStats(resource_stats.other, dump_name + "/other", pmd);
83
84 auto shared_guid = base::trace_event::MemoryAllocatorDumpGuid(
85 base::StringPrintf("web-cache-x-process/%" PRIx64, tracing_process_id));
86 pmd->CreateSharedGlobalAllocatorDump(shared_guid);
87
88 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps)
89 // the tracing UI will account the effective size of the allocation to the
90 // child.
91 const int kImportance = 2;
92 pmd->AddOwnershipEdge(allocator_dump->guid(), shared_guid, kImportance);
93 return true;
94 }
95
96 } // namespace web_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698