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

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

Issue 1113953002: Revert of base: Remove use of MessageLoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « base/trace_event/trace_event_memory.h ('k') | base/trace_event/trace_event_memory_unittest.cc » ('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/trace_event/trace_event_memory.h" 5 #include "base/trace_event/trace_event_memory.h"
6 6
7 #include "base/debug/leak_annotations.h" 7 #include "base/debug/leak_annotations.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/location.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
12 #include "base/single_thread_task_runner.h" 11 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
15 #include "base/threading/thread_local_storage.h" 14 #include "base/threading/thread_local_storage.h"
16 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
17 16
18 namespace base { 17 namespace base {
19 namespace trace_event { 18 namespace trace_event {
20 19
21 namespace { 20 namespace {
22 21
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // 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
139 // tcmalloc that we have returned |count| * 2 stack frames. 138 // tcmalloc that we have returned |count| * 2 stack frames.
140 return static_cast<int>(count * 2); 139 return static_cast<int>(count * 2);
141 } 140 }
142 141
143 } // namespace 142 } // namespace
144 143
145 ////////////////////////////////////////////////////////////////////////////// 144 //////////////////////////////////////////////////////////////////////////////
146 145
147 TraceMemoryController::TraceMemoryController( 146 TraceMemoryController::TraceMemoryController(
148 scoped_refptr<SingleThreadTaskRunner> task_runner, 147 scoped_refptr<MessageLoopProxy> message_loop_proxy,
149 HeapProfilerStartFunction heap_profiler_start_function, 148 HeapProfilerStartFunction heap_profiler_start_function,
150 HeapProfilerStopFunction heap_profiler_stop_function, 149 HeapProfilerStopFunction heap_profiler_stop_function,
151 GetHeapProfileFunction get_heap_profile_function) 150 GetHeapProfileFunction get_heap_profile_function)
152 : task_runner_(task_runner.Pass()), 151 : message_loop_proxy_(message_loop_proxy),
153 heap_profiler_start_function_(heap_profiler_start_function), 152 heap_profiler_start_function_(heap_profiler_start_function),
154 heap_profiler_stop_function_(heap_profiler_stop_function), 153 heap_profiler_stop_function_(heap_profiler_stop_function),
155 get_heap_profile_function_(get_heap_profile_function), 154 get_heap_profile_function_(get_heap_profile_function),
156 weak_factory_(this) { 155 weak_factory_(this) {
157 // Force the "memory" category to show up in the trace viewer. 156 // Force the "memory" category to show up in the trace viewer.
158 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory"), "init"); 157 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory"), "init");
159 // Watch for the tracing system being enabled. 158 // Watch for the tracing system being enabled.
160 TraceLog::GetInstance()->AddEnabledStateObserver(this); 159 TraceLog::GetInstance()->AddEnabledStateObserver(this);
161 } 160 }
162 161
163 TraceMemoryController::~TraceMemoryController() { 162 TraceMemoryController::~TraceMemoryController() {
164 if (dump_timer_.IsRunning()) 163 if (dump_timer_.IsRunning())
165 StopProfiling(); 164 StopProfiling();
166 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 165 TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
167 } 166 }
168 167
169 // base::trace_event::TraceLog::EnabledStateChangedObserver overrides: 168 // base::trace_event::TraceLog::EnabledStateChangedObserver overrides:
170 void TraceMemoryController::OnTraceLogEnabled() { 169 void TraceMemoryController::OnTraceLogEnabled() {
171 // Check to see if tracing is enabled for the memory category. 170 // Check to see if tracing is enabled for the memory category.
172 bool enabled; 171 bool enabled;
173 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory"), 172 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory"),
174 &enabled); 173 &enabled);
175 if (!enabled) 174 if (!enabled)
176 return; 175 return;
177 DVLOG(1) << "OnTraceLogEnabled"; 176 DVLOG(1) << "OnTraceLogEnabled";
178 task_runner_->PostTask(FROM_HERE, 177 message_loop_proxy_->PostTask(
179 base::Bind(&TraceMemoryController::StartProfiling, 178 FROM_HERE,
180 weak_factory_.GetWeakPtr())); 179 base::Bind(&TraceMemoryController::StartProfiling,
180 weak_factory_.GetWeakPtr()));
181 } 181 }
182 182
183 void TraceMemoryController::OnTraceLogDisabled() { 183 void TraceMemoryController::OnTraceLogDisabled() {
184 // The memory category is always disabled before OnTraceLogDisabled() is 184 // The memory category is always disabled before OnTraceLogDisabled() is
185 // called, so we cannot tell if it was enabled before. Always try to turn 185 // called, so we cannot tell if it was enabled before. Always try to turn
186 // off profiling. 186 // off profiling.
187 DVLOG(1) << "OnTraceLogDisabled"; 187 DVLOG(1) << "OnTraceLogDisabled";
188 task_runner_->PostTask(FROM_HERE, 188 message_loop_proxy_->PostTask(
189 base::Bind(&TraceMemoryController::StopProfiling, 189 FROM_HERE,
190 weak_factory_.GetWeakPtr())); 190 base::Bind(&TraceMemoryController::StopProfiling,
191 weak_factory_.GetWeakPtr()));
191 } 192 }
192 193
193 void TraceMemoryController::StartProfiling() { 194 void TraceMemoryController::StartProfiling() {
194 // Watch for the tracing framework sending enabling more than once. 195 // Watch for the tracing framework sending enabling more than once.
195 if (dump_timer_.IsRunning()) 196 if (dump_timer_.IsRunning())
196 return; 197 return;
197 DVLOG(1) << "Starting trace memory"; 198 DVLOG(1) << "Starting trace memory";
198 if (!InitThreadLocalStorage()) 199 if (!InitThreadLocalStorage())
199 return; 200 return;
200 ScopedTraceMemory::set_enabled(true); 201 ScopedTraceMemory::set_enabled(true);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 if (!base::HexStringToUInt64(hex_address, &address)) 431 if (!base::HexStringToUInt64(hex_address, &address))
431 return "error"; 432 return "error";
432 if (!address) 433 if (!address)
433 return "null"; 434 return "null";
434 // Note that this cast handles 64-bit to 32-bit conversion if necessary. 435 // Note that this cast handles 64-bit to 32-bit conversion if necessary.
435 return reinterpret_cast<const char*>(address); 436 return reinterpret_cast<const char*>(address);
436 } 437 }
437 438
438 } // namespace trace_event 439 } // namespace trace_event
439 } // namespace base 440 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_memory.h ('k') | base/trace_event/trace_event_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698