| 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/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/allocator/features.h" | 10 #include "base/allocator/features.h" |
| 11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/debug/debugging_flags.h" | 15 #include "base/debug/debugging_flags.h" |
| 16 #include "base/debug/stack_trace.h" | 16 #include "base/debug/stack_trace.h" |
| 17 #include "base/debug/thread_heap_usage_tracker.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/trace_event/heap_profiler.h" | 21 #include "base/trace_event/heap_profiler.h" |
| 21 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 22 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 22 #include "base/trace_event/heap_profiler_event_filter.h" | 23 #include "base/trace_event/heap_profiler_event_filter.h" |
| 23 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 24 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" |
| 24 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | 25 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" |
| 25 #include "base/trace_event/malloc_dump_provider.h" | 26 #include "base/trace_event/malloc_dump_provider.h" |
| 26 #include "base/trace_event/memory_dump_provider.h" | 27 #include "base/trace_event/memory_dump_provider.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (!CommandLine::InitializedForCurrentProcess() || | 180 if (!CommandLine::InitializedForCurrentProcess() || |
| 180 !CommandLine::ForCurrentProcess()->HasSwitch( | 181 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 181 switches::kEnableHeapProfiling)) | 182 switches::kEnableHeapProfiling)) |
| 182 return; | 183 return; |
| 183 | 184 |
| 184 std::string profiling_mode = CommandLine::ForCurrentProcess() | 185 std::string profiling_mode = CommandLine::ForCurrentProcess() |
| 185 ->GetSwitchValueASCII(switches::kEnableHeapProfiling); | 186 ->GetSwitchValueASCII(switches::kEnableHeapProfiling); |
| 186 if (profiling_mode == "") { | 187 if (profiling_mode == "") { |
| 187 AllocationContextTracker::SetCaptureMode( | 188 AllocationContextTracker::SetCaptureMode( |
| 188 AllocationContextTracker::CaptureMode::PSEUDO_STACK); | 189 AllocationContextTracker::CaptureMode::PSEUDO_STACK); |
| 189 } | |
| 190 else if (profiling_mode == switches::kEnableHeapProfilingModeNative) { | |
| 191 #if HAVE_TRACE_STACK_FRAME_POINTERS && \ | 190 #if HAVE_TRACE_STACK_FRAME_POINTERS && \ |
| 192 (BUILDFLAG(ENABLE_PROFILING) || !defined(NDEBUG)) | 191 (BUILDFLAG(ENABLE_PROFILING) || !defined(NDEBUG)) |
| 192 } else if (profiling_mode == switches::kEnableHeapProfilingModeNative) { |
| 193 // We need frame pointers for native tracing to work, and they are | 193 // We need frame pointers for native tracing to work, and they are |
| 194 // enabled in profiling and debug builds. | 194 // enabled in profiling and debug builds. |
| 195 AllocationContextTracker::SetCaptureMode( | 195 AllocationContextTracker::SetCaptureMode( |
| 196 AllocationContextTracker::CaptureMode::NATIVE_STACK); | 196 AllocationContextTracker::CaptureMode::NATIVE_STACK); |
| 197 #else | 197 #endif |
| 198 CHECK(false) << "'" << profiling_mode << "' mode for " | 198 #if BUILDFLAG(ENABLE_MEMORY_TASK_PROFILER) |
| 199 << switches::kEnableHeapProfiling << " flag is not supported " | 199 } else if (profiling_mode == switches::kEnableHeapProfilingTaskProfiler) { |
| 200 << "for this platform / build type."; | 200 // Enable heap tracking, which in turn enables capture of heap usage |
| 201 // tracking in tracked_objects.cc. |
| 202 if (!base::debug::ThreadHeapUsageTracker::IsHeapTrackingEnabled()) |
| 203 base::debug::ThreadHeapUsageTracker::EnableHeapTracking(); |
| 201 #endif | 204 #endif |
| 202 } else { | 205 } else { |
| 203 CHECK(false) << "Invalid mode '" << profiling_mode << "' for " | 206 CHECK(false) << "Invalid mode '" << profiling_mode << "' for " |
| 204 << switches::kEnableHeapProfiling << " flag."; | 207 << switches::kEnableHeapProfiling << " flag."; |
| 205 } | 208 } |
| 206 | 209 |
| 207 for (auto mdp : dump_providers_) | 210 for (auto mdp : dump_providers_) |
| 208 mdp->dump_provider->OnHeapProfilingEnabled(true); | 211 mdp->dump_provider->OnHeapProfilingEnabled(true); |
| 209 heap_profiling_enabled_ = true; | 212 heap_profiling_enabled_ = true; |
| 210 } | 213 } |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) | 989 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) |
| 987 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; | 990 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; |
| 988 ++periodic_dumps_count_; | 991 ++periodic_dumps_count_; |
| 989 | 992 |
| 990 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 993 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 991 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); | 994 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); |
| 992 } | 995 } |
| 993 | 996 |
| 994 } // namespace trace_event | 997 } // namespace trace_event |
| 995 } // namespace base | 998 } // namespace base |
| OLD | NEW |