| 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/process_memory_dump.h" | 5 #include "base/trace_event/process_memory_dump.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/process/process_metrics.h" | 12 #include "base/process/process_metrics.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/trace_event/heap_profiler_heap_dump_writer.h" | 14 #include "base/trace_event/heap_profiler_allocation_register.h" |
| 15 #include "base/trace_event/heap_profiler_serialization_state.h" | 15 #include "base/trace_event/heap_profiler_event_writer.h" |
| 16 #include "base/trace_event/memory_infra_background_whitelist.h" | 16 #include "base/trace_event/memory_infra_background_whitelist.h" |
| 17 #include "base/trace_event/process_memory_totals.h" | 17 #include "base/trace_event/process_memory_totals.h" |
| 18 #include "base/trace_event/trace_event_argument.h" | 18 #include "base/trace_event/trace_event_argument.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 | 20 |
| 21 #if defined(OS_IOS) | 21 #if defined(OS_IOS) |
| 22 #include <mach/vm_page_size.h> | 22 #include <mach/vm_page_size.h> |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 #if defined(OS_POSIX) | 25 #if defined(OS_POSIX) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 mad->set_flags(MemoryAllocatorDump::Flags::WEAK); | 240 mad->set_flags(MemoryAllocatorDump::Flags::WEAK); |
| 241 return mad; | 241 return mad; |
| 242 } | 242 } |
| 243 | 243 |
| 244 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( | 244 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( |
| 245 const MemoryAllocatorDumpGuid& guid) const { | 245 const MemoryAllocatorDumpGuid& guid) const { |
| 246 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); | 246 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ProcessMemoryDump::DumpHeapUsage( | 249 void ProcessMemoryDump::DumpHeapUsage( |
| 250 const std::unordered_map<base::trace_event::AllocationContext, | 250 const AllocationRegister& allocation_register, |
| 251 base::trace_event::AllocationMetrics>& | |
| 252 metrics_by_context, | |
| 253 base::trace_event::TraceEventMemoryOverhead& overhead, | |
| 254 const char* allocator_name) { | 251 const char* allocator_name) { |
| 255 if (!metrics_by_context.empty()) { | 252 if (allocation_register.begin() != allocation_register.end()) { |
| 256 // We shouldn't end up here unless we're doing a detailed dump with | 253 // We shouldn't end up here unless we're doing a detailed dump with |
| 257 // heap profiling enabled and if that is the case tracing should be | 254 // heap profiling enabled and if that is the case tracing should be |
| 258 // enabled which sets up the heap profiler serialization state. | 255 // enabled which sets up the heap profiler serialization state. |
| 259 if (!heap_profiler_serialization_state()) { | 256 if (!heap_profiler_serialization_state()) { |
| 260 NOTREACHED(); | 257 NOTREACHED(); |
| 261 return; | 258 return; |
| 262 } | 259 } |
| 263 DCHECK_EQ(0ul, heap_dumps_.count(allocator_name)); | 260 DCHECK_EQ(0ul, heap_dumps_.count(allocator_name)); |
| 264 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( | 261 std::unique_ptr<TracedValue> heap_dump = SerializeHeapDump( |
| 265 metrics_by_context, *heap_profiler_serialization_state()); | 262 allocation_register, *heap_profiler_serialization_state()); |
| 266 heap_dumps_[allocator_name] = std::move(heap_dump); | 263 heap_dumps_[allocator_name] = std::move(heap_dump); |
| 267 } | 264 } |
| 268 | 265 |
| 266 TraceEventMemoryOverhead overhead; |
| 267 allocation_register.EstimateTraceMemoryOverhead(&overhead); |
| 269 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", | 268 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", |
| 270 allocator_name); | 269 allocator_name); |
| 271 overhead.DumpInto(base_name.c_str(), this); | 270 overhead.DumpInto(base_name.c_str(), this); |
| 272 } | 271 } |
| 273 | 272 |
| 274 void ProcessMemoryDump::Clear() { | 273 void ProcessMemoryDump::Clear() { |
| 275 if (has_process_totals_) { | 274 if (has_process_totals_) { |
| 276 process_totals_.Clear(); | 275 process_totals_.Clear(); |
| 277 has_process_totals_ = false; | 276 has_process_totals_ = false; |
| 278 } | 277 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 322 } |
| 324 | 323 |
| 325 if (allocator_dumps_.size() > 0) { | 324 if (allocator_dumps_.size() > 0) { |
| 326 value->BeginDictionary("allocators"); | 325 value->BeginDictionary("allocators"); |
| 327 for (const auto& allocator_dump_it : allocator_dumps_) | 326 for (const auto& allocator_dump_it : allocator_dumps_) |
| 328 allocator_dump_it.second->AsValueInto(value); | 327 allocator_dump_it.second->AsValueInto(value); |
| 329 value->EndDictionary(); | 328 value->EndDictionary(); |
| 330 } | 329 } |
| 331 | 330 |
| 332 if (heap_dumps_.size() > 0) { | 331 if (heap_dumps_.size() > 0) { |
| 333 value->BeginDictionary("heaps"); | 332 auto profile_data = SerializeHeapProfileEventData( |
| 334 for (const auto& name_and_dump : heap_dumps_) | 333 heap_dumps_, *heap_profiler_serialization_state_); |
| 335 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); | 334 value->SetValue("heaps_v2", *profile_data); |
| 336 value->EndDictionary(); // "heaps" | |
| 337 } | 335 } |
| 338 | 336 |
| 339 value->BeginArray("allocators_graph"); | 337 value->BeginArray("allocators_graph"); |
| 340 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { | 338 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { |
| 341 value->BeginDictionary(); | 339 value->BeginDictionary(); |
| 342 value->SetString("source", edge.source.ToString()); | 340 value->SetString("source", edge.source.ToString()); |
| 343 value->SetString("target", edge.target.ToString()); | 341 value->SetString("target", edge.target.ToString()); |
| 344 value->SetInteger("importance", edge.importance); | 342 value->SetInteger("importance", edge.importance); |
| 345 value->SetString("type", edge.type); | 343 value->SetString("type", edge.type); |
| 346 value->EndDictionary(); | 344 value->EndDictionary(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 374 | 372 |
| 375 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 373 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
| 376 DCHECK(is_black_hole_non_fatal_for_testing_); | 374 DCHECK(is_black_hole_non_fatal_for_testing_); |
| 377 if (!black_hole_mad_) | 375 if (!black_hole_mad_) |
| 378 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 376 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
| 379 return black_hole_mad_.get(); | 377 return black_hole_mad_.get(); |
| 380 } | 378 } |
| 381 | 379 |
| 382 } // namespace trace_event | 380 } // namespace trace_event |
| 383 } // namespace base | 381 } // namespace base |
| OLD | NEW |