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

Side by Side Diff: base/debug/trace_event_memory.cc

Issue 369703003: Reduce usage of MessageLoopProxy in base/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_memory.h ('k') | base/files/file_path_watcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/debug/trace_event_memory.h" 5 #include "base/debug/trace_event_memory.h"
6 6
7 #include "base/debug/leak_annotations.h" 7 #include "base/debug/leak_annotations.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/threading/thread_local_storage.h" 15 #include "base/threading/thread_local_storage.h"
16 16
17 namespace base { 17 namespace base {
18 namespace debug { 18 namespace debug {
19 19
20 namespace { 20 namespace {
21 21
22 // Maximum number of nested TRACE_EVENT scopes to record. Must be less than 22 // Maximum number of nested TRACE_EVENT scopes to record. Must be less than
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Each item in the trace event stack contains both name and category so tell 137 // Each item in the trace event stack contains both name and category so tell
138 // tcmalloc that we have returned |count| * 2 stack frames. 138 // tcmalloc that we have returned |count| * 2 stack frames.
139 return static_cast<int>(count * 2); 139 return static_cast<int>(count * 2);
140 } 140 }
141 141
142 } // namespace 142 } // namespace
143 143
144 ////////////////////////////////////////////////////////////////////////////// 144 //////////////////////////////////////////////////////////////////////////////
145 145
146 TraceMemoryController::TraceMemoryController( 146 TraceMemoryController::TraceMemoryController(
147 scoped_refptr<MessageLoopProxy> message_loop_proxy, 147 scoped_refptr<SingleThreadTaskRunner> main_task_runner,
148 HeapProfilerStartFunction heap_profiler_start_function, 148 HeapProfilerStartFunction heap_profiler_start_function,
149 HeapProfilerStopFunction heap_profiler_stop_function, 149 HeapProfilerStopFunction heap_profiler_stop_function,
150 GetHeapProfileFunction get_heap_profile_function) 150 GetHeapProfileFunction get_heap_profile_function)
151 : message_loop_proxy_(message_loop_proxy), 151 : main_task_runner_(main_task_runner),
152 heap_profiler_start_function_(heap_profiler_start_function), 152 heap_profiler_start_function_(heap_profiler_start_function),
153 heap_profiler_stop_function_(heap_profiler_stop_function), 153 heap_profiler_stop_function_(heap_profiler_stop_function),
154 get_heap_profile_function_(get_heap_profile_function), 154 get_heap_profile_function_(get_heap_profile_function),
155 weak_factory_(this) { 155 weak_factory_(this) {
156 // Force the "memory" category to show up in the trace viewer. 156 // Force the "memory" category to show up in the trace viewer.
157 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory"), "init"); 157 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory"), "init");
158 // Watch for the tracing system being enabled. 158 // Watch for the tracing system being enabled.
159 TraceLog::GetInstance()->AddEnabledStateObserver(this); 159 TraceLog::GetInstance()->AddEnabledStateObserver(this);
160 } 160 }
161 161
162 TraceMemoryController::~TraceMemoryController() { 162 TraceMemoryController::~TraceMemoryController() {
163 if (dump_timer_.IsRunning()) 163 if (dump_timer_.IsRunning())
164 StopProfiling(); 164 StopProfiling();
165 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 165 TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
166 } 166 }
167 167
168 // base::debug::TraceLog::EnabledStateChangedObserver overrides: 168 // base::debug::TraceLog::EnabledStateChangedObserver overrides:
169 void TraceMemoryController::OnTraceLogEnabled() { 169 void TraceMemoryController::OnTraceLogEnabled() {
170 // Check to see if tracing is enabled for the memory category. 170 // Check to see if tracing is enabled for the memory category.
171 bool enabled; 171 bool enabled;
172 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory"), 172 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory"),
173 &enabled); 173 &enabled);
174 if (!enabled) 174 if (!enabled)
175 return; 175 return;
176 DVLOG(1) << "OnTraceLogEnabled"; 176 DVLOG(1) << "OnTraceLogEnabled";
177 message_loop_proxy_->PostTask( 177 main_task_runner_->PostTask(FROM_HERE,
178 FROM_HERE, 178 base::Bind(&TraceMemoryController::StartProfiling,
179 base::Bind(&TraceMemoryController::StartProfiling, 179 weak_factory_.GetWeakPtr()));
180 weak_factory_.GetWeakPtr()));
181 } 180 }
182 181
183 void TraceMemoryController::OnTraceLogDisabled() { 182 void TraceMemoryController::OnTraceLogDisabled() {
184 // The memory category is always disabled before OnTraceLogDisabled() is 183 // The memory category is always disabled before OnTraceLogDisabled() is
185 // called, so we cannot tell if it was enabled before. Always try to turn 184 // called, so we cannot tell if it was enabled before. Always try to turn
186 // off profiling. 185 // off profiling.
187 DVLOG(1) << "OnTraceLogDisabled"; 186 DVLOG(1) << "OnTraceLogDisabled";
188 message_loop_proxy_->PostTask( 187 main_task_runner_->PostTask(FROM_HERE,
189 FROM_HERE, 188 base::Bind(&TraceMemoryController::StopProfiling,
190 base::Bind(&TraceMemoryController::StopProfiling, 189 weak_factory_.GetWeakPtr()));
191 weak_factory_.GetWeakPtr()));
192 } 190 }
193 191
194 void TraceMemoryController::StartProfiling() { 192 void TraceMemoryController::StartProfiling() {
195 // Watch for the tracing framework sending enabling more than once. 193 // Watch for the tracing framework sending enabling more than once.
196 if (dump_timer_.IsRunning()) 194 if (dump_timer_.IsRunning())
197 return; 195 return;
198 DVLOG(1) << "Starting trace memory"; 196 DVLOG(1) << "Starting trace memory";
199 if (!InitThreadLocalStorage()) 197 if (!InitThreadLocalStorage())
200 return; 198 return;
201 ScopedTraceMemory::set_enabled(true); 199 ScopedTraceMemory::set_enabled(true);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (!base::HexStringToUInt64(hex_address, &address)) 429 if (!base::HexStringToUInt64(hex_address, &address))
432 return "error"; 430 return "error";
433 if (!address) 431 if (!address)
434 return "null"; 432 return "null";
435 // Note that this cast handles 64-bit to 32-bit conversion if necessary. 433 // Note that this cast handles 64-bit to 32-bit conversion if necessary.
436 return reinterpret_cast<const char*>(address); 434 return reinterpret_cast<const char*>(address);
437 } 435 }
438 436
439 } // namespace debug 437 } // namespace debug
440 } // namespace base 438 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_memory.h ('k') | base/files/file_path_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698