Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "skia/ext/SkTraceMemoryDump_chrome.h" | |
| 6 | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "base/trace_event/memory_allocator_dump.h" | |
| 9 #include "base/trace_event/memory_dump_manager.h" | |
| 10 #include "base/trace_event/process_memory_dump.h" | |
| 11 #include "skia/ext/SkDiscardableMemory_chrome.h" | |
| 12 | |
| 13 namespace skia { | |
| 14 | |
| 15 namespace { | |
| 16 const char kMallocBackingType[] = "malloc"; | |
| 17 } | |
| 18 | |
| 19 SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome( | |
| 20 base::trace_event::ProcessMemoryDump* process_memory_dump) | |
| 21 : process_memory_dump_(process_memory_dump) {} | |
| 22 | |
| 23 SkTraceMemoryDump_Chrome::~SkTraceMemoryDump_Chrome() {} | |
| 24 | |
| 25 void SkTraceMemoryDump_Chrome::dumpNumericValue(const char* dumpName, | |
| 26 const char* valueName, | |
| 27 const char* units, | |
| 28 uint64_t value) { | |
| 29 auto dump = GetOrCreateAllocatorDump(dumpName); | |
| 30 dump->AddScalar(valueName, units, value); | |
| 31 } | |
| 32 | |
| 33 void SkTraceMemoryDump_Chrome::setMemoryBacking(const char* dumpName, | |
| 34 const char* backingType, | |
| 35 const char* backingObjectId) { | |
| 36 if (base::CompareCaseInsensitiveASCII(backingType, kMallocBackingType) == 0) { | |
| 37 auto dump = GetOrCreateAllocatorDump(dumpName); | |
|
Primiano Tucci (use gerrit)
2015/08/30 18:28:36
why do we allow case insensitive compare here? I'd
ssid
2015/08/30 23:11:23
I mainly made it because skia could say malloc or
| |
| 38 process_memory_dump_->AddSuballocation( | |
| 39 dump->guid(), base::trace_event::MemoryDumpManager::GetInstance() | |
| 40 ->system_allocator_pool_name()); | |
| 41 } | |
| 42 } | |
|
Primiano Tucci (use gerrit)
2015/08/30 18:28:36
also, please add a else{ NOTREACHED()} section at
ssid
2015/09/02 12:59:52
Done.
| |
| 43 | |
| 44 void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking( | |
| 45 const char* dumpName, | |
| 46 const SkDiscardableMemory& discardableMemoryObject) { | |
| 47 DCHECK(!process_memory_dump_->GetAllocatorDump(dumpName)); | |
| 48 const SkDiscardableMemoryChrome& discardable_memory_obj = | |
| 49 static_cast<const SkDiscardableMemoryChrome&>(discardableMemoryObject); | |
| 50 auto dump = discardable_memory_obj.CreateMemoryAllocatorDump( | |
|
Primiano Tucci (use gerrit)
2015/08/30 18:28:36
why are you not using the GetOrCreateAllocatorDump
ssid
2015/08/30 23:11:23
Yes it will fail if skia first calls dump and then
| |
| 51 dumpName, process_memory_dump_); | |
| 52 DCHECK(dump); | |
| 53 } | |
| 54 | |
| 55 base::trace_event::MemoryAllocatorDump* | |
| 56 SkTraceMemoryDump_Chrome::GetOrCreateAllocatorDump(const char* dumpName) { | |
| 57 auto dump = process_memory_dump_->GetAllocatorDump(dumpName); | |
| 58 if (!dump) | |
| 59 dump = process_memory_dump_->CreateAllocatorDump(dumpName); | |
| 60 return dump; | |
| 61 } | |
| 62 | |
| 63 } // namespace skia | |
| OLD | NEW |