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_heap_dump_writer.h" |
| 15 #include "base/trace_event/heap_profiler_serialization_state.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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 DCHECK(!failure); | 145 DCHECK(!failure); |
145 if (failure) { | 146 if (failure) { |
146 total_resident_size = 0; | 147 total_resident_size = 0; |
147 LOG(ERROR) << "CountResidentBytes failed. The resident size is invalid"; | 148 LOG(ERROR) << "CountResidentBytes failed. The resident size is invalid"; |
148 } | 149 } |
149 return total_resident_size; | 150 return total_resident_size; |
150 } | 151 } |
151 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 152 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
152 | 153 |
153 ProcessMemoryDump::ProcessMemoryDump( | 154 ProcessMemoryDump::ProcessMemoryDump( |
154 scoped_refptr<MemoryDumpSessionState> session_state, | 155 scoped_refptr<HeapProfilerSerializationState> |
| 156 heap_profiler_serialization_state, |
155 const MemoryDumpArgs& dump_args) | 157 const MemoryDumpArgs& dump_args) |
156 : has_process_totals_(false), | 158 : has_process_totals_(false), |
157 has_process_mmaps_(false), | 159 has_process_mmaps_(false), |
158 session_state_(std::move(session_state)), | 160 heap_profiler_serialization_state_( |
| 161 std::move(heap_profiler_serialization_state)), |
159 dump_args_(dump_args) {} | 162 dump_args_(dump_args) {} |
160 | 163 |
161 ProcessMemoryDump::~ProcessMemoryDump() {} | 164 ProcessMemoryDump::~ProcessMemoryDump() {} |
162 | 165 |
163 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( | 166 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( |
164 const std::string& absolute_name) { | 167 const std::string& absolute_name) { |
165 return AddAllocatorDumpInternal( | 168 return AddAllocatorDumpInternal( |
166 MakeUnique<MemoryAllocatorDump>(absolute_name, this)); | 169 MakeUnique<MemoryAllocatorDump>(absolute_name, this)); |
167 } | 170 } |
168 | 171 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 248 |
246 void ProcessMemoryDump::DumpHeapUsage( | 249 void ProcessMemoryDump::DumpHeapUsage( |
247 const std::unordered_map<base::trace_event::AllocationContext, | 250 const std::unordered_map<base::trace_event::AllocationContext, |
248 base::trace_event::AllocationMetrics>& | 251 base::trace_event::AllocationMetrics>& |
249 metrics_by_context, | 252 metrics_by_context, |
250 base::trace_event::TraceEventMemoryOverhead& overhead, | 253 base::trace_event::TraceEventMemoryOverhead& overhead, |
251 const char* allocator_name) { | 254 const char* allocator_name) { |
252 if (!metrics_by_context.empty()) { | 255 if (!metrics_by_context.empty()) { |
253 DCHECK_EQ(0ul, heap_dumps_.count(allocator_name)); | 256 DCHECK_EQ(0ul, heap_dumps_.count(allocator_name)); |
254 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( | 257 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( |
255 metrics_by_context, *session_state()); | 258 metrics_by_context, *heap_profiler_serialization_state()); |
256 heap_dumps_[allocator_name] = std::move(heap_dump); | 259 heap_dumps_[allocator_name] = std::move(heap_dump); |
257 } | 260 } |
258 | 261 |
259 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", | 262 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", |
260 allocator_name); | 263 allocator_name); |
261 overhead.DumpInto(base_name.c_str(), this); | 264 overhead.DumpInto(base_name.c_str(), this); |
262 } | 265 } |
263 | 266 |
264 void ProcessMemoryDump::Clear() { | 267 void ProcessMemoryDump::Clear() { |
265 if (has_process_totals_) { | 268 if (has_process_totals_) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 367 |
365 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 368 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
366 DCHECK(is_black_hole_non_fatal_for_testing_); | 369 DCHECK(is_black_hole_non_fatal_for_testing_); |
367 if (!black_hole_mad_) | 370 if (!black_hole_mad_) |
368 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 371 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
369 return black_hole_mad_.get(); | 372 return black_hole_mad_.get(); |
370 } | 373 } |
371 | 374 |
372 } // namespace trace_event | 375 } // namespace trace_event |
373 } // namespace base | 376 } // namespace base |
OLD | NEW |