| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 WTF::PartitionMemoryStats*) override; | 53 const WTF::PartitionMemoryStats*) override; |
| 54 void partitionsDumpBucketStats( | 54 void PartitionsDumpBucketStats( |
| 55 const char* partitionName, | 55 const char* partitionName, |
| 56 const WTF::PartitionBucketMemoryStats*) override; | 56 const WTF::PartitionBucketMemoryStats*) override; |
| 57 | 57 |
| 58 size_t totalActiveBytes() const { return m_totalActiveBytes; } | 58 size_t TotalActiveBytes() const { return m_totalActiveBytes; } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 base::trace_event::ProcessMemoryDump* m_memoryDump; | 61 base::trace_event::ProcessMemoryDump* m_memoryDump; |
| 62 unsigned long m_uid; | 62 unsigned long m_uid; |
| 63 size_t m_totalActiveBytes; | 63 size_t m_totalActiveBytes; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 void PartitionStatsDumperImpl::partitionDumpTotals( | 66 void PartitionStatsDumperImpl::PartitionDumpTotals( |
| 67 const char* partitionName, | 67 const char* partitionName, |
| 68 const WTF::PartitionMemoryStats* memoryStats) { | 68 const WTF::PartitionMemoryStats* memoryStats) { |
| 69 m_totalActiveBytes += memoryStats->totalActiveBytes; | 69 m_totalActiveBytes += memoryStats->total_active_bytes; |
| 70 std::string dumpName = getPartitionDumpName(partitionName); | 70 std::string dumpName = getPartitionDumpName(partitionName); |
| 71 base::trace_event::MemoryAllocatorDump* allocatorDump = | 71 base::trace_event::MemoryAllocatorDump* allocatorDump = |
| 72 m_memoryDump->CreateAllocatorDump(dumpName); | 72 m_memoryDump->CreateAllocatorDump(dumpName); |
| 73 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes); | 73 allocatorDump->AddScalar("size", "bytes", memoryStats->total_resident_bytes); |
| 74 allocatorDump->AddScalar("allocated_objects_size", "bytes", | 74 allocatorDump->AddScalar("allocated_objects_size", "bytes", |
| 75 memoryStats->totalActiveBytes); | 75 memoryStats->total_active_bytes); |
| 76 allocatorDump->AddScalar("virtual_size", "bytes", | 76 allocatorDump->AddScalar("virtual_size", "bytes", |
| 77 memoryStats->totalMmappedBytes); | 77 memoryStats->total_mmapped_bytes); |
| 78 allocatorDump->AddScalar("virtual_committed_size", "bytes", | 78 allocatorDump->AddScalar("virtual_committed_size", "bytes", |
| 79 memoryStats->totalCommittedBytes); | 79 memoryStats->total_committed_bytes); |
| 80 allocatorDump->AddScalar("decommittable_size", "bytes", | 80 allocatorDump->AddScalar("decommittable_size", "bytes", |
| 81 memoryStats->totalDecommittableBytes); | 81 memoryStats->total_decommittable_bytes); |
| 82 allocatorDump->AddScalar("discardable_size", "bytes", | 82 allocatorDump->AddScalar("discardable_size", "bytes", |
| 83 memoryStats->totalDiscardableBytes); | 83 memoryStats->total_discardable_bytes); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void PartitionStatsDumperImpl::partitionsDumpBucketStats( | 86 void PartitionStatsDumperImpl::PartitionsDumpBucketStats( |
| 87 const char* partitionName, | 87 const char* partitionName, |
| 88 const WTF::PartitionBucketMemoryStats* memoryStats) { | 88 const WTF::PartitionBucketMemoryStats* memoryStats) { |
| 89 ASSERT(memoryStats->isValid); | 89 DCHECK(memoryStats->is_valid); |
| 90 std::string dumpName = getPartitionDumpName(partitionName); | 90 std::string dumpName = getPartitionDumpName(partitionName); |
| 91 if (memoryStats->isDirectMap) | 91 if (memoryStats->is_direct_map) { |
| 92 dumpName.append(base::StringPrintf("/directMap_%lu", ++m_uid)); | 92 dumpName.append(base::StringPrintf("/directMap_%lu", ++m_uid)); |
| 93 else | 93 } else { |
| 94 dumpName.append(base::StringPrintf( | 94 dumpName.append(base::StringPrintf( |
| 95 "/bucket_%u", static_cast<unsigned>(memoryStats->bucketSlotSize))); | 95 "/bucket_%u", static_cast<unsigned>(memoryStats->bucket_slot_size))); |
| 96 } |
| 96 | 97 |
| 97 base::trace_event::MemoryAllocatorDump* allocatorDump = | 98 base::trace_event::MemoryAllocatorDump* allocatorDump = |
| 98 m_memoryDump->CreateAllocatorDump(dumpName); | 99 m_memoryDump->CreateAllocatorDump(dumpName); |
| 99 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes); | 100 allocatorDump->AddScalar("size", "bytes", memoryStats->resident_bytes); |
| 100 allocatorDump->AddScalar("allocated_objects_size", "bytes", | 101 allocatorDump->AddScalar("allocated_objects_size", "bytes", |
| 101 memoryStats->activeBytes); | 102 memoryStats->active_bytes); |
| 102 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize); | 103 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucket_slot_size); |
| 103 allocatorDump->AddScalar("decommittable_size", "bytes", | 104 allocatorDump->AddScalar("decommittable_size", "bytes", |
| 104 memoryStats->decommittableBytes); | 105 memoryStats->decommittable_bytes); |
| 105 allocatorDump->AddScalar("discardable_size", "bytes", | 106 allocatorDump->AddScalar("discardable_size", "bytes", |
| 106 memoryStats->discardableBytes); | 107 memoryStats->discardable_bytes); |
| 107 allocatorDump->AddScalar("total_pages_size", "bytes", | 108 allocatorDump->AddScalar("total_pages_size", "bytes", |
| 108 memoryStats->allocatedPageSize); | 109 memoryStats->allocated_page_size); |
| 109 allocatorDump->AddScalar("active_pages", "objects", | 110 allocatorDump->AddScalar("active_pages", "objects", |
| 110 memoryStats->numActivePages); | 111 memoryStats->num_active_pages); |
| 111 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages); | 112 allocatorDump->AddScalar("full_pages", "objects", |
| 113 memoryStats->num_full_pages); |
| 112 allocatorDump->AddScalar("empty_pages", "objects", | 114 allocatorDump->AddScalar("empty_pages", "objects", |
| 113 memoryStats->numEmptyPages); | 115 memoryStats->num_empty_pages); |
| 114 allocatorDump->AddScalar("decommitted_pages", "objects", | 116 allocatorDump->AddScalar("decommitted_pages", "objects", |
| 115 memoryStats->numDecommittedPages); | 117 memoryStats->num_decommitted_pages); |
| 116 } | 118 } |
| 117 | 119 |
| 118 } // namespace | 120 } // namespace |
| 119 | 121 |
| 120 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance() { | 122 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance() { |
| 121 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ()); | 123 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ()); |
| 122 return &instance; | 124 return &instance; |
| 123 } | 125 } |
| 124 | 126 |
| 125 bool PartitionAllocMemoryDumpProvider::OnMemoryDump( | 127 bool PartitionAllocMemoryDumpProvider::OnMemoryDump( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 160 |
| 159 // This method calls memoryStats.partitionsDumpBucketStats with memory | 161 // This method calls memoryStats.partitionsDumpBucketStats with memory |
| 160 // statistics. | 162 // statistics. |
| 161 WTF::Partitions::dumpMemoryStats( | 163 WTF::Partitions::dumpMemoryStats( |
| 162 levelOfDetail != MemoryDumpLevelOfDetail::DETAILED, | 164 levelOfDetail != MemoryDumpLevelOfDetail::DETAILED, |
| 163 &partitionStatsDumper); | 165 &partitionStatsDumper); |
| 164 | 166 |
| 165 base::trace_event::MemoryAllocatorDump* allocatedObjectsDump = | 167 base::trace_event::MemoryAllocatorDump* allocatedObjectsDump = |
| 166 memoryDump->CreateAllocatorDump(Partitions::kAllocatedObjectPoolName); | 168 memoryDump->CreateAllocatorDump(Partitions::kAllocatedObjectPoolName); |
| 167 allocatedObjectsDump->AddScalar("size", "bytes", | 169 allocatedObjectsDump->AddScalar("size", "bytes", |
| 168 partitionStatsDumper.totalActiveBytes()); | 170 partitionStatsDumper.TotalActiveBytes()); |
| 169 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), | 171 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), |
| 170 partitionsDump->guid()); | 172 partitionsDump->guid()); |
| 171 | 173 |
| 172 return true; | 174 return true; |
| 173 } | 175 } |
| 174 | 176 |
| 175 // |m_allocationRegister| should be initialized only when necessary to avoid | 177 // |m_allocationRegister| should be initialized only when necessary to avoid |
| 176 // waste of memory. | 178 // waste of memory. |
| 177 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() | 179 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() |
| 178 : m_allocationRegister(nullptr), m_isHeapProfilingEnabled(false) {} | 180 : m_allocationRegister(nullptr), m_isHeapProfilingEnabled(false) {} |
| 179 | 181 |
| 180 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() {} | 182 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() {} |
| 181 | 183 |
| 182 void PartitionAllocMemoryDumpProvider::OnHeapProfilingEnabled(bool enabled) { | 184 void PartitionAllocMemoryDumpProvider::OnHeapProfilingEnabled(bool enabled) { |
| 183 if (enabled) { | 185 if (enabled) { |
| 184 { | 186 { |
| 185 MutexLocker locker(m_allocationRegisterMutex); | 187 MutexLocker locker(m_allocationRegisterMutex); |
| 186 if (!m_allocationRegister) | 188 if (!m_allocationRegister) |
| 187 m_allocationRegister.reset(new base::trace_event::AllocationRegister()); | 189 m_allocationRegister.reset(new base::trace_event::AllocationRegister()); |
| 188 } | 190 } |
| 189 WTF::PartitionAllocHooks::setAllocationHook(reportAllocation); | 191 WTF::PartitionAllocHooks::SetAllocationHook(reportAllocation); |
| 190 WTF::PartitionAllocHooks::setFreeHook(reportFree); | 192 WTF::PartitionAllocHooks::SetFreeHook(reportFree); |
| 191 } else { | 193 } else { |
| 192 WTF::PartitionAllocHooks::setAllocationHook(nullptr); | 194 WTF::PartitionAllocHooks::SetAllocationHook(nullptr); |
| 193 WTF::PartitionAllocHooks::setFreeHook(nullptr); | 195 WTF::PartitionAllocHooks::SetFreeHook(nullptr); |
| 194 } | 196 } |
| 195 m_isHeapProfilingEnabled = enabled; | 197 m_isHeapProfilingEnabled = enabled; |
| 196 } | 198 } |
| 197 | 199 |
| 198 void PartitionAllocMemoryDumpProvider::insert(void* address, | 200 void PartitionAllocMemoryDumpProvider::insert(void* address, |
| 199 size_t size, | 201 size_t size, |
| 200 const char* typeName) { | 202 const char* typeName) { |
| 201 base::trace_event::AllocationContext context = | 203 base::trace_event::AllocationContext context = |
| 202 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() | 204 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() |
| 203 ->GetContextSnapshot(); | 205 ->GetContextSnapshot(); |
| 204 context.type_name = typeName; | 206 context.type_name = typeName; |
| 205 MutexLocker locker(m_allocationRegisterMutex); | 207 MutexLocker locker(m_allocationRegisterMutex); |
| 206 if (m_allocationRegister) | 208 if (m_allocationRegister) |
| 207 m_allocationRegister->Insert(address, size, context); | 209 m_allocationRegister->Insert(address, size, context); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void PartitionAllocMemoryDumpProvider::remove(void* address) { | 212 void PartitionAllocMemoryDumpProvider::remove(void* address) { |
| 211 MutexLocker locker(m_allocationRegisterMutex); | 213 MutexLocker locker(m_allocationRegisterMutex); |
| 212 if (m_allocationRegister) | 214 if (m_allocationRegister) |
| 213 m_allocationRegister->Remove(address); | 215 m_allocationRegister->Remove(address); |
| 214 } | 216 } |
| 215 | 217 |
| 216 } // namespace blink | 218 } // namespace blink |
| OLD | NEW |