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" | 7 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
8 #include "base/trace_event/heap_profiler_allocation_register.h" | 8 #include "base/trace_event/heap_profiler_allocation_register.h" |
9 #include "base/trace_event/trace_event_memory_overhead.h" | 9 #include "base/trace_event/trace_event_memory_overhead.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
11 #include "platform/web_process_memory_dump_impl.h" | 11 #include "platform/web_process_memory_dump_impl.h" |
12 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
13 #include "public/platform/WebMemoryAllocatorDump.h" | 13 #include "public/platform/WebMemoryAllocatorDump.h" |
14 #include "wtf/StdLibExtras.h" | 14 #include "wtf/StdLibExtras.h" |
15 #include "wtf/Threading.h" | 15 #include "wtf/Threading.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 namespace { | 18 namespace { |
19 | 19 |
20 void dumpMemoryTotals(blink::WebProcessMemoryDump* memoryDump) | 20 void dumpMemoryTotals(blink::WebProcessMemoryDump* memoryDump) |
21 { | 21 { |
22 String dumpName = String::format("blink_gc"); | 22 String dumpName = String::format("blink_gc"); |
23 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum
p(dumpName); | 23 WebMemoryAllocatorDump* allocatorDump = memoryDump->createMemoryAllocatorDum
p(dumpName); |
24 allocatorDump->addScalar("size", "bytes", ProcessHeap::totalAllocatedSpace()
); | 24 allocatorDump->addScalar("size", "bytes", ProcessHeap::totalAllocatedSpace()
); |
25 | 25 |
26 dumpName.append("/allocated_objects"); | 26 dumpName.append("/allocated_objects"); |
27 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump(
dumpName); | 27 WebMemoryAllocatorDump* objectsDump = memoryDump->createMemoryAllocatorDump(
dumpName); |
28 | 28 |
29 // ThreadHeap::markedObjectSize() can be underestimated if we're still in th
e | 29 // Heap::markedObjectSize() can be underestimated if we're still in the |
30 // process of lazy sweeping. | 30 // process of lazy sweeping. |
31 objectsDump->addScalar("size", "bytes", ProcessHeap::totalAllocatedObjectSiz
e() + ProcessHeap::totalMarkedObjectSize()); | 31 objectsDump->addScalar("size", "bytes", ProcessHeap::totalAllocatedObjectSiz
e() + ProcessHeap::totalMarkedObjectSize()); |
32 } | 32 } |
33 | 33 |
34 void reportAllocation(Address address, size_t size, const char* typeName) | 34 void reportAllocation(Address address, size_t size, const char* typeName) |
35 { | 35 { |
36 BlinkGCMemoryDumpProvider::instance()->insert(address, size, typeName); | 36 BlinkGCMemoryDumpProvider::instance()->insert(address, size, typeName); |
37 } | 37 } |
38 | 38 |
39 void reportFree(Address address) | 39 void reportFree(Address address) |
(...skipping 11 matching lines...) Expand all Loading... |
51 | 51 |
52 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() | 52 BlinkGCMemoryDumpProvider::~BlinkGCMemoryDumpProvider() |
53 { | 53 { |
54 } | 54 } |
55 | 55 |
56 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD
etail, blink::WebProcessMemoryDump* memoryDump) | 56 bool BlinkGCMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfD
etail, blink::WebProcessMemoryDump* memoryDump) |
57 { | 57 { |
58 // In the case of a detailed dump perform a mark-only GC pass to collect | 58 // In the case of a detailed dump perform a mark-only GC pass to collect |
59 // more detailed stats. | 59 // more detailed stats. |
60 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) | 60 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) |
61 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::Take
Snapshot, BlinkGC::ForcedGC); | 61 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::TakeSnapsh
ot, BlinkGC::ForcedGC); |
62 dumpMemoryTotals(memoryDump); | 62 dumpMemoryTotals(memoryDump); |
63 | 63 |
64 if (m_isHeapProfilingEnabled) { | 64 if (m_isHeapProfilingEnabled) { |
65 // Overhead should always be reported, regardless of light vs. heavy. | 65 // Overhead should always be reported, regardless of light vs. heavy. |
66 base::trace_event::TraceEventMemoryOverhead overhead; | 66 base::trace_event::TraceEventMemoryOverhead overhead; |
67 base::hash_map<base::trace_event::AllocationContext, size_t> bytesByCont
ext; | 67 base::hash_map<base::trace_event::AllocationContext, size_t> bytesByCont
ext; |
68 { | 68 { |
69 MutexLocker locker(m_allocationRegisterMutex); | 69 MutexLocker locker(m_allocationRegisterMutex); |
70 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { | 70 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { |
71 for (const auto& allocSize : *m_allocationRegister) | 71 for (const auto& allocSize : *m_allocationRegister) |
72 bytesByContext[allocSize.context] += allocSize.size; | 72 bytesByContext[allocSize.context] += allocSize.size; |
73 } | 73 } |
74 m_allocationRegister->EstimateTraceMemoryOverhead(&overhead); | 74 m_allocationRegister->EstimateTraceMemoryOverhead(&overhead); |
75 } | 75 } |
76 memoryDump->dumpHeapUsage(bytesByContext, overhead, "blink_gc"); | 76 memoryDump->dumpHeapUsage(bytesByContext, overhead, "blink_gc"); |
77 } | 77 } |
78 | 78 |
79 // Merge all dumps collected by ThreadHeap::collectGarbage. | 79 // Merge all dumps collected by Heap::collectGarbage. |
80 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) | 80 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) |
81 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); | 81 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 void BlinkGCMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) | 85 void BlinkGCMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) |
86 { | 86 { |
87 if (enabled) { | 87 if (enabled) { |
88 { | 88 { |
89 MutexLocker locker(m_allocationRegisterMutex); | 89 MutexLocker locker(m_allocationRegisterMutex); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 125 } |
126 | 126 |
127 void BlinkGCMemoryDumpProvider::remove(Address address) | 127 void BlinkGCMemoryDumpProvider::remove(Address address) |
128 { | 128 { |
129 MutexLocker locker(m_allocationRegisterMutex); | 129 MutexLocker locker(m_allocationRegisterMutex); |
130 if (m_allocationRegister) | 130 if (m_allocationRegister) |
131 m_allocationRegister->Remove(address); | 131 m_allocationRegister->Remove(address); |
132 } | 132 } |
133 | 133 |
134 } // namespace blink | 134 } // namespace blink |
OLD | NEW |