Chromium Code Reviews| 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 "base/trace_event/malloc_dump_provider.h" | 5 #include "base/trace_event/malloc_dump_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
| 10 #include "base/allocator/allocator_shim.h" | 10 #include "base/allocator/allocator_shim.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. | 171 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. |
| 172 // However, when enabled, the overhead of the heap profiler should be always | 172 // However, when enabled, the overhead of the heap profiler should be always |
| 173 // reported to avoid oscillations of the malloc total in LIGHT dumps. | 173 // reported to avoid oscillations of the malloc total in LIGHT dumps. |
| 174 | 174 |
| 175 tid_dumping_heap_ = PlatformThread::CurrentId(); | 175 tid_dumping_heap_ = PlatformThread::CurrentId(); |
| 176 // At this point the Insert/RemoveAllocation hooks will ignore this thread. | 176 // At this point the Insert/RemoveAllocation hooks will ignore this thread. |
| 177 // Enclosing all the temporariy data structures in a scope, so that the heap | 177 // Enclosing all the temporariy data structures in a scope, so that the heap |
| 178 // profiler does not see unabalanced malloc/free calls from these containers. | 178 // profiler does not see unabalanced malloc/free calls from these containers. |
| 179 { | 179 { |
| 180 TraceEventMemoryOverhead overhead; | 180 TraceEventMemoryOverhead overhead; |
| 181 hash_map<AllocationContext, size_t> bytes_by_context; | 181 hash_map<AllocationContext, AllocationsSizeAndCount> metrics_by_context; |
| 182 { | 182 { |
| 183 AutoLock lock(allocation_register_lock_); | 183 AutoLock lock(allocation_register_lock_); |
| 184 if (allocation_register_) { | 184 if (allocation_register_) { |
| 185 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { | 185 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { |
| 186 for (const auto& alloc_size : *allocation_register_) | 186 for (const auto& alloc_size : *allocation_register_) { |
| 187 bytes_by_context[alloc_size.context] += alloc_size.size; | 187 metrics_by_context[alloc_size.context].size += alloc_size.size; |
| 188 metrics_by_context[alloc_size.context].count++; | |
|
Dmitry Skiba
2016/04/14 19:07:30
Let's avoid second lookup by caching result from t
Primiano Tucci (use gerrit)
2016/04/14 19:37:21
+1. Good suggestion ;-)
ssid
2016/04/14 20:17:10
Done.
| |
| 189 } | |
| 188 } | 190 } |
| 189 allocation_register_->EstimateTraceMemoryOverhead(&overhead); | 191 allocation_register_->EstimateTraceMemoryOverhead(&overhead); |
| 190 } | 192 } |
| 191 } // lock(allocation_register_lock_) | 193 } // lock(allocation_register_lock_) |
| 192 | 194 |
| 193 if (!bytes_by_context.empty()) { | 195 if (!metrics_by_context.empty()) { |
| 194 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( | 196 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( |
| 195 bytes_by_context, pmd->session_state()->stack_frame_deduplicator(), | 197 metrics_by_context, pmd->session_state()->stack_frame_deduplicator(), |
| 196 pmd->session_state()->type_name_deduplicator()); | 198 pmd->session_state()->type_name_deduplicator()); |
| 197 pmd->AddHeapDump("malloc", std::move(heap_dump)); | 199 pmd->AddHeapDump("malloc", std::move(heap_dump)); |
| 198 } | 200 } |
| 199 overhead.DumpInto("tracing/heap_profiler_malloc", pmd); | 201 overhead.DumpInto("tracing/heap_profiler_malloc", pmd); |
| 200 } | 202 } |
| 201 tid_dumping_heap_ = kInvalidThreadId; | 203 tid_dumping_heap_ = kInvalidThreadId; |
| 202 | 204 |
| 203 return true; | 205 return true; |
| 204 } | 206 } |
| 205 | 207 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 tid_dumping_heap_ == PlatformThread::CurrentId()) | 254 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 253 return; | 255 return; |
| 254 AutoLock lock(allocation_register_lock_); | 256 AutoLock lock(allocation_register_lock_); |
| 255 if (!allocation_register_) | 257 if (!allocation_register_) |
| 256 return; | 258 return; |
| 257 allocation_register_->Remove(address); | 259 allocation_register_->Remove(address); |
| 258 } | 260 } |
| 259 | 261 |
| 260 } // namespace trace_event | 262 } // namespace trace_event |
| 261 } // namespace base | 263 } // namespace base |
| OLD | NEW |