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/trace_event/heap_profiler_allocation_context.h" | 7 #include "base/trace_event/heap_profiler_allocation_context.h" |
8 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 8 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
9 #include "base/trace_event/heap_profiler_allocation_register.h" | 9 #include "base/trace_event/heap_profiler_allocation_register.h" |
10 #include "base/trace_event/process_memory_dump.h" | 10 #include "base/trace_event/process_memory_dump.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics. | 130 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics. |
131 WTF::Partitions::dumpMemoryStats(levelOfDetail == WebMemoryDumpLevelOfDetail ::Light, &partitionStatsDumper); | 131 WTF::Partitions::dumpMemoryStats(levelOfDetail == WebMemoryDumpLevelOfDetail ::Light, &partitionStatsDumper); |
132 | 132 |
133 WebMemoryAllocatorDump* allocatedObjectsDump = memoryDump->createMemoryAlloc atorDump(String(Partitions::kAllocatedObjectPoolName)); | 133 WebMemoryAllocatorDump* allocatedObjectsDump = memoryDump->createMemoryAlloc atorDump(String(Partitions::kAllocatedObjectPoolName)); |
134 allocatedObjectsDump->addScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes()); | 134 allocatedObjectsDump->addScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes()); |
135 memoryDump->addOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid()); | 135 memoryDump->addOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid()); |
136 | 136 |
137 return true; | 137 return true; |
138 } | 138 } |
139 | 139 |
140 // |m_allocationRegister| should be initialized only when necessary to avoid was te of memory. | |
140 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() | 141 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() |
141 : m_allocationRegister(adoptPtr(new base::trace_event::AllocationRegister()) ) | 142 : m_allocationRegister(nullptr) |
142 , m_isHeapProfilingEnabled(false) | 143 , m_isHeapProfilingEnabled(false) |
143 { | 144 { |
144 } | 145 } |
145 | 146 |
146 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() | 147 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() |
147 { | 148 { |
148 } | 149 } |
149 | 150 |
150 void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) | 151 void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) |
151 { | 152 { |
152 if (enabled) { | 153 if (enabled) { |
154 { | |
155 MutexLocker locker(m_allocationRegisterMutex); | |
156 if (!m_allocationRegister) | |
157 m_allocationRegister = adoptPtr(new base::trace_event::Allocatio nRegister()); | |
158 } | |
153 PartitionAllocHooks::setAllocationHook(reportAllocation); | 159 PartitionAllocHooks::setAllocationHook(reportAllocation); |
154 PartitionAllocHooks::setFreeHook(reportFree); | 160 PartitionAllocHooks::setFreeHook(reportFree); |
155 } else { | 161 } else { |
156 PartitionAllocHooks::setAllocationHook(nullptr); | 162 PartitionAllocHooks::setAllocationHook(nullptr); |
157 PartitionAllocHooks::setFreeHook(nullptr); | 163 PartitionAllocHooks::setFreeHook(nullptr); |
esprehn
2016/02/09 07:07:13
should we clear m_allocationRegister here? What ev
Primiano Tucci (use gerrit)
2016/02/09 11:00:24
That's a good point, missed it.
So, right now ther
| |
158 } | 164 } |
159 m_isHeapProfilingEnabled = enabled; | 165 m_isHeapProfilingEnabled = enabled; |
160 } | 166 } |
161 | 167 |
162 void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const char* typeName) | 168 void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const char* typeName) |
163 { | 169 { |
164 base::trace_event::AllocationContext context = base::trace_event::Allocation ContextTracker::GetContextSnapshot(); | 170 base::trace_event::AllocationContext context = base::trace_event::Allocation ContextTracker::GetContextSnapshot(); |
165 context.type_name = typeName; | 171 context.type_name = typeName; |
166 MutexLocker locker(m_allocationRegisterMutex); | 172 MutexLocker locker(m_allocationRegisterMutex); |
haraken
2016/02/05 11:20:59
Nit: It would be heavy to use MutexLocker in inser
Primiano Tucci (use gerrit)
2016/02/05 11:42:08
Note that here we have also to protect against con
| |
167 m_allocationRegister->Insert(address, size, context); | 173 if (m_allocationRegister) |
174 m_allocationRegister->Insert(address, size, context); | |
168 } | 175 } |
169 | 176 |
170 void PartitionAllocMemoryDumpProvider::remove(void* address) | 177 void PartitionAllocMemoryDumpProvider::remove(void* address) |
171 { | 178 { |
172 MutexLocker locker(m_allocationRegisterMutex); | 179 MutexLocker locker(m_allocationRegisterMutex); |
173 m_allocationRegister->Remove(address); | 180 if (m_allocationRegister) |
181 m_allocationRegister->Remove(address); | |
174 } | 182 } |
175 | 183 |
176 } // namespace blink | 184 } // namespace blink |
OLD | NEW |