OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/thread_heap_usage_tracker.h" | 5 #include "base/debug/thread_heap_usage_tracker.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <new> | 10 #include <new> |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 ThreadHeapUsage* usage = GetOrCreateThreadUsage(); | 281 ThreadHeapUsage* usage = GetOrCreateThreadUsage(); |
282 DCHECK_NE(nullptr, usage); | 282 DCHECK_NE(nullptr, usage); |
283 return *usage; | 283 return *usage; |
284 } | 284 } |
285 | 285 |
286 void ThreadHeapUsageTracker::EnableHeapTracking() { | 286 void ThreadHeapUsageTracker::EnableHeapTracking() { |
287 EnsureTLSInitialized(); | 287 EnsureTLSInitialized(); |
288 | 288 |
289 CHECK_EQ(false, g_heap_tracking_enabled) << "No double-enabling."; | 289 CHECK_EQ(false, g_heap_tracking_enabled) << "No double-enabling."; |
290 g_heap_tracking_enabled = true; | 290 g_heap_tracking_enabled = true; |
291 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 291 #if BUILDFLAG(USE_ALLOCATOR_SHIM) |
292 base::allocator::InsertAllocatorDispatch(&allocator_dispatch); | 292 base::allocator::InsertAllocatorDispatch(&allocator_dispatch); |
293 #else | 293 #else |
294 CHECK(false) << "Can't enable heap tracking without the shim."; | 294 CHECK(false) << "Can't enable heap tracking without the shim."; |
295 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 295 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM) |
296 } | 296 } |
297 | 297 |
298 bool ThreadHeapUsageTracker::IsHeapTrackingEnabled() { | 298 bool ThreadHeapUsageTracker::IsHeapTrackingEnabled() { |
299 return g_heap_tracking_enabled; | 299 return g_heap_tracking_enabled; |
300 } | 300 } |
301 | 301 |
302 void ThreadHeapUsageTracker::DisableHeapTrackingForTesting() { | 302 void ThreadHeapUsageTracker::DisableHeapTrackingForTesting() { |
303 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 303 #if BUILDFLAG(USE_ALLOCATOR_SHIM) |
304 base::allocator::RemoveAllocatorDispatchForTesting(&allocator_dispatch); | 304 base::allocator::RemoveAllocatorDispatchForTesting(&allocator_dispatch); |
305 #else | 305 #else |
306 CHECK(false) << "Can't disable heap tracking without the shim."; | 306 CHECK(false) << "Can't disable heap tracking without the shim."; |
307 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 307 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM) |
308 DCHECK_EQ(true, g_heap_tracking_enabled) << "Heap tracking not enabled."; | 308 DCHECK_EQ(true, g_heap_tracking_enabled) << "Heap tracking not enabled."; |
309 g_heap_tracking_enabled = false; | 309 g_heap_tracking_enabled = false; |
310 } | 310 } |
311 | 311 |
312 base::allocator::AllocatorDispatch* | 312 base::allocator::AllocatorDispatch* |
313 ThreadHeapUsageTracker::GetDispatchForTesting() { | 313 ThreadHeapUsageTracker::GetDispatchForTesting() { |
314 return &allocator_dispatch; | 314 return &allocator_dispatch; |
315 } | 315 } |
316 | 316 |
317 void ThreadHeapUsageTracker::EnsureTLSInitialized() { | 317 void ThreadHeapUsageTracker::EnsureTLSInitialized() { |
(...skipping 13 matching lines...) Expand all Loading... |
331 // RecordFree() above. The sentinel prevents RecordFree() from re-creating | 331 // RecordFree() above. The sentinel prevents RecordFree() from re-creating |
332 // another ThreadHeapUsage object. | 332 // another ThreadHeapUsage object. |
333 g_thread_allocator_usage.Set(kTeardownSentinel); | 333 g_thread_allocator_usage.Set(kTeardownSentinel); |
334 delete static_cast<ThreadHeapUsage*>(thread_heap_usage); | 334 delete static_cast<ThreadHeapUsage*>(thread_heap_usage); |
335 }); | 335 }); |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
339 } // namespace debug | 339 } // namespace debug |
340 } // namespace base | 340 } // namespace base |
OLD | NEW |