| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() | 141 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() |
| 142 : m_allocationRegister(nullptr) | 142 : m_allocationRegister(nullptr) |
| 143 , m_isHeapProfilingEnabled(false) | 143 , m_isHeapProfilingEnabled(false) |
| 144 { | 144 { |
| 145 } | 145 } |
| 146 | 146 |
| 147 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() | 147 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() |
| 148 { | 148 { |
| 149 } | 149 } |
| 150 | 150 |
| 151 void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled(bool enabled) | 151 void PartitionAllocMemoryDumpProvider::onHeapProfilingEnabled() |
| 152 { | 152 { |
| 153 if (enabled) { | 153 ASSERT(!m_isHeapProfilingEnabled); |
| 154 { | 154 { |
| 155 MutexLocker locker(m_allocationRegisterMutex); | 155 MutexLocker locker(m_allocationRegisterMutex); |
| 156 if (!m_allocationRegister) | 156 if (!m_allocationRegister) |
| 157 m_allocationRegister = adoptPtr(new base::trace_event::Allocatio
nRegister()); | 157 m_allocationRegister = adoptPtr(new base::trace_event::AllocationReg
ister()); |
| 158 } | |
| 159 PartitionAllocHooks::setAllocationHook(reportAllocation); | |
| 160 PartitionAllocHooks::setFreeHook(reportFree); | |
| 161 } else { | |
| 162 PartitionAllocHooks::setAllocationHook(nullptr); | |
| 163 PartitionAllocHooks::setFreeHook(nullptr); | |
| 164 } | 158 } |
| 165 m_isHeapProfilingEnabled = enabled; | 159 PartitionAllocHooks::setAllocationHook(reportAllocation); |
| 160 PartitionAllocHooks::setFreeHook(reportFree); |
| 161 m_isHeapProfilingEnabled = true; |
| 166 } | 162 } |
| 167 | 163 |
| 168 void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const
char* typeName) | 164 void PartitionAllocMemoryDumpProvider::insert(void* address, size_t size, const
char* typeName) |
| 169 { | 165 { |
| 170 base::trace_event::AllocationContext context = base::trace_event::Allocation
ContextTracker::GetContextSnapshot(); | 166 base::trace_event::AllocationContext context = base::trace_event::Allocation
ContextTracker::GetContextSnapshot(); |
| 171 context.type_name = typeName; | 167 context.type_name = typeName; |
| 172 MutexLocker locker(m_allocationRegisterMutex); | 168 MutexLocker locker(m_allocationRegisterMutex); |
| 173 if (m_allocationRegister) | 169 if (m_allocationRegister) |
| 174 m_allocationRegister->Insert(address, size, context); | 170 m_allocationRegister->Insert(address, size, context); |
| 175 } | 171 } |
| 176 | 172 |
| 177 void PartitionAllocMemoryDumpProvider::remove(void* address) | 173 void PartitionAllocMemoryDumpProvider::remove(void* address) |
| 178 { | 174 { |
| 179 MutexLocker locker(m_allocationRegisterMutex); | 175 MutexLocker locker(m_allocationRegisterMutex); |
| 180 if (m_allocationRegister) | 176 if (m_allocationRegister) |
| 181 m_allocationRegister->Remove(address); | 177 m_allocationRegister->Remove(address); |
| 182 } | 178 } |
| 183 | 179 |
| 184 } // namespace blink | 180 } // namespace blink |
| OLD | NEW |