| 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_event_writer.h" |
| 15 #include "base/trace_event/memory_infra_background_whitelist.h" | 16 #include "base/trace_event/memory_infra_background_whitelist.h" |
| 16 #include "base/trace_event/process_memory_totals.h" | 17 #include "base/trace_event/process_memory_totals.h" |
| 17 #include "base/trace_event/trace_event_argument.h" | 18 #include "base/trace_event/trace_event_argument.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 | 20 |
| 20 #if defined(OS_IOS) | 21 #if defined(OS_IOS) |
| 21 #include <mach/vm_page_size.h> | 22 #include <mach/vm_page_size.h> |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 #if defined(OS_POSIX) | 25 #if defined(OS_POSIX) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 mad->set_flags(MemoryAllocatorDump::Flags::WEAK); | 233 mad->set_flags(MemoryAllocatorDump::Flags::WEAK); |
| 233 return mad; | 234 return mad; |
| 234 } | 235 } |
| 235 | 236 |
| 236 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( | 237 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( |
| 237 const MemoryAllocatorDumpGuid& guid) const { | 238 const MemoryAllocatorDumpGuid& guid) const { |
| 238 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); | 239 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); |
| 239 } | 240 } |
| 240 | 241 |
| 241 void ProcessMemoryDump::DumpHeapUsage( | 242 void ProcessMemoryDump::DumpHeapUsage( |
| 242 const base::hash_map<base::trace_event::AllocationContext, | 243 const AllocationRegister& allocation_register, |
| 243 base::trace_event::AllocationMetrics>& metrics_by_context, | |
| 244 base::trace_event::TraceEventMemoryOverhead& overhead, | |
| 245 const char* allocator_name) { | 244 const char* allocator_name) { |
| 246 if (!metrics_by_context.empty()) { | 245 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::DETAILED && |
| 246 allocation_register.begin() != allocation_register.end()) { |
| 247 DCHECK_EQ(0ul, heap_dumps_.count(allocator_name)); | 247 DCHECK_EQ(0ul, heap_dumps_.count(allocator_name)); |
| 248 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( | 248 std::unique_ptr<TracedValue> heap_dump = |
| 249 metrics_by_context, *session_state()); | 249 SerializeHeapDump(allocation_register, *session_state()); |
| 250 heap_dumps_[allocator_name] = std::move(heap_dump); | 250 heap_dumps_[allocator_name] = std::move(heap_dump); |
| 251 } | 251 } |
| 252 | 252 |
| 253 TraceEventMemoryOverhead overhead; |
| 254 allocation_register.EstimateTraceMemoryOverhead(&overhead); |
| 253 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", | 255 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", |
| 254 allocator_name); | 256 allocator_name); |
| 255 overhead.DumpInto(base_name.c_str(), this); | 257 overhead.DumpInto(base_name.c_str(), this); |
| 256 } | 258 } |
| 257 | 259 |
| 258 void ProcessMemoryDump::Clear() { | 260 void ProcessMemoryDump::Clear() { |
| 259 if (has_process_totals_) { | 261 if (has_process_totals_) { |
| 260 process_totals_.Clear(); | 262 process_totals_.Clear(); |
| 261 has_process_totals_ = false; | 263 has_process_totals_ = false; |
| 262 } | 264 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 309 } |
| 308 | 310 |
| 309 if (allocator_dumps_.size() > 0) { | 311 if (allocator_dumps_.size() > 0) { |
| 310 value->BeginDictionary("allocators"); | 312 value->BeginDictionary("allocators"); |
| 311 for (const auto& allocator_dump_it : allocator_dumps_) | 313 for (const auto& allocator_dump_it : allocator_dumps_) |
| 312 allocator_dump_it.second->AsValueInto(value); | 314 allocator_dump_it.second->AsValueInto(value); |
| 313 value->EndDictionary(); | 315 value->EndDictionary(); |
| 314 } | 316 } |
| 315 | 317 |
| 316 if (heap_dumps_.size() > 0) { | 318 if (heap_dumps_.size() > 0) { |
| 317 value->BeginDictionary("heaps"); | 319 auto profile_data = |
| 318 for (const auto& name_and_dump : heap_dumps_) | 320 SerializeHeapProfileEventData(heap_dumps_, *session_state_); |
| 319 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); | 321 value->SetValue("heaps_v2", *profile_data); |
| 320 value->EndDictionary(); // "heaps" | |
| 321 } | 322 } |
| 322 | 323 |
| 323 value->BeginArray("allocators_graph"); | 324 value->BeginArray("allocators_graph"); |
| 324 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { | 325 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { |
| 325 value->BeginDictionary(); | 326 value->BeginDictionary(); |
| 326 value->SetString("source", edge.source.ToString()); | 327 value->SetString("source", edge.source.ToString()); |
| 327 value->SetString("target", edge.target.ToString()); | 328 value->SetString("target", edge.target.ToString()); |
| 328 value->SetInteger("importance", edge.importance); | 329 value->SetInteger("importance", edge.importance); |
| 329 value->SetString("type", edge.type); | 330 value->SetString("type", edge.type); |
| 330 value->EndDictionary(); | 331 value->EndDictionary(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 358 | 359 |
| 359 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 360 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
| 360 DCHECK(is_black_hole_non_fatal_for_testing_); | 361 DCHECK(is_black_hole_non_fatal_for_testing_); |
| 361 if (!black_hole_mad_) | 362 if (!black_hole_mad_) |
| 362 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 363 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
| 363 return black_hole_mad_.get(); | 364 return black_hole_mad_.get(); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace trace_event | 367 } // namespace trace_event |
| 367 } // namespace base | 368 } // namespace base |
| OLD | NEW |