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 "platform/heap/BlinkGCMemoryDumpProvider.h" | 5 #include "platform/heap/BlinkGCMemoryDumpProvider.h" |
| 6 | 6 |
| 7 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | |
| 8 #include "base/trace_event/heap_profiler_allocation_register.h" | |
| 9 #include "base/trace_event/trace_event_memory_overhead.h" | |
| 7 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 8 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 9 #include "public/platform/WebMemoryAllocatorDump.h" | 12 #include "public/platform/WebMemoryAllocatorDump.h" |
| 10 #include "public/platform/WebProcessMemoryDump.h" | 13 #include "public/platform/WebProcessMemoryDump.h" |
| 11 #include "wtf/StdLibExtras.h" | 14 #include "wtf/StdLibExtras.h" |
| 12 #include "wtf/Threading.h" | 15 #include "wtf/Threading.h" |
| 13 | 16 |
| 14 namespace blink { | 17 namespace blink { |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 void dumpMemoryTotals(blink::WebProcessMemoryDump* memoryDump) | 20 void dumpMemoryTotals(blink::WebProcessMemoryDump* memoryDump) |
| 18 { | 21 { |
| 19 String dumpName = String::format("blink_gc"); | 22 String dumpName = String::format("blink_gc"); |
| 20 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum p(dumpName); | 23 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum p(dumpName); |
| 21 allocatorDump->addScalar("size", "bytes", Heap::allocatedSpace()); | 24 allocatorDump->addScalar("size", "bytes", Heap::allocatedSpace()); |
| 22 | 25 |
| 23 dumpName.append("/allocated_objects"); | 26 dumpName.append("/allocated_objects"); |
| 24 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump( dumpName); | 27 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump( dumpName); |
| 25 | 28 |
| 26 // Heap::markedObjectSize() can be underestimated if we're still in the | 29 // Heap::markedObjectSize() can be underestimated if we're still in the |
| 27 // process of lazy sweeping. | 30 // process of lazy sweeping. |
| 28 objectsDump->addScalar("size", "bytes", Heap::allocatedObjectSize() + Heap:: markedObjectSize()); | 31 objectsDump->addScalar("size", "bytes", Heap::allocatedObjectSize() + Heap:: markedObjectSize()); |
| 29 } | 32 } |
| 30 | 33 |
| 34 void reportAllocation(Address address, size_t size) | |
| 35 { | |
| 36 BlinkGCMemoryDumpProvider::instance()->insert(address, size); | |
| 37 } | |
| 38 | |
| 39 void reportFree(Address address) | |
| 40 { | |
| 41 BlinkGCMemoryDumpProvider::instance()->remove(address); | |
| 42 } | |
| 43 | |
| 31 } // namespace | 44 } // namespace |
| 32 | 45 |
| 33 BlinkGCMemoryDumpProvider* BlinkGCMemoryDumpProvider::instance() | 46 BlinkGCMemoryDumpProvider* BlinkGCMemoryDumpProvider::instance() |
| 34 { | 47 { |
| 35 DEFINE_STATIC_LOCAL(BlinkGCMemoryDumpProvider, instance, ()); | 48 DEFINE_STATIC_LOCAL(BlinkGCMemoryDumpProvider, instance, ()); |
| 36 return &instance; | 49 return &instance; |
| 37 } | 50 } |
| 38 | 51 |
| 39 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() | 52 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() |
| 40 { | 53 { |
| 41 } | 54 } |
| 42 | 55 |
| 43 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD etail, blink::WebProcessMemoryDump* memoryDump) | 56 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD etail, blink::WebProcessMemoryDump* memoryDump) |
| 44 { | 57 { |
| 45 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Light) { | 58 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Light) { |
| 46 dumpMemoryTotals(memoryDump); | 59 dumpMemoryTotals(memoryDump); |
| 47 return true; | 60 return true; |
| 48 } | 61 } |
| 49 | 62 |
| 50 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::TakeSnapshot, BlinkGC::ForcedGC); | 63 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::TakeSnapshot, BlinkGC::ForcedGC); |
| 51 dumpMemoryTotals(memoryDump); | 64 dumpMemoryTotals(memoryDump); |
| 52 | 65 |
| 66 // TODO(hajimehoshi): This doesn't work causing assert error: [process_memor y_dump.cc(149)] Check failed: 0ul == allocator_dumps_.count(mad->absolute_name() ) (0 vs. 1) | |
|
hajimehoshi
2016/02/16 11:02:07
primiano: I simply copied this dump heap usage log
Primiano Tucci (use gerrit)
2016/02/16 11:16:42
Oh I think I know what it is: is the overhead dump
hajimehoshi
2016/02/17 09:19:40
Thanks, done.
| |
| 67 if (m_isHeapProfilingEnabled) { | |
| 68 base::trace_event::TraceEventMemoryOverhead overhead; | |
| 69 base::hash_map<base::trace_event::AllocationContext, size_t> bytesByCont ext; | |
| 70 { | |
| 71 MutexLocker locker(m_allocationRegisterMutex); | |
| 72 for (const auto& allocSize : *m_allocationRegister) | |
| 73 bytesByContext[allocSize.context] += allocSize.size; | |
| 74 | |
| 75 m_allocationRegister->EstimateTraceMemoryOverhead(&overhead); | |
| 76 } | |
| 77 memoryDump->dumpHeapUsage(bytesByContext, overhead, "blink_gc"); | |
| 78 } | |
| 79 | |
| 53 // Merge all dumps collected by Heap::collectGarbage. | 80 // Merge all dumps collected by Heap::collectGarbage. |
| 54 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); | 81 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); |
| 55 return true; | 82 return true; |
| 56 } | 83 } |
| 57 | 84 |
| 85 void BlinkGCMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) | |
| 86 { | |
| 87 if (enabled) { | |
| 88 { | |
| 89 MutexLocker locker(m_allocationRegisterMutex); | |
| 90 if (!m_allocationRegister) | |
| 91 m_allocationRegister = adoptPtr(new base::trace_event::Allocatio nRegister()); | |
| 92 } | |
| 93 HeapAllocHooks::setAllocationHook(reportAllocation); | |
| 94 HeapAllocHooks::setFreeHook(reportFree); | |
| 95 } else { | |
| 96 HeapAllocHooks::setAllocationHook(nullptr); | |
| 97 HeapAllocHooks::setFreeHook(nullptr); | |
| 98 } | |
|
Primiano Tucci (use gerrit)
2016/02/16 11:16:42
similarly to the other CL, I think you might want
hajimehoshi
2016/02/17 09:19:40
In PartitionAllocMemoryDumpProvider, no tearing do
haraken
2016/02/17 09:23:05
Would it make sense to support disabling the heap
hajimehoshi
2016/02/17 09:57:38
+1 to haraken
Primiano Tucci (use gerrit)
2016/02/17 10:13:46
You are right. The only motivation I see for tear-
| |
| 99 m_isHeapProfilingEnabled = enabled; | |
| 100 } | |
| 101 | |
| 58 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC urrentGC(const String& absoluteName) | 102 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC urrentGC(const String& absoluteName) |
| 59 { | 103 { |
| 60 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName); | 104 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName); |
| 61 } | 105 } |
| 62 | 106 |
| 63 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() | 107 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() |
| 64 { | 108 { |
| 65 m_currentProcessMemoryDump->clear(); | 109 m_currentProcessMemoryDump->clear(); |
| 66 } | 110 } |
| 67 | 111 |
| 68 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() | 112 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() |
| 69 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo ryDump())) | 113 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo ryDump())) |
| 114 , m_isHeapProfilingEnabled(false) | |
| 70 { | 115 { |
| 71 } | 116 } |
| 72 | 117 |
| 118 void BlinkGCMemoryDumpProvider::insert(Address address, size_t size) | |
| 119 { | |
| 120 base::trace_event::AllocationContext context = base::trace_event::Allocation ContextTracker::GetContextSnapshot(); | |
| 121 // TODO(hajimehoshi): Implement to use a correct type name. | |
| 122 context.type_name = "(other)"; | |
|
Primiano Tucci (use gerrit)
2016/02/16 11:16:42
I think you can leave it empty, and will just appe
hajimehoshi
2016/02/17 09:19:40
Done.
| |
| 123 MutexLocker locker(m_allocationRegisterMutex); | |
| 124 if (m_allocationRegister) | |
| 125 m_allocationRegister->Insert(address, size, context); | |
| 126 } | |
| 127 | |
| 128 void BlinkGCMemoryDumpProvider::remove(Address address) | |
| 129 { | |
| 130 MutexLocker locker(m_allocationRegisterMutex); | |
| 131 if (m_allocationRegister) | |
| 132 m_allocationRegister->Remove(address); | |
| 133 } | |
| 134 | |
| 73 } // namespace blink | 135 } // namespace blink |
| OLD | NEW |