Chromium Code Reviews| 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 "base/memory/discardable_memory_allocator.h" | 5 #include "base/memory/discardable_memory_allocator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/trace_event/memory_allocator_dump.h" | |
| 9 #include "base/trace_event/process_memory_dump.h" | |
| 8 | 10 |
| 9 namespace base { | 11 namespace base { |
| 10 namespace { | 12 namespace { |
| 11 | 13 |
| 12 DiscardableMemoryAllocator* g_allocator = nullptr; | 14 DiscardableMemoryAllocator* g_allocator = nullptr; |
| 13 | 15 |
| 14 } // namespace | 16 } // namespace |
| 15 | 17 |
| 16 // static | 18 // static |
| 17 void DiscardableMemoryAllocator::SetInstance( | 19 void DiscardableMemoryAllocator::SetInstance( |
| 18 DiscardableMemoryAllocator* allocator) { | 20 DiscardableMemoryAllocator* allocator) { |
| 19 DCHECK(allocator); | 21 DCHECK(allocator); |
| 20 | 22 |
| 21 // Make sure this function is only called once before the first call | 23 // Make sure this function is only called once before the first call |
| 22 // to GetInstance(). | 24 // to GetInstance(). |
| 23 DCHECK(!g_allocator); | 25 DCHECK(!g_allocator); |
| 24 | 26 |
| 25 g_allocator = allocator; | 27 g_allocator = allocator; |
| 26 } | 28 } |
| 27 | 29 |
| 28 // static | 30 // static |
| 29 DiscardableMemoryAllocator* DiscardableMemoryAllocator::GetInstance() { | 31 DiscardableMemoryAllocator* DiscardableMemoryAllocator::GetInstance() { |
| 30 DCHECK(g_allocator); | 32 DCHECK(g_allocator); |
| 31 return g_allocator; | 33 return g_allocator; |
| 32 } | 34 } |
| 33 | 35 |
| 36 // static | |
| 37 const char* DiscardableMemoryAllocator::GetMemoryPoolNameForTracing() { | |
| 38 return "discardable/allocated_objects"; | |
| 39 } | |
| 40 | |
| 41 // static | |
| 42 void DiscardableMemoryAllocator::CreateMemoryPoolDumpForTracing( | |
| 43 trace_event::ProcessMemoryDump* pmd) { | |
| 44 base::trace_event::MemoryAllocatorDump* objects_dump = | |
| 45 pmd->CreateAllocatorDump(GetMemoryPoolNameForTracing()); | |
| 46 base::trace_event::MemoryAllocatorDump* discardable_segments_dump = | |
| 47 pmd->CreateAllocatorDump("discardable/segments"); | |
|
reveman
2015/07/30 21:27:56
The use of segments is a detail of the allocator i
ssid
2015/07/31 12:59:40
Done.
| |
| 48 | |
| 49 // The discardable memory segments will be dumped with | |
| 50 // "discardable/segments" as the parent and will be owned by | |
| 51 // sub-allocations dumped with kAllocatedObjectsDumpName as their parent. | |
| 52 pmd->AddOwnershipEdge(objects_dump->guid(), | |
| 53 discardable_segments_dump->guid()); | |
|
reveman
2015/07/30 21:27:56
same here. we shouldn't be referring to segments h
ssid
2015/07/31 12:59:40
Done.
| |
| 54 } | |
| 55 | |
| 34 } // namespace base | 56 } // namespace base |
| OLD | NEW |