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 "skia/ext/SkTraceMemoryDump_chrome.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 "skia/ext/SkDiscardableMemory_chrome.h"
15 const char kMallocBackingType
[] = "malloc";
18 SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome(
19 base::trace_event::ProcessMemoryDump
* process_memory_dump
)
20 : SkTraceMemoryDump_Chrome("", process_memory_dump
) {}
22 SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome(
23 const char* dump_name_prefix
,
24 base::trace_event::ProcessMemoryDump
* process_memory_dump
)
25 : dump_name_prefix_(dump_name_prefix
),
26 process_memory_dump_(process_memory_dump
) {}
28 SkTraceMemoryDump_Chrome::~SkTraceMemoryDump_Chrome() {}
30 void SkTraceMemoryDump_Chrome::dumpNumericValue(const char* dumpName
,
31 const char* valueName
,
34 auto dump
= GetOrCreateAllocatorDump(dumpName
);
35 dump
->AddScalar(valueName
, units
, value
);
38 void SkTraceMemoryDump_Chrome::setMemoryBacking(const char* dumpName
,
39 const char* backingType
,
40 const char* backingObjectId
) {
41 if (strcmp(backingType
, kMallocBackingType
) == 0) {
42 auto dump
= GetOrCreateAllocatorDump(dumpName
);
43 const char* system_allocator_name
=
44 base::trace_event::MemoryDumpManager::GetInstance()
45 ->system_allocator_pool_name();
46 if (system_allocator_name
) {
47 process_memory_dump_
->AddSuballocation(dump
->guid(),
48 system_allocator_name
);
55 void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking(
57 const SkDiscardableMemory
& discardableMemoryObject
) {
58 std::string name
= dump_name_prefix_
+ dumpName
;
59 DCHECK(!process_memory_dump_
->GetAllocatorDump(name
));
60 const SkDiscardableMemoryChrome
& discardable_memory_obj
=
61 static_cast<const SkDiscardableMemoryChrome
&>(discardableMemoryObject
);
62 auto dump
= discardable_memory_obj
.CreateMemoryAllocatorDump(
63 name
.c_str(), process_memory_dump_
);
67 base::trace_event::MemoryAllocatorDump
*
68 SkTraceMemoryDump_Chrome::GetOrCreateAllocatorDump(const char* dumpName
) {
69 std::string name
= dump_name_prefix_
+ dumpName
;
70 auto dump
= process_memory_dump_
->GetAllocatorDump(name
);
72 dump
= process_memory_dump_
->CreateAllocatorDump(name
);