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