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

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

Issue 1469843002: Remove dependency on allocator from 'content' targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify_allocator1_2
Patch Set: Fix build Created 5 years, 1 month 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 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" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 127 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 138 // Each item in the trace event stack contains both name and category so tell
139 // tcmalloc that we have returned |count| * 2 stack frames. 139 // tcmalloc that we have returned |count| * 2 stack frames.
140 return static_cast<int>(count * 2); 140 return static_cast<int>(count * 2);
141 } 141 }
142 142
143 } // namespace 143 } // namespace
144 144
145 ////////////////////////////////////////////////////////////////////////////// 145 //////////////////////////////////////////////////////////////////////////////
146 146
147 TraceMemoryController::TraceMemoryController( 147 TraceMemoryController::TraceMemoryController(
148 scoped_refptr<SingleThreadTaskRunner> task_runner, 148 scoped_refptr<SingleThreadTaskRunner> task_runner)
149 HeapProfilerStartFunction heap_profiler_start_function, 149 : task_runner_(task_runner.Pass()), weak_factory_(this) {
150 HeapProfilerStopFunction heap_profiler_stop_function,
151 GetHeapProfileFunction get_heap_profile_function)
152 : task_runner_(task_runner.Pass()),
153 heap_profiler_start_function_(heap_profiler_start_function),
154 heap_profiler_stop_function_(heap_profiler_stop_function),
155 get_heap_profile_function_(get_heap_profile_function),
156 weak_factory_(this) {
157 // Force the "memory" category to show up in the trace viewer. 150 // Force the "memory" category to show up in the trace viewer.
158 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory"), "init"); 151 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory"), "init");
159 // Watch for the tracing system being enabled. 152 // Watch for the tracing system being enabled.
160 TraceLog::GetInstance()->AddEnabledStateObserver(this); 153 TraceLog::GetInstance()->AddEnabledStateObserver(this);
161 } 154 }
162 155
163 TraceMemoryController::~TraceMemoryController() { 156 TraceMemoryController::~TraceMemoryController() {
164 if (dump_timer_.IsRunning()) 157 if (dump_timer_.IsRunning())
165 StopProfiling(); 158 StopProfiling();
166 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 159 TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
(...skipping 24 matching lines...) Expand all
191 } 184 }
192 185
193 void TraceMemoryController::StartProfiling() { 186 void TraceMemoryController::StartProfiling() {
194 // Watch for the tracing framework sending enabling more than once. 187 // Watch for the tracing framework sending enabling more than once.
195 if (dump_timer_.IsRunning()) 188 if (dump_timer_.IsRunning())
196 return; 189 return;
197 DVLOG(1) << "Starting trace memory"; 190 DVLOG(1) << "Starting trace memory";
198 InitThreadLocalStorage(); 191 InitThreadLocalStorage();
199 ScopedTraceMemory::set_enabled(true); 192 ScopedTraceMemory::set_enabled(true);
200 // Call ::HeapProfilerWithPseudoStackStart(). 193 // Call ::HeapProfilerWithPseudoStackStart().
201 heap_profiler_start_function_(&GetPseudoStack); 194 allocator::HeapProfilerStart(&GetPseudoStack);
202 const int kDumpIntervalSeconds = 5; 195 const int kDumpIntervalSeconds = 5;
203 dump_timer_.Start(FROM_HERE, 196 dump_timer_.Start(FROM_HERE,
204 TimeDelta::FromSeconds(kDumpIntervalSeconds), 197 TimeDelta::FromSeconds(kDumpIntervalSeconds),
205 base::Bind(&TraceMemoryController::DumpMemoryProfile, 198 base::Bind(&TraceMemoryController::DumpMemoryProfile,
206 weak_factory_.GetWeakPtr())); 199 weak_factory_.GetWeakPtr()));
207 } 200 }
208 201
209 void TraceMemoryController::DumpMemoryProfile() { 202 void TraceMemoryController::DumpMemoryProfile() {
210 // Don't trace allocations here in the memory tracing system. 203 // Don't trace allocations here in the memory tracing system.
211 INTERNAL_TRACE_MEMORY(TRACE_DISABLED_BY_DEFAULT("memory"), 204 INTERNAL_TRACE_MEMORY(TRACE_DISABLED_BY_DEFAULT("memory"),
212 TRACE_MEMORY_IGNORE); 205 TRACE_MEMORY_IGNORE);
213 206
214 DVLOG(1) << "DumpMemoryProfile"; 207 DVLOG(1) << "DumpMemoryProfile";
215 // MemoryDumpHolder takes ownership of this string. See GetHeapProfile() in 208 // MemoryDumpHolder takes ownership of this string. See GetHeapProfile() in
216 // tcmalloc for details. 209 // tcmalloc for details.
217 char* dump = get_heap_profile_function_(); 210 char* dump = allocator::GetHeapProfile();
218 const int kSnapshotId = 1; 211 const int kSnapshotId = 1;
219 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 212 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
220 TRACE_DISABLED_BY_DEFAULT("memory"), 213 TRACE_DISABLED_BY_DEFAULT("memory"),
221 "memory::Heap", 214 "memory::Heap",
222 kSnapshotId, 215 kSnapshotId,
223 scoped_refptr<ConvertableToTraceFormat>(new MemoryDumpHolder(dump))); 216 scoped_refptr<ConvertableToTraceFormat>(new MemoryDumpHolder(dump)));
224 } 217 }
225 218
226 void TraceMemoryController::StopProfiling() { 219 void TraceMemoryController::StopProfiling() {
227 // Watch for the tracing framework sending disabled more than once. 220 // Watch for the tracing framework sending disabled more than once.
228 if (!dump_timer_.IsRunning()) 221 if (!dump_timer_.IsRunning())
229 return; 222 return;
230 DVLOG(1) << "Stopping trace memory"; 223 DVLOG(1) << "Stopping trace memory";
231 dump_timer_.Stop(); 224 dump_timer_.Stop();
232 ScopedTraceMemory::set_enabled(false); 225 ScopedTraceMemory::set_enabled(false);
233 CleanupThreadLocalStorage(); 226 CleanupThreadLocalStorage();
234 // Call ::HeapProfilerStop(). 227 // Call ::HeapProfilerStop().
235 heap_profiler_stop_function_(); 228 allocator::HeapProfilerStop();
236 } 229 }
237 230
238 bool TraceMemoryController::IsTimerRunningForTest() const { 231 bool TraceMemoryController::IsTimerRunningForTest() const {
239 return dump_timer_.IsRunning(); 232 return dump_timer_.IsRunning();
240 } 233 }
241 234
242 ///////////////////////////////////////////////////////////////////////////// 235 /////////////////////////////////////////////////////////////////////////////
243 236
244 // static 237 // static
245 bool ScopedTraceMemory::enabled_ = false; 238 bool ScopedTraceMemory::enabled_ = false;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (!base::HexStringToUInt64(hex_address, &address)) 420 if (!base::HexStringToUInt64(hex_address, &address))
428 return "error"; 421 return "error";
429 if (!address) 422 if (!address)
430 return "null"; 423 return "null";
431 // Note that this cast handles 64-bit to 32-bit conversion if necessary. 424 // Note that this cast handles 64-bit to 32-bit conversion if necessary.
432 return reinterpret_cast<const char*>(address); 425 return reinterpret_cast<const char*>(address);
433 } 426 }
434 427
435 } // namespace trace_event 428 } // namespace trace_event
436 } // namespace base 429 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698