OLD | NEW |
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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 // Pointer to a TraceMemoryStack per thread. | 64 // Pointer to a TraceMemoryStack per thread. |
65 base::ThreadLocalStorage::StaticSlot tls_trace_memory_stack = TLS_INITIALIZER; | 65 base::ThreadLocalStorage::StaticSlot tls_trace_memory_stack = TLS_INITIALIZER; |
66 | 66 |
67 // Clean up memory pointed to by our thread-local storage. | 67 // Clean up memory pointed to by our thread-local storage. |
68 void DeleteStackOnThreadCleanup(void* value) { | 68 void DeleteStackOnThreadCleanup(void* value) { |
69 TraceMemoryStack* stack = static_cast<TraceMemoryStack*>(value); | 69 TraceMemoryStack* stack = static_cast<TraceMemoryStack*>(value); |
70 delete stack; | 70 delete stack; |
71 } | 71 } |
72 | 72 |
73 // Initializes the thread-local TraceMemoryStack pointer. Returns true on | 73 // Initializes the thread-local TraceMemoryStack pointer. |
74 // success or if it is already initialized. | 74 void InitThreadLocalStorage() { |
75 bool InitThreadLocalStorage() { | |
76 if (tls_trace_memory_stack.initialized()) | 75 if (tls_trace_memory_stack.initialized()) |
77 return true; | 76 return; |
78 // Initialize the thread-local storage key, returning true on success. | 77 // Initialize the thread-local storage key. |
79 return tls_trace_memory_stack.Initialize(&DeleteStackOnThreadCleanup); | 78 tls_trace_memory_stack.Initialize(&DeleteStackOnThreadCleanup); |
80 } | 79 } |
81 | 80 |
82 // Clean up thread-local-storage in the main thread. | 81 // Clean up thread-local-storage in the main thread. |
83 void CleanupThreadLocalStorage() { | 82 void CleanupThreadLocalStorage() { |
84 if (!tls_trace_memory_stack.initialized()) | 83 if (!tls_trace_memory_stack.initialized()) |
85 return; | 84 return; |
86 TraceMemoryStack* stack = | 85 TraceMemoryStack* stack = |
87 static_cast<TraceMemoryStack*>(tls_trace_memory_stack.Get()); | 86 static_cast<TraceMemoryStack*>(tls_trace_memory_stack.Get()); |
88 delete stack; | 87 delete stack; |
89 tls_trace_memory_stack.Set(NULL); | 88 tls_trace_memory_stack.Set(NULL); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 FROM_HERE, | 188 FROM_HERE, |
190 base::Bind(&TraceMemoryController::StopProfiling, | 189 base::Bind(&TraceMemoryController::StopProfiling, |
191 weak_factory_.GetWeakPtr())); | 190 weak_factory_.GetWeakPtr())); |
192 } | 191 } |
193 | 192 |
194 void TraceMemoryController::StartProfiling() { | 193 void TraceMemoryController::StartProfiling() { |
195 // Watch for the tracing framework sending enabling more than once. | 194 // Watch for the tracing framework sending enabling more than once. |
196 if (dump_timer_.IsRunning()) | 195 if (dump_timer_.IsRunning()) |
197 return; | 196 return; |
198 DVLOG(1) << "Starting trace memory"; | 197 DVLOG(1) << "Starting trace memory"; |
199 if (!InitThreadLocalStorage()) | 198 InitThreadLocalStorage(); |
200 return; | |
201 ScopedTraceMemory::set_enabled(true); | 199 ScopedTraceMemory::set_enabled(true); |
202 // Call ::HeapProfilerWithPseudoStackStart(). | 200 // Call ::HeapProfilerWithPseudoStackStart(). |
203 heap_profiler_start_function_(&GetPseudoStack); | 201 heap_profiler_start_function_(&GetPseudoStack); |
204 const int kDumpIntervalSeconds = 5; | 202 const int kDumpIntervalSeconds = 5; |
205 dump_timer_.Start(FROM_HERE, | 203 dump_timer_.Start(FROM_HERE, |
206 TimeDelta::FromSeconds(kDumpIntervalSeconds), | 204 TimeDelta::FromSeconds(kDumpIntervalSeconds), |
207 base::Bind(&TraceMemoryController::DumpMemoryProfile, | 205 base::Bind(&TraceMemoryController::DumpMemoryProfile, |
208 weak_factory_.GetWeakPtr())); | 206 weak_factory_.GetWeakPtr())); |
209 } | 207 } |
210 | 208 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 trace_event | 437 } // namespace trace_event |
440 } // namespace base | 438 } // namespace base |
OLD | NEW |