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/PartitionAllocMemoryDumpProvider.h" | 5 #include "platform/PartitionAllocMemoryDumpProvider.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/trace_event/heap_profiler_allocation_context.h" | 8 #include "base/trace_event/heap_profiler_allocation_context.h" |
9 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 9 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
10 #include "base/trace_event/heap_profiler_allocation_register.h" | 10 #include "base/trace_event/heap_profiler_allocation_register.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 const char kPartitionsDumpName[] = "partitions"; | 31 const char kPartitionsDumpName[] = "partitions"; |
32 | 32 |
33 std::string getPartitionDumpName(const char* partitionName) { | 33 std::string getPartitionDumpName(const char* partitionName) { |
34 return base::StringPrintf("%s/%s/%s", kPartitionAllocDumpName, | 34 return base::StringPrintf("%s/%s/%s", kPartitionAllocDumpName, |
35 kPartitionsDumpName, partitionName); | 35 kPartitionsDumpName, partitionName); |
36 } | 36 } |
37 | 37 |
38 // This class is used to invert the dependency of PartitionAlloc on the | 38 // This class is used to invert the dependency of PartitionAlloc on the |
39 // PartitionAllocMemoryDumpProvider. This implements an interface that will | 39 // PartitionAllocMemoryDumpProvider. This implements an interface that will |
40 // be called with memory statistics for each bucket in the allocator. | 40 // be called with memory statistics for each bucket in the allocator. |
41 class PartitionStatsDumperImpl final : public PartitionStatsDumper { | 41 class PartitionStatsDumperImpl final : public WTF::PartitionStatsDumper { |
42 DISALLOW_NEW(); | 42 DISALLOW_NEW(); |
43 WTF_MAKE_NONCOPYABLE(PartitionStatsDumperImpl); | 43 WTF_MAKE_NONCOPYABLE(PartitionStatsDumperImpl); |
44 | 44 |
45 public: | 45 public: |
46 PartitionStatsDumperImpl( | 46 PartitionStatsDumperImpl( |
47 base::trace_event::ProcessMemoryDump* memoryDump, | 47 base::trace_event::ProcessMemoryDump* memoryDump, |
48 base::trace_event::MemoryDumpLevelOfDetail levelOfDetail) | 48 base::trace_event::MemoryDumpLevelOfDetail levelOfDetail) |
49 : m_memoryDump(memoryDump), m_uid(0), m_totalActiveBytes(0) {} | 49 : m_memoryDump(memoryDump), m_uid(0), m_totalActiveBytes(0) {} |
50 | 50 |
51 // PartitionStatsDumper implementation. | 51 // PartitionStatsDumper implementation. |
52 void partitionDumpTotals(const char* partitionName, | 52 void partitionDumpTotals(const char* partitionName, |
53 const PartitionMemoryStats*) override; | 53 const WTF::PartitionMemoryStats*) override; |
54 void partitionsDumpBucketStats(const char* partitionName, | 54 void partitionsDumpBucketStats( |
55 const PartitionBucketMemoryStats*) override; | 55 const char* partitionName, |
| 56 const WTF::PartitionBucketMemoryStats*) override; |
56 | 57 |
57 size_t totalActiveBytes() const { return m_totalActiveBytes; } | 58 size_t totalActiveBytes() const { return m_totalActiveBytes; } |
58 | 59 |
59 private: | 60 private: |
60 base::trace_event::ProcessMemoryDump* m_memoryDump; | 61 base::trace_event::ProcessMemoryDump* m_memoryDump; |
61 unsigned long m_uid; | 62 unsigned long m_uid; |
62 size_t m_totalActiveBytes; | 63 size_t m_totalActiveBytes; |
63 }; | 64 }; |
64 | 65 |
65 void PartitionStatsDumperImpl::partitionDumpTotals( | 66 void PartitionStatsDumperImpl::partitionDumpTotals( |
66 const char* partitionName, | 67 const char* partitionName, |
67 const PartitionMemoryStats* memoryStats) { | 68 const WTF::PartitionMemoryStats* memoryStats) { |
68 m_totalActiveBytes += memoryStats->totalActiveBytes; | 69 m_totalActiveBytes += memoryStats->totalActiveBytes; |
69 std::string dumpName = getPartitionDumpName(partitionName); | 70 std::string dumpName = getPartitionDumpName(partitionName); |
70 base::trace_event::MemoryAllocatorDump* allocatorDump = | 71 base::trace_event::MemoryAllocatorDump* allocatorDump = |
71 m_memoryDump->CreateAllocatorDump(dumpName); | 72 m_memoryDump->CreateAllocatorDump(dumpName); |
72 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes); | 73 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes); |
73 allocatorDump->AddScalar("allocated_objects_size", "bytes", | 74 allocatorDump->AddScalar("allocated_objects_size", "bytes", |
74 memoryStats->totalActiveBytes); | 75 memoryStats->totalActiveBytes); |
75 allocatorDump->AddScalar("virtual_size", "bytes", | 76 allocatorDump->AddScalar("virtual_size", "bytes", |
76 memoryStats->totalMmappedBytes); | 77 memoryStats->totalMmappedBytes); |
77 allocatorDump->AddScalar("virtual_committed_size", "bytes", | 78 allocatorDump->AddScalar("virtual_committed_size", "bytes", |
78 memoryStats->totalCommittedBytes); | 79 memoryStats->totalCommittedBytes); |
79 allocatorDump->AddScalar("decommittable_size", "bytes", | 80 allocatorDump->AddScalar("decommittable_size", "bytes", |
80 memoryStats->totalDecommittableBytes); | 81 memoryStats->totalDecommittableBytes); |
81 allocatorDump->AddScalar("discardable_size", "bytes", | 82 allocatorDump->AddScalar("discardable_size", "bytes", |
82 memoryStats->totalDiscardableBytes); | 83 memoryStats->totalDiscardableBytes); |
83 } | 84 } |
84 | 85 |
85 void PartitionStatsDumperImpl::partitionsDumpBucketStats( | 86 void PartitionStatsDumperImpl::partitionsDumpBucketStats( |
86 const char* partitionName, | 87 const char* partitionName, |
87 const PartitionBucketMemoryStats* memoryStats) { | 88 const WTF::PartitionBucketMemoryStats* memoryStats) { |
88 ASSERT(memoryStats->isValid); | 89 ASSERT(memoryStats->isValid); |
89 std::string dumpName = getPartitionDumpName(partitionName); | 90 std::string dumpName = getPartitionDumpName(partitionName); |
90 if (memoryStats->isDirectMap) | 91 if (memoryStats->isDirectMap) |
91 dumpName.append(base::StringPrintf("/directMap_%lu", ++m_uid)); | 92 dumpName.append(base::StringPrintf("/directMap_%lu", ++m_uid)); |
92 else | 93 else |
93 dumpName.append(base::StringPrintf( | 94 dumpName.append(base::StringPrintf( |
94 "/bucket_%u", static_cast<unsigned>(memoryStats->bucketSlotSize))); | 95 "/bucket_%u", static_cast<unsigned>(memoryStats->bucketSlotSize))); |
95 | 96 |
96 base::trace_event::MemoryAllocatorDump* allocatorDump = | 97 base::trace_event::MemoryAllocatorDump* allocatorDump = |
97 m_memoryDump->CreateAllocatorDump(dumpName); | 98 m_memoryDump->CreateAllocatorDump(dumpName); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 179 |
179 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() {} | 180 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() {} |
180 | 181 |
181 void PartitionAllocMemoryDumpProvider::OnHeapProfilingEnabled(bool enabled) { | 182 void PartitionAllocMemoryDumpProvider::OnHeapProfilingEnabled(bool enabled) { |
182 if (enabled) { | 183 if (enabled) { |
183 { | 184 { |
184 MutexLocker locker(m_allocationRegisterMutex); | 185 MutexLocker locker(m_allocationRegisterMutex); |
185 if (!m_allocationRegister) | 186 if (!m_allocationRegister) |
186 m_allocationRegister.reset(new base::trace_event::AllocationRegister()); | 187 m_allocationRegister.reset(new base::trace_event::AllocationRegister()); |
187 } | 188 } |
188 PartitionAllocHooks::setAllocationHook(reportAllocation); | 189 WTF::PartitionAllocHooks::setAllocationHook(reportAllocation); |
189 PartitionAllocHooks::setFreeHook(reportFree); | 190 WTF::PartitionAllocHooks::setFreeHook(reportFree); |
190 } else { | 191 } else { |
191 PartitionAllocHooks::setAllocationHook(nullptr); | 192 WTF::PartitionAllocHooks::setAllocationHook(nullptr); |
192 PartitionAllocHooks::setFreeHook(nullptr); | 193 WTF::PartitionAllocHooks::setFreeHook(nullptr); |
193 } | 194 } |
194 m_isHeapProfilingEnabled = enabled; | 195 m_isHeapProfilingEnabled = enabled; |
195 } | 196 } |
196 | 197 |
197 void PartitionAllocMemoryDumpProvider::insert(void* address, | 198 void PartitionAllocMemoryDumpProvider::insert(void* address, |
198 size_t size, | 199 size_t size, |
199 const char* typeName) { | 200 const char* typeName) { |
200 base::trace_event::AllocationContext context = | 201 base::trace_event::AllocationContext context = |
201 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() | 202 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() |
202 ->GetContextSnapshot(); | 203 ->GetContextSnapshot(); |
203 context.type_name = typeName; | 204 context.type_name = typeName; |
204 MutexLocker locker(m_allocationRegisterMutex); | 205 MutexLocker locker(m_allocationRegisterMutex); |
205 if (m_allocationRegister) | 206 if (m_allocationRegister) |
206 m_allocationRegister->Insert(address, size, context); | 207 m_allocationRegister->Insert(address, size, context); |
207 } | 208 } |
208 | 209 |
209 void PartitionAllocMemoryDumpProvider::remove(void* address) { | 210 void PartitionAllocMemoryDumpProvider::remove(void* address) { |
210 MutexLocker locker(m_allocationRegisterMutex); | 211 MutexLocker locker(m_allocationRegisterMutex); |
211 if (m_allocationRegister) | 212 if (m_allocationRegister) |
212 m_allocationRegister->Remove(address); | 213 m_allocationRegister->Remove(address); |
213 } | 214 } |
214 | 215 |
215 } // namespace blink | 216 } // namespace blink |
OLD | NEW |