Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp

Issue 1701813003: Heap Profiling for Oilpan (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change base_name Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 if (m_isHeapProfilingEnabled) {
67 base::trace_event::TraceEventMemoryOverhead overhead;
68 base::hash_map<base::trace_event::AllocationContext, size_t> bytesByCont ext;
69 {
70 MutexLocker locker(m_allocationRegisterMutex);
71 for (const auto& allocSize : *m_allocationRegister)
72 bytesByContext[allocSize.context] += allocSize.size;
73
74 m_allocationRegister->EstimateTraceMemoryOverhead(&overhead);
75 }
76 memoryDump->dumpHeapUsage(bytesByContext, overhead, "blink_gc");
77 }
78
53 // Merge all dumps collected by Heap::collectGarbage. 79 // Merge all dumps collected by Heap::collectGarbage.
54 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get()); 80 memoryDump->takeAllDumpsFrom(m_currentProcessMemoryDump.get());
55 return true; 81 return true;
56 } 82 }
57 83
84 void BlinkGCMemoryDumpProvider::onHeapProfilingEnabled(bool enabled)
85 {
86 if (enabled) {
87 {
88 MutexLocker locker(m_allocationRegisterMutex);
89 if (!m_allocationRegister)
90 m_allocationRegister = adoptPtr(new base::trace_event::Allocatio nRegister());
91 }
92 HeapAllocHooks::setAllocationHook(reportAllocation);
93 HeapAllocHooks::setFreeHook(reportFree);
94 } else {
95 HeapAllocHooks::setAllocationHook(nullptr);
96 HeapAllocHooks::setFreeHook(nullptr);
97 }
98 m_isHeapProfilingEnabled = enabled;
99 }
100
58 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC urrentGC(const String& absoluteName) 101 WebMemoryAllocatorDump* BlinkGCMemoryDumpProvider::createMemoryAllocatorDumpForC urrentGC(const String& absoluteName)
59 { 102 {
60 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName); 103 return m_currentProcessMemoryDump->createMemoryAllocatorDump(absoluteName);
61 } 104 }
62 105
63 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC() 106 void BlinkGCMemoryDumpProvider::clearProcessDumpForCurrentGC()
64 { 107 {
65 m_currentProcessMemoryDump->clear(); 108 m_currentProcessMemoryDump->clear();
66 } 109 }
67 110
68 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() 111 BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider()
69 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo ryDump())) 112 : m_currentProcessMemoryDump(adoptPtr(Platform::current()->createProcessMemo ryDump()))
113 , m_isHeapProfilingEnabled(false)
70 { 114 {
71 } 115 }
72 116
117 void BlinkGCMemoryDumpProvider::insert(Address address, size_t size)
118 {
119 base::trace_event::AllocationContext context = base::trace_event::Allocation ContextTracker::GetContextSnapshot();
120 // TODO(hajimehoshi): Implement to use a correct type name.
121 context.type_name = "";
122 MutexLocker locker(m_allocationRegisterMutex);
123 if (m_allocationRegister)
124 m_allocationRegister->Insert(address, size, context);
125 }
126
127 void BlinkGCMemoryDumpProvider::remove(Address address)
128 {
129 MutexLocker locker(m_allocationRegisterMutex);
130 if (m_allocationRegister)
131 m_allocationRegister->Remove(address);
132 }
133
73 } // namespace blink 134 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698