| 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 "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
| 9 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 10 #include "public/platform/WebMemoryAllocatorDump.h" | 10 #include "public/platform/WebMemoryAllocatorDump.h" |
| 11 #include "public/platform/WebProcessMemoryDump.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 { |
| 17 |
| 18 void dumpMemoryTotals(blink::WebProcessMemoryDump* memoryDump) |
| 19 { |
| 20 String dumpName = String::format("blink_gc"); |
| 21 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum
p(dumpName); |
| 22 allocatorDump->AddScalar("size", "bytes", Heap::allocatedSpace()); |
| 23 |
| 24 dumpName.append("/allocated_objects"); |
| 25 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump(
dumpName); |
| 26 |
| 27 // Heap::markedObjectSize() can be underestimated if we're still in the |
| 28 // process of lazy sweeping. |
| 29 objectsDump->AddScalar("size", "bytes", Heap::allocatedObjectSize() + Heap::
markedObjectSize()); |
| 30 } |
| 31 |
| 32 } // namespace |
| 16 | 33 |
| 17 BlinkGCMemoryDumpProvider* BlinkGCMemoryDumpProvider::instance() | 34 BlinkGCMemoryDumpProvider* BlinkGCMemoryDumpProvider::instance() |
| 18 { | 35 { |
| 19 DEFINE_STATIC_LOCAL(BlinkGCMemoryDumpProvider, instance, ()); | 36 DEFINE_STATIC_LOCAL(BlinkGCMemoryDumpProvider, instance, ()); |
| 20 return &instance; | 37 return &instance; |
| 21 } | 38 } |
| 22 | 39 |
| 23 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() | 40 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() |
| 24 { | 41 { |
| 25 } | 42 } |
| 26 | 43 |
| 27 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD
etail, blink::WebProcessMemoryDump* memoryDump) | 44 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD
etail, blink::WebProcessMemoryDump* memoryDump) |
| 28 { | 45 { |
| 29 // TODO(ssid): Use levelOfDetail to create light dumps when requested (crbug
.com/499731). | 46 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Low) { |
| 47 dumpMemoryTotals(memoryDump); |
| 48 return true; |
| 49 } |
| 30 | 50 |
| 31 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::TakeSn
apshot, Heap::ForcedGC); | 51 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::TakeSn
apshot, Heap::ForcedGC); |
| 32 String dumpName = String::format("blink_gc/thread_%lu", static_cast<unsigned
long>(WTF::currentThread())); | 52 dumpMemoryTotals(memoryDump); |
| 33 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum
p(dumpName); | |
| 34 allocatorDump->AddScalar("size", "bytes", Heap::allocatedSpace()); | |
| 35 | |
| 36 dumpName.append("/allocated_objects"); | |
| 37 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump(
dumpName); | |
| 38 objectsDump->AddScalar("size", "bytes", Heap::allocatedObjectSize() + Heap::
markedObjectSize()); | |
| 39 | 53 |
| 40 // Merge all dumps collected by Heap::collectGarbage. | 54 // Merge all dumps collected by Heap::collectGarbage. |
| 41 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); | 55 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); |
| 42 return true; | 56 return true; |
| 43 } | 57 } |
| 44 | 58 |
| 45 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC
urrentGC(const String& absoluteName) | 59 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC
urrentGC(const String& absoluteName) |
| 46 { | 60 { |
| 47 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName); | 61 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName); |
| 48 } | 62 } |
| 49 | 63 |
| 50 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() | 64 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() |
| 51 { | 65 { |
| 52 m_currentProcessMemoryDump->clear(); | 66 m_currentProcessMemoryDump->clear(); |
| 53 } | 67 } |
| 54 | 68 |
| 55 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() | 69 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() |
| 56 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo
ryDump())) | 70 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo
ryDump())) |
| 57 { | 71 { |
| 58 } | 72 } |
| 59 | 73 |
| 60 } // namespace blink | 74 } // namespace blink |
| OLD | NEW |