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