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

Side by Side Diff: third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp

Issue 1910253003: PartitionAllocMemoryDumpProvider can directly inherit from MemoryDumpProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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/PartitionAllocMemoryDumpProvider.h" 5 #include "platform/PartitionAllocMemoryDumpProvider.h"
6 6
7 #include "base/strings/stringprintf.h"
7 #include "base/trace_event/heap_profiler_allocation_context.h" 8 #include "base/trace_event/heap_profiler_allocation_context.h"
8 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 9 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
9 #include "base/trace_event/heap_profiler_allocation_register.h" 10 #include "base/trace_event/heap_profiler_allocation_register.h"
10 #include "base/trace_event/process_memory_dump.h" 11 #include "base/trace_event/process_memory_dump.h"
11 #include "base/trace_event/trace_event_memory_overhead.h" 12 #include "base/trace_event/trace_event_memory_overhead.h"
12 #include "public/platform/WebMemoryAllocatorDump.h"
13 #include "public/platform/WebProcessMemoryDump.h"
14 #include "wtf/allocator/Partitions.h" 13 #include "wtf/allocator/Partitions.h"
15 #include "wtf/text/WTFString.h" 14 #include "wtf/text/WTFString.h"
16 15
17 namespace blink { 16 namespace blink {
18 17
19 namespace { 18 namespace {
20 19
21 using namespace WTF; 20 using namespace WTF;
22 21
23 void reportAllocation(void* address, size_t size, const char* typeName) 22 void reportAllocation(void* address, size_t size, const char* typeName)
24 { 23 {
25 PartitionAllocMemoryDumpProvider::instance()->insert(address, size, typeName ); 24 PartitionAllocMemoryDumpProvider::instance()->insert(address, size, typeName );
26 } 25 }
27 26
28 void reportFree(void* address) 27 void reportFree(void* address)
29 { 28 {
30 PartitionAllocMemoryDumpProvider::instance()->remove(address); 29 PartitionAllocMemoryDumpProvider::instance()->remove(address);
31 } 30 }
32 31
33 const char kPartitionAllocDumpName[] = "partition_alloc"; 32 const char kPartitionAllocDumpName[] = "partition_alloc";
34 const char kPartitionsDumpName[] = "partitions"; 33 const char kPartitionsDumpName[] = "partitions";
35 34
36 String getPartitionDumpName(const char* partitionName) 35 std::string getPartitionDumpName(const char* partitionName)
37 { 36 {
38 return String::format("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDumpNa me, partitionName); 37 return base::StringPrintf("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDu mpName, partitionName);
39 } 38 }
40 39
41 // This class is used to invert the dependency of PartitionAlloc on the 40 // This class is used to invert the dependency of PartitionAlloc on the
42 // PartitionAllocMemoryDumpProvider. This implements an interface that will 41 // PartitionAllocMemoryDumpProvider. This implements an interface that will
43 // be called with memory statistics for each bucket in the allocator. 42 // be called with memory statistics for each bucket in the allocator.
44 class PartitionStatsDumperImpl final : public PartitionStatsDumper { 43 class PartitionStatsDumperImpl final : public PartitionStatsDumper {
45 DISALLOW_NEW(); 44 DISALLOW_NEW();
46 WTF_MAKE_NONCOPYABLE(PartitionStatsDumperImpl); 45 WTF_MAKE_NONCOPYABLE(PartitionStatsDumperImpl);
47 public: 46 public:
48 PartitionStatsDumperImpl(WebProcessMemoryDump* memoryDump, WebMemoryDumpLeve lOfDetail levelOfDetail) 47 PartitionStatsDumperImpl(base::trace_event::ProcessMemoryDump* memoryDump, b ase::trace_event::MemoryDumpLevelOfDetail levelOfDetail)
49 : m_memoryDump(memoryDump) 48 : m_memoryDump(memoryDump)
50 , m_uid(0) 49 , m_uid(0)
51 , m_totalActiveBytes(0) 50 , m_totalActiveBytes(0)
52 { 51 {
53 } 52 }
54 53
55 // PartitionStatsDumper implementation. 54 // PartitionStatsDumper implementation.
56 void partitionDumpTotals(const char* partitionName, const PartitionMemorySta ts*) override; 55 void partitionDumpTotals(const char* partitionName, const PartitionMemorySta ts*) override;
57 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats*) override; 56 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats*) override;
58 57
59 size_t totalActiveBytes() const { return m_totalActiveBytes; } 58 size_t totalActiveBytes() const { return m_totalActiveBytes; }
60 59
61 private: 60 private:
62 WebProcessMemoryDump* m_memoryDump; 61 base::trace_event::ProcessMemoryDump* m_memoryDump;
63 unsigned long m_uid; 62 unsigned long m_uid;
64 size_t m_totalActiveBytes; 63 size_t m_totalActiveBytes;
65 }; 64 };
66 65
67 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, co nst PartitionMemoryStats* memoryStats) 66 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, co nst PartitionMemoryStats* memoryStats)
68 { 67 {
69 m_totalActiveBytes += memoryStats->totalActiveBytes; 68 m_totalActiveBytes += memoryStats->totalActiveBytes;
70 String dumpName = getPartitionDumpName(partitionName); 69 std::string dumpName = getPartitionDumpName(partitionName);
71 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorD ump(dumpName); 70 base::trace_event::MemoryAllocatorDump* allocatorDump = m_memoryDump->Create AllocatorDump(dumpName);
72 allocatorDump->addScalar("size", "bytes", memoryStats->totalResidentBytes); 71 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes);
73 allocatorDump->addScalar("allocated_objects_size", "bytes", memoryStats->tot alActiveBytes); 72 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->tot alActiveBytes);
74 allocatorDump->addScalar("virtual_size", "bytes", memoryStats->totalMmappedB ytes); 73 allocatorDump->AddScalar("virtual_size", "bytes", memoryStats->totalMmappedB ytes);
75 allocatorDump->addScalar("virtual_committed_size", "bytes", memoryStats->tot alCommittedBytes); 74 allocatorDump->AddScalar("virtual_committed_size", "bytes", memoryStats->tot alCommittedBytes);
76 allocatorDump->addScalar("decommittable_size", "bytes", memoryStats->totalDe committableBytes); 75 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->totalDe committableBytes);
77 allocatorDump->addScalar("discardable_size", "bytes", memoryStats->totalDisc ardableBytes); 76 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->totalDisc ardableBytes);
78 } 77 }
79 78
80 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionNa me, const PartitionBucketMemoryStats* memoryStats) 79 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionNa me, const PartitionBucketMemoryStats* memoryStats)
81 { 80 {
82 ASSERT(memoryStats->isValid); 81 ASSERT(memoryStats->isValid);
83 String dumpName = getPartitionDumpName(partitionName); 82 std::string dumpName = getPartitionDumpName(partitionName);
84 if (memoryStats->isDirectMap) 83 if (memoryStats->isDirectMap)
85 dumpName.append(String::format("/directMap_%lu", ++m_uid)); 84 dumpName.append(base::StringPrintf("/directMap_%lu", ++m_uid));
86 else 85 else
87 dumpName.append(String::format("/bucket_%u", static_cast<unsigned>(memor yStats->bucketSlotSize))); 86 dumpName.append(base::StringPrintf("/bucket_%u", static_cast<unsigned>(m emoryStats->bucketSlotSize)));
88 87
89 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorD ump(dumpName); 88 base::trace_event::MemoryAllocatorDump* allocatorDump = m_memoryDump->Create AllocatorDump(dumpName);
90 allocatorDump->addScalar("size", "bytes", memoryStats->residentBytes); 89 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes);
91 allocatorDump->addScalar("allocated_objects_size", "bytes", memoryStats->act iveBytes); 90 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->act iveBytes);
92 allocatorDump->addScalar("slot_size", "bytes", memoryStats->bucketSlotSize); 91 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize);
93 allocatorDump->addScalar("decommittable_size", "bytes", memoryStats->decommi ttableBytes); 92 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->decommi ttableBytes);
94 allocatorDump->addScalar("discardable_size", "bytes", memoryStats->discardab leBytes); 93 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->discardab leBytes);
95 allocatorDump->addScalar("total_pages_size", "bytes", memoryStats->allocated PageSize); 94 allocatorDump->AddScalar("total_pages_size", "bytes", memoryStats->allocated PageSize);
96 allocatorDump->addScalar("active_pages", "objects", memoryStats->numActivePa ges); 95 allocatorDump->AddScalar("active_pages", "objects", memoryStats->numActivePa ges);
97 allocatorDump->addScalar("full_pages", "objects", memoryStats->numFullPages) ; 96 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages) ;
98 allocatorDump->addScalar("empty_pages", "objects", memoryStats->numEmptyPage s); 97 allocatorDump->AddScalar("empty_pages", "objects", memoryStats->numEmptyPage s);
99 allocatorDump->addScalar("decommitted_pages", "objects", memoryStats->numDec ommittedPages); 98 allocatorDump->AddScalar("decommitted_pages", "objects", memoryStats->numDec ommittedPages);
100 } 99 }
101 100
102 } // namespace 101 } // namespace
103 102
104 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance() 103 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance()
105 { 104 {
106 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ()); 105 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ());
107 return &instance; 106 return &instance;
108 } 107 }
109 108
110 bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail l evelOfDetail, WebProcessMemoryDump* memoryDump) 109 bool PartitionAllocMemoryDumpProvider::OnMemoryDump(const base::trace_event::Mem oryDumpArgs& args, base::trace_event::ProcessMemoryDump* memoryDump)
111 { 110 {
111 using base::trace_event::MemoryDumpLevelOfDetail;
112
113 MemoryDumpLevelOfDetail levelOfDetail = args.level_of_detail;
112 if (m_isHeapProfilingEnabled) { 114 if (m_isHeapProfilingEnabled) {
113 // Overhead should always be reported, regardless of light vs. heavy. 115 // Overhead should always be reported, regardless of light vs. heavy.
114 base::trace_event::TraceEventMemoryOverhead overhead; 116 base::trace_event::TraceEventMemoryOverhead overhead;
115 base::hash_map<base::trace_event::AllocationContext, base::trace_event:: AllocationMetrics> metricsByContext; 117 base::hash_map<base::trace_event::AllocationContext, base::trace_event:: AllocationMetrics> metricsByContext;
116 { 118 {
117 MutexLocker locker(m_allocationRegisterMutex); 119 MutexLocker locker(m_allocationRegisterMutex);
118 // Dump only the overhead estimation in non-detailed dumps. 120 // Dump only the overhead estimation in non-detailed dumps.
119 if (levelOfDetail == WebMemoryDumpLevelOfDetail::Detailed) { 121 if (levelOfDetail == MemoryDumpLevelOfDetail::DETAILED) {
120 for (const auto& allocSize : *m_allocationRegister) { 122 for (const auto& allocSize : *m_allocationRegister) {
121 base::trace_event::AllocationMetrics& metrics = metricsByCon text[allocSize.context]; 123 base::trace_event::AllocationMetrics& metrics = metricsByCon text[allocSize.context];
122 metrics.size += allocSize.size; 124 metrics.size += allocSize.size;
123 metrics.count++; 125 metrics.count++;
124 } 126 }
125 } 127 }
126 m_allocationRegister->EstimateTraceMemoryOverhead(&overhead); 128 m_allocationRegister->EstimateTraceMemoryOverhead(&overhead);
127 } 129 }
128 memoryDump->dumpHeapUsage(metricsByContext, overhead, "partition_alloc") ; 130 memoryDump->DumpHeapUsage(metricsByContext, overhead, "partition_alloc") ;
129 } 131 }
130 132
131 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail); 133 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail);
132 134
133 WebMemoryAllocatorDump* partitionsDump = memoryDump->createMemoryAllocatorDu mp( 135 base::trace_event::MemoryAllocatorDump* partitionsDump = memoryDump->CreateA llocatorDump(
134 String::format("%s/%s", kPartitionAllocDumpName, kPartitionsDumpName)); 136 base::StringPrintf("%s/%s", kPartitionAllocDumpName, kPartitionsDumpName ));
135 137
136 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics. 138 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics.
137 WTF::Partitions::dumpMemoryStats(levelOfDetail == WebMemoryDumpLevelOfDetail ::Light, &partitionStatsDumper); 139 WTF::Partitions::dumpMemoryStats(levelOfDetail == MemoryDumpLevelOfDetail::L IGHT, &partitionStatsDumper);
138 140
139 WebMemoryAllocatorDump* allocatedObjectsDump = memoryDump->createMemoryAlloc atorDump(String(Partitions::kAllocatedObjectPoolName)); 141 base::trace_event::MemoryAllocatorDump* allocatedObjectsDump = memoryDump->C reateAllocatorDump(Partitions::kAllocatedObjectPoolName);
140 allocatedObjectsDump->addScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes()); 142 allocatedObjectsDump->AddScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes());
141 memoryDump->addOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid()); 143 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid());
142 144
143 return true; 145 return true;
144 } 146 }
145 147
146 // |m_allocationRegister| should be initialized only when necessary to avoid was te of memory. 148 // |m_allocationRegister| should be initialized only when necessary to avoid was te of memory.
147 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() 149 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider()
148 : m_allocationRegister(nullptr) 150 : m_allocationRegister(nullptr)
149 , m_isHeapProfilingEnabled(false) 151 , m_isHeapProfilingEnabled(false)
150 { 152 {
151 } 153 }
152 154
153 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() 155 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider()
154 { 156 {
155 } 157 }
156 158
157 void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) 159 void PartitionAllocMemoryDumpProvider::OnHeapProfilingEnabled(bool enabled)
158 { 160 {
159 if (enabled) { 161 if (enabled) {
160 { 162 {
161 MutexLocker locker(m_allocationRegisterMutex); 163 MutexLocker locker(m_allocationRegisterMutex);
162 if (!m_allocationRegister) 164 if (!m_allocationRegister)
163 m_allocationRegister = adoptPtr(new base::trace_event::Allocatio nRegister()); 165 m_allocationRegister.reset(new base::trace_event::AllocationRegi ster());
164 } 166 }
165 PartitionAllocHooks::setAllocationHook(reportAllocation); 167 PartitionAllocHooks::setAllocationHook(reportAllocation);
166 PartitionAllocHooks::setFreeHook(reportFree); 168 PartitionAllocHooks::setFreeHook(reportFree);
167 } else { 169 } else {
168 PartitionAllocHooks::setAllocationHook(nullptr); 170 PartitionAllocHooks::setAllocationHook(nullptr);
169 PartitionAllocHooks::setFreeHook(nullptr); 171 PartitionAllocHooks::setFreeHook(nullptr);
170 } 172 }
171 m_isHeapProfilingEnabled = enabled; 173 m_isHeapProfilingEnabled = enabled;
172 } 174 }
173 175
174 void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const char* typeName) 176 void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const char* typeName)
175 { 177 {
176 base::trace_event::AllocationContext context = base::trace_event::Allocation ContextTracker::GetInstanceForCurrentThread()->GetContextSnapshot(); 178 base::trace_event::AllocationContext context = base::trace_event::Allocation ContextTracker::GetInstanceForCurrentThread()->GetContextSnapshot();
177 context.type_name = typeName; 179 context.type_name = typeName;
178 MutexLocker locker(m_allocationRegisterMutex); 180 MutexLocker locker(m_allocationRegisterMutex);
179 if (m_allocationRegister) 181 if (m_allocationRegister)
180 m_allocationRegister->Insert(address, size, context); 182 m_allocationRegister->Insert(address, size, context);
181 } 183 }
182 184
183 void PartitionAllocMemoryDumpProvider::remove(void* address) 185 void PartitionAllocMemoryDumpProvider::remove(void* address)
184 { 186 {
185 MutexLocker locker(m_allocationRegisterMutex); 187 MutexLocker locker(m_allocationRegisterMutex);
186 if (m_allocationRegister) 188 if (m_allocationRegister)
187 m_allocationRegister->Remove(address); 189 m_allocationRegister->Remove(address);
188 } 190 }
189 191
190 } // namespace blink 192 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698