Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / skia / ext / SkTraceMemoryDump_chrome.cc
bloba5309047630f61f095fa7977f713d904cac2927b
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"
12 namespace skia {
14 namespace {
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,
32 const char* units,
33 uint64_t value) {
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);
50 } else {
51 NOTREACHED();
55 void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking(
56 const char* dumpName,
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_);
64 DCHECK(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);
71 if (!dump)
72 dump = process_memory_dump_->CreateAllocatorDump(name);
73 return dump;
76 } // namespace skia