| 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" |
| 14 #include "base/trace_event/heap_profiler_heap_dump_writer.h" |
| 13 #include "base/trace_event/process_memory_totals.h" | 15 #include "base/trace_event/process_memory_totals.h" |
| 14 #include "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 16 | 18 |
| 17 #if defined(OS_IOS) | 19 #if defined(OS_IOS) |
| 18 #include <sys/sysctl.h> | 20 #include <sys/sysctl.h> |
| 19 #endif | 21 #endif |
| 20 | 22 |
| 21 #if defined(OS_POSIX) | 23 #if defined(OS_POSIX) |
| 22 #include <sys/mman.h> | 24 #include <sys/mman.h> |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const MemoryAllocatorDumpGuid& guid) const { | 216 const MemoryAllocatorDumpGuid& guid) const { |
| 215 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); | 217 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void ProcessMemoryDump::AddHeapDump(const std::string& absolute_name, | 220 void ProcessMemoryDump::AddHeapDump(const std::string& absolute_name, |
| 219 std::unique_ptr<TracedValue> heap_dump) { | 221 std::unique_ptr<TracedValue> heap_dump) { |
| 220 DCHECK_EQ(0ul, heap_dumps_.count(absolute_name)); | 222 DCHECK_EQ(0ul, heap_dumps_.count(absolute_name)); |
| 221 heap_dumps_[absolute_name] = std::move(heap_dump); | 223 heap_dumps_[absolute_name] = std::move(heap_dump); |
| 222 } | 224 } |
| 223 | 225 |
| 226 void ProcessMemoryDump::DumpHeapUsage( |
| 227 const base::hash_map<base::trace_event::AllocationContext, |
| 228 base::trace_event::AllocationMetrics>& metrics_by_context, |
| 229 base::trace_event::TraceEventMemoryOverhead& overhead, |
| 230 const char* allocator_name) { |
| 231 if (!metrics_by_context.empty()) { |
| 232 std::unique_ptr<base::trace_event::TracedValue> heap_dump = ExportHeapDump( |
| 233 metrics_by_context, session_state()->stack_frame_deduplicator(), |
| 234 session_state()->type_name_deduplicator()); |
| 235 AddHeapDump(allocator_name, std::move(heap_dump)); |
| 236 } |
| 237 |
| 238 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", |
| 239 allocator_name); |
| 240 overhead.DumpInto(base_name.c_str(), this); |
| 241 } |
| 242 |
| 224 void ProcessMemoryDump::Clear() { | 243 void ProcessMemoryDump::Clear() { |
| 225 if (has_process_totals_) { | 244 if (has_process_totals_) { |
| 226 process_totals_.Clear(); | 245 process_totals_.Clear(); |
| 227 has_process_totals_ = false; | 246 has_process_totals_ = false; |
| 228 } | 247 } |
| 229 | 248 |
| 230 if (has_process_mmaps_) { | 249 if (has_process_mmaps_) { |
| 231 process_mmaps_.Clear(); | 250 process_mmaps_.Clear(); |
| 232 has_process_mmaps_ = false; | 251 has_process_mmaps_ = false; |
| 233 } | 252 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 332 |
| 314 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 333 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
| 315 const std::string& target_node_name) { | 334 const std::string& target_node_name) { |
| 316 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 335 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
| 317 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 336 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
| 318 AddOwnershipEdge(source, target_child_mad->guid()); | 337 AddOwnershipEdge(source, target_child_mad->guid()); |
| 319 } | 338 } |
| 320 | 339 |
| 321 } // namespace trace_event | 340 } // namespace trace_event |
| 322 } // namespace base | 341 } // namespace base |
| OLD | NEW |