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.
5 #include "components/web_cache/renderer/web_cache_memory_dump_provider.h"
7 #include "base/trace_event/memory_allocator_dump.h"
8 #include "base/trace_event/memory_dump_manager.h"
9 #include "base/trace_event/process_memory_dump.h"
10 #include "third_party/WebKit/public/web/WebCache.h"
15 base::LazyInstance
<WebCacheMemoryDumpProvider
>::Leaky g_wcmdp_instance
=
16 LAZY_INSTANCE_INITIALIZER
;
18 void DumpResourceStats(const blink::WebCache::ResourceTypeStat
& resource_stat
,
19 const std::string
& resource_name
,
20 base::trace_event::ProcessMemoryDump
* pmd
) {
21 base::trace_event::MemoryAllocatorDump
* allocator_dump
=
22 pmd
->CreateAllocatorDump(resource_name
);
23 allocator_dump
->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize
,
24 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
26 allocator_dump
->AddScalar(
27 base::trace_event::MemoryAllocatorDump::kNameObjectsCount
,
28 base::trace_event::MemoryAllocatorDump::kUnitsObjects
,
30 allocator_dump
->AddScalar("live_size",
31 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
32 resource_stat
.liveSize
);
33 allocator_dump
->AddScalar("decoded_size",
34 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
35 resource_stat
.decodedSize
);
36 allocator_dump
->AddScalar("purged_size",
37 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
38 resource_stat
.purgedSize
);
39 allocator_dump
->AddScalar("purgeable_size",
40 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
41 resource_stat
.purgeableSize
);
47 WebCacheMemoryDumpProvider
* WebCacheMemoryDumpProvider::GetInstance() {
48 return g_wcmdp_instance
.Pointer();
51 WebCacheMemoryDumpProvider::WebCacheMemoryDumpProvider() {}
53 WebCacheMemoryDumpProvider::~WebCacheMemoryDumpProvider() {}
55 bool WebCacheMemoryDumpProvider::OnMemoryDump(
56 const base::trace_event::MemoryDumpArgs
& args
,
57 base::trace_event::ProcessMemoryDump
* pmd
) {
58 blink::WebCache::UsageStats memory_stats
;
59 blink::WebCache::getUsageStats(&memory_stats
);
61 const std::string
dump_name("web_cache");
62 base::trace_event::MemoryAllocatorDump
* allocator_dump
=
63 pmd
->CreateAllocatorDump(dump_name
);
65 allocator_dump
->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize
,
66 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
67 memory_stats
.liveSize
+ memory_stats
.deadSize
);
68 allocator_dump
->AddScalar("live_size",
69 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
70 memory_stats
.liveSize
);
71 allocator_dump
->AddScalar("dead_size",
72 base::trace_event::MemoryAllocatorDump::kUnitsBytes
,
73 memory_stats
.deadSize
);
75 blink::WebCache::ResourceTypeStats resource_stats
;
76 blink::WebCache::getResourceTypeStats(&resource_stats
);
77 DumpResourceStats(resource_stats
.images
, dump_name
+ "/images", pmd
);
78 DumpResourceStats(resource_stats
.cssStyleSheets
,
79 dump_name
+ "/css_style_sheets", pmd
);
80 DumpResourceStats(resource_stats
.scripts
, dump_name
+ "/scripts", pmd
);
81 DumpResourceStats(resource_stats
.xslStyleSheets
,
82 dump_name
+ "/xsl_style_sheets", pmd
);
83 DumpResourceStats(resource_stats
.fonts
, dump_name
+ "/fonts", pmd
);
84 DumpResourceStats(resource_stats
.other
, dump_name
+ "/other", pmd
);
89 } // namespace web_cache