| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "skia_memory_dump_provider.h" | 5 #include "skia_memory_dump_provider.h" |
| 6 | 6 |
| 7 #include "base/memory/discardable_memory_allocator.h" |
| 8 #include "base/trace_event/malloc_dump_provider.h" |
| 7 #include "base/trace_event/memory_allocator_dump.h" | 9 #include "base/trace_event/memory_allocator_dump.h" |
| 8 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
| 9 #include "base/trace_event/process_memory_dump.h" | 11 #include "base/trace_event/process_memory_dump.h" |
| 10 #include "third_party/skia/include/core/SkGraphics.h" | 12 #include "third_party/skia/include/core/SkGraphics.h" |
| 11 #include "third_party/skia/src/core/SkResourceCache.h" | 13 #include "third_party/skia/src/core/SkResourceCache.h" |
| 12 | 14 |
| 13 namespace skia { | 15 namespace skia { |
| 14 | 16 |
| 15 // static | 17 // static |
| 16 SkiaMemoryDumpProvider* SkiaMemoryDumpProvider::GetInstance() { | 18 SkiaMemoryDumpProvider* SkiaMemoryDumpProvider::GetInstance() { |
| 17 return Singleton<SkiaMemoryDumpProvider, | 19 return Singleton<SkiaMemoryDumpProvider, |
| 18 LeakySingletonTraits<SkiaMemoryDumpProvider>>::get(); | 20 LeakySingletonTraits<SkiaMemoryDumpProvider>>::get(); |
| 19 } | 21 } |
| 20 | 22 |
| 21 SkiaMemoryDumpProvider::SkiaMemoryDumpProvider() {} | 23 SkiaMemoryDumpProvider::SkiaMemoryDumpProvider() {} |
| 22 | 24 |
| 23 SkiaMemoryDumpProvider::~SkiaMemoryDumpProvider() {} | 25 SkiaMemoryDumpProvider::~SkiaMemoryDumpProvider() {} |
| 24 | 26 |
| 25 bool SkiaMemoryDumpProvider::OnMemoryDump( | 27 bool SkiaMemoryDumpProvider::OnMemoryDump( |
| 26 base::trace_event::ProcessMemoryDump* process_memory_dump) { | 28 base::trace_event::ProcessMemoryDump* process_memory_dump) { |
| 27 auto font_mad = | 29 auto font_mad = |
| 28 process_memory_dump->CreateAllocatorDump("skia/sk_font_cache"); | 30 process_memory_dump->CreateAllocatorDump("skia/sk_font_cache"); |
| 29 font_mad->AddScalar("size", "bytes", SkGraphics::GetFontCacheUsed()); | 31 font_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 30 font_mad->AddScalar("count", "objects", SkGraphics::GetFontCacheCountUsed()); | 32 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 33 SkGraphics::GetFontCacheUsed()); |
| 34 font_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectsCount, |
| 35 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 36 SkGraphics::GetFontCacheCountUsed()); |
| 31 | 37 |
| 32 auto resource_mad = | 38 auto resource_mad = |
| 33 process_memory_dump->CreateAllocatorDump("skia/sk_resource_cache"); | 39 process_memory_dump->CreateAllocatorDump("skia/sk_resource_cache"); |
| 34 resource_mad->AddScalar("size", "bytes", | 40 resource_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 41 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 35 SkResourceCache::GetTotalBytesUsed()); | 42 SkResourceCache::GetTotalBytesUsed()); |
| 36 // TODO(ssid): crbug.com/503168. Add sub-allocation edges from discardable or | 43 const char* source_name = |
| 37 // malloc memory dumps to avoid double counting. | 44 SkResourceCache::GetDiscardableFactory() |
| 45 ? base::DiscardableMemoryAllocator::GetMemoryPoolNameForTracing() |
| 46 : base::trace_event::MemoryDumpManager::GetInstance() |
| 47 ->system_allocator_pool_name(); |
| 48 process_memory_dump->AddSuballocation(resource_mad->guid(), source_name); |
| 38 | 49 |
| 39 return true; | 50 return true; |
| 40 } | 51 } |
| 41 | 52 |
| 42 } // namespace skia | 53 } // namespace skia |
| OLD | NEW |