Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: base/trace_event/memory_dump_manager.cc

Issue 1921773003: Reland of [tracing] Add native allocation tracing mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "base/debug/stack_trace.h"
14 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
15 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
17 #include "base/trace_event/heap_profiler.h" 19 #include "base/trace_event/heap_profiler.h"
18 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 20 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
19 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" 21 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
20 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" 22 #include "base/trace_event/heap_profiler_type_name_deduplicator.h"
21 #include "base/trace_event/malloc_dump_provider.h" 23 #include "base/trace_event/malloc_dump_provider.h"
22 #include "base/trace_event/memory_dump_provider.h" 24 #include "base/trace_event/memory_dump_provider.h"
23 #include "base/trace_event/memory_dump_session_state.h" 25 #include "base/trace_event/memory_dump_session_state.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 165
164 void MemoryDumpManager::EnableHeapProfilingIfNeeded() { 166 void MemoryDumpManager::EnableHeapProfilingIfNeeded() {
165 if (heap_profiling_enabled_) 167 if (heap_profiling_enabled_)
166 return; 168 return;
167 169
168 if (!CommandLine::InitializedForCurrentProcess() || 170 if (!CommandLine::InitializedForCurrentProcess() ||
169 !CommandLine::ForCurrentProcess()->HasSwitch( 171 !CommandLine::ForCurrentProcess()->HasSwitch(
170 switches::kEnableHeapProfiling)) 172 switches::kEnableHeapProfiling))
171 return; 173 return;
172 174
173 AllocationContextTracker::SetCaptureEnabled(true); 175 std::string profiling_mode = CommandLine::ForCurrentProcess()
176 ->GetSwitchValueASCII(switches::kEnableHeapProfiling);
177 if (profiling_mode == "") {
178 AllocationContextTracker::SetCaptureMode(
179 AllocationContextTracker::CaptureMode::PSEUDO_STACK);
180 }
181 else if (profiling_mode == switches::kEnableHeapProfilingModeNative) {
182 #if HAVE_TRACE_STACK_FRAME_POINTERS && \
183 (BUILDFLAG(ENABLE_PROFILING) || !defined(NDEBUG))
184 // We need frame pointers for native tracing to work, and they are
185 // enabled in profiling and debug builds.
186 AllocationContextTracker::SetCaptureMode(
187 AllocationContextTracker::CaptureMode::NATIVE_STACK);
188 #else
189 CHECK(false) << "'" << profiling_mode << "' mode for "
190 << switches::kEnableHeapProfiling << " flag is not supported "
191 << "for this platform / build type.";
192 #endif
193 } else {
194 CHECK(false) << "Invalid mode '" << profiling_mode << "' for "
195 << switches::kEnableHeapProfiling << " flag.";
196 }
197
174 for (auto mdp : dump_providers_) 198 for (auto mdp : dump_providers_)
175 mdp->dump_provider->OnHeapProfilingEnabled(true); 199 mdp->dump_provider->OnHeapProfilingEnabled(true);
176 heap_profiling_enabled_ = true; 200 heap_profiling_enabled_ = true;
177 } 201 }
178 202
179 void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate, 203 void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate,
180 bool is_coordinator) { 204 bool is_coordinator) {
181 { 205 {
182 AutoLock lock(lock_); 206 AutoLock lock(lock_);
183 DCHECK(delegate); 207 DCHECK(delegate);
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 if (iter == process_dumps.end()) { 779 if (iter == process_dumps.end()) {
756 std::unique_ptr<ProcessMemoryDump> new_pmd( 780 std::unique_ptr<ProcessMemoryDump> new_pmd(
757 new ProcessMemoryDump(session_state)); 781 new ProcessMemoryDump(session_state));
758 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 782 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
759 } 783 }
760 return iter->second.get(); 784 return iter->second.get();
761 } 785 }
762 786
763 } // namespace trace_event 787 } // namespace trace_event
764 } // namespace base 788 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_stack_frame_deduplicator.cc ('k') | base/trace_event/trace_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698