| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/heap/BlinkGCMemoryDumpProvider.h" | 6 #include "platform/heap/BlinkGCMemoryDumpProvider.h" |
| 7 | 7 |
| 8 #include "base/trace_event/memory_allocator_dump.h" |
| 9 #include "base/trace_event/process_memory_dump.h" |
| 8 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 9 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 10 #include "public/platform/WebMemoryAllocatorDump.h" | |
| 11 #include "public/platform/WebProcessMemoryDump.h" | |
| 12 #include "wtf/StdLibExtras.h" | 12 #include "wtf/StdLibExtras.h" |
| 13 #include "wtf/Threading.h" | 13 #include "wtf/Threading.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 void dumpMemoryTotals(blink::WebProcessMemoryDump* memoryDump) | 18 using base::trace_event::MemoryAllocatorDump; |
| 19 using base::trace_event::ProcessMemoryDump; |
| 20 |
| 21 void dumpMemoryTotals(ProcessMemoryDump* memoryDump) |
| 19 { | 22 { |
| 20 String dumpName = String::format("blink_gc"); | 23 String dumpName = String::format("blink_gc"); |
| 21 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum
p(dumpName); | 24 MemoryAllocatorDump* allocatorDump = memoryDump->CreateAllocatorDump(dumpNam
e.toUTF8StdString()); |
| 22 allocatorDump->AddScalar("size", "bytes", Heap::allocatedSpace()); | 25 allocatorDump->AddScalar("size", "bytes", Heap::allocatedSpace()); |
| 23 | 26 |
| 24 dumpName.append("/allocated_objects"); | 27 dumpName.append("/allocated_objects"); |
| 25 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump(
dumpName); | 28 MemoryAllocatorDump* objectsDump = memoryDump->CreateAllocatorDump(dumpName.
toUTF8StdString()); |
| 26 | 29 |
| 27 // Heap::markedObjectSize() can be underestimated if we're still in the | 30 // Heap::markedObjectSize() can be underestimated if we're still in the |
| 28 // process of lazy sweeping. | 31 // process of lazy sweeping. |
| 29 objectsDump->AddScalar("size", "bytes", Heap::allocatedObjectSize() + Heap::
markedObjectSize()); | 32 objectsDump->AddScalar(MemoryAllocatorDump::kNameSize, MemoryAllocatorDump::
kUnitsBytes, Heap::allocatedObjectSize() + Heap::markedObjectSize()); |
| 30 } | 33 } |
| 31 | 34 |
| 32 } // namespace | 35 } // namespace |
| 33 | 36 |
| 34 BlinkGCMemoryDumpProvider* BlinkGCMemoryDumpProvider::instance() | 37 BlinkGCMemoryDumpProvider* BlinkGCMemoryDumpProvider::instance() |
| 35 { | 38 { |
| 36 DEFINE_STATIC_LOCAL(BlinkGCMemoryDumpProvider, instance, ()); | 39 DEFINE_STATIC_LOCAL(BlinkGCMemoryDumpProvider, instance, ()); |
| 37 return &instance; | 40 return &instance; |
| 38 } | 41 } |
| 39 | 42 |
| 40 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() | 43 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() |
| 41 { | 44 { |
| 42 } | 45 } |
| 43 | 46 |
| 44 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD
etail, blink::WebProcessMemoryDump* memoryDump) | 47 bool BlinkGCMemoryDumpProvider::OnMemoryDump(const base::trace_event::MemoryDump
Args& args, base::trace_event::ProcessMemoryDump* memoryDump) |
| 45 { | 48 { |
| 46 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Light) { | 49 if (args.level_of_detail == base::trace_event::MemoryDumpLevelOfDetail::LIGH
T) { |
| 47 dumpMemoryTotals(memoryDump); | 50 dumpMemoryTotals(memoryDump); |
| 48 return true; | 51 return true; |
| 49 } | 52 } |
| 50 | 53 |
| 51 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::TakeSn
apshot, Heap::ForcedGC); | 54 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::TakeSn
apshot, Heap::ForcedGC); |
| 52 dumpMemoryTotals(memoryDump); | 55 dumpMemoryTotals(memoryDump); |
| 53 | 56 |
| 54 // Merge all dumps collected by Heap::collectGarbage. | 57 // Merge all dumps collected by Heap::collectGarbage. |
| 55 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); | 58 memoryDump->TakeAllDumpsFrom(m_currentProcessMemoryDump.get()); |
| 56 return true; | 59 return true; |
| 57 } | 60 } |
| 58 | 61 |
| 59 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC
urrentGC(const String& absoluteName) | 62 MemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForCurr
entGC(const String& absoluteName) |
| 60 { | 63 { |
| 61 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName); | 64 return m_currentProcessMemoryDump->CreateAllocatorDump(absoluteName.toUTF8St
dString()); |
| 62 } | 65 } |
| 63 | 66 |
| 64 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() | 67 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() |
| 65 { | 68 { |
| 66 m_currentProcessMemoryDump->clear(); | 69 m_currentProcessMemoryDump->Clear(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() | 72 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() |
| 70 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo
ryDump())) | 73 : m_currentProcessMemoryDump(adoptPtr(new base::trace_event::ProcessMemoryDu
mp(nullptr))) |
| 71 { | 74 { |
| 72 } | 75 } |
| 73 | 76 |
| 74 } // namespace blink | 77 } // namespace blink |
| OLD | NEW |