Chromium Code Reviews| 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/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/debug/debugging_flags.h" | |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
|
Primiano Tucci (use gerrit)
2016/04/28 07:02:42
add an include to base/debug/stack_trace.h as that
Dmitry Skiba
2016/04/28 18:16:31
Done.
| |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "base/trace_event/heap_profiler.h" | 18 #include "base/trace_event/heap_profiler.h" |
| 18 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 19 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 19 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 20 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" |
| 20 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | 21 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" |
| 21 #include "base/trace_event/malloc_dump_provider.h" | 22 #include "base/trace_event/malloc_dump_provider.h" |
| 22 #include "base/trace_event/memory_dump_provider.h" | 23 #include "base/trace_event/memory_dump_provider.h" |
| 23 #include "base/trace_event/memory_dump_session_state.h" | 24 #include "base/trace_event/memory_dump_session_state.h" |
| 24 #include "base/trace_event/process_memory_dump.h" | 25 #include "base/trace_event/process_memory_dump.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 164 |
| 164 void MemoryDumpManager::EnableHeapProfilingIfNeeded() { | 165 void MemoryDumpManager::EnableHeapProfilingIfNeeded() { |
| 165 if (heap_profiling_enabled_) | 166 if (heap_profiling_enabled_) |
| 166 return; | 167 return; |
| 167 | 168 |
| 168 if (!CommandLine::InitializedForCurrentProcess() || | 169 if (!CommandLine::InitializedForCurrentProcess() || |
| 169 !CommandLine::ForCurrentProcess()->HasSwitch( | 170 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 170 switches::kEnableHeapProfiling)) | 171 switches::kEnableHeapProfiling)) |
| 171 return; | 172 return; |
| 172 | 173 |
| 173 AllocationContextTracker::SetCaptureEnabled(true); | 174 std::string profiling_mode = CommandLine::ForCurrentProcess() |
| 175 ->GetSwitchValueASCII(switches::kEnableHeapProfiling); | |
| 176 if (profiling_mode == "") { | |
| 177 AllocationContextTracker::SetCaptureMode( | |
| 178 AllocationContextTracker::CaptureMode::PSEUDO_STACK); | |
| 179 } | |
| 180 else if (profiling_mode == switches::kEnableHeapProfilingModeNative) { | |
| 181 #if HAVE_TRACE_STACK_FRAME_POINTERS && \ | |
| 182 (BUILDFLAG(ENABLE_PROFILING) || !defined(NDEBUG)) | |
| 183 // We need frame pointers for native tracing to work, and they are | |
| 184 // enabled in profiling and debug builds. | |
| 185 AllocationContextTracker::SetCaptureMode( | |
| 186 AllocationContextTracker::CaptureMode::NATIVE_STACK); | |
| 187 #else | |
| 188 CHECK(false) << "'" << profiling_mode << "' mode for " | |
| 189 << switches::kEnableHeapProfiling << " flag is not supported " | |
| 190 << "for this platform / build type."; | |
| 191 #endif | |
| 192 } else { | |
| 193 CHECK(false) << "Invalid mode '" << profiling_mode << "' for " | |
| 194 << switches::kEnableHeapProfiling << " flag."; | |
| 195 } | |
| 196 | |
| 174 for (auto mdp : dump_providers_) | 197 for (auto mdp : dump_providers_) |
| 175 mdp->dump_provider->OnHeapProfilingEnabled(true); | 198 mdp->dump_provider->OnHeapProfilingEnabled(true); |
| 176 heap_profiling_enabled_ = true; | 199 heap_profiling_enabled_ = true; |
| 177 } | 200 } |
| 178 | 201 |
| 179 void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate, | 202 void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate, |
| 180 bool is_coordinator) { | 203 bool is_coordinator) { |
| 181 { | 204 { |
| 182 AutoLock lock(lock_); | 205 AutoLock lock(lock_); |
| 183 DCHECK(delegate); | 206 DCHECK(delegate); |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 if (iter == process_dumps.end()) { | 778 if (iter == process_dumps.end()) { |
| 756 std::unique_ptr<ProcessMemoryDump> new_pmd( | 779 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 757 new ProcessMemoryDump(session_state)); | 780 new ProcessMemoryDump(session_state)); |
| 758 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 781 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 759 } | 782 } |
| 760 return iter->second.get(); | 783 return iter->second.get(); |
| 761 } | 784 } |
| 762 | 785 |
| 763 } // namespace trace_event | 786 } // namespace trace_event |
| 764 } // namespace base | 787 } // namespace base |
| OLD | NEW |