| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/memory_profiler_allocation_context.h" | 5 #include "base/trace_event/memory_profiler_allocation_context.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" |
| 9 #include "base/threading/thread_local_storage.h" | 10 #include "base/threading/thread_local_storage.h" |
| 10 | 11 |
| 11 namespace base { | 12 namespace base { |
| 12 namespace trace_event { | 13 namespace trace_event { |
| 13 | 14 |
| 14 subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0; | 15 subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0; |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER; | 18 ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER; |
| 18 } | 19 |
| 20 } // namespace |
| 19 | 21 |
| 20 AllocationStack::AllocationStack() {} | 22 AllocationStack::AllocationStack() {} |
| 21 AllocationStack::~AllocationStack() {} | 23 AllocationStack::~AllocationStack() {} |
| 22 | 24 |
| 25 AllocationContext AllocationContext::GetEmpty() { |
| 26 AllocationContext context; |
| 27 |
| 28 for (size_t i = 0; i < arraysize(context.backtrace.frames); i++) |
| 29 context.backtrace.frames[i] = nullptr; |
| 30 |
| 31 for (size_t i = 0; i < arraysize(context.fields); i++) |
| 32 context.fields[i].first = nullptr; |
| 33 |
| 34 return context; |
| 35 } |
| 36 |
| 23 // This function is added to the TLS slot to clean up the instance when the | 37 // This function is added to the TLS slot to clean up the instance when the |
| 24 // thread exits. | 38 // thread exits. |
| 25 void DestructAllocationContextTracker(void* alloc_ctx_tracker) { | 39 void DestructAllocationContextTracker(void* alloc_ctx_tracker) { |
| 26 delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker); | 40 delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker); |
| 27 } | 41 } |
| 28 | 42 |
| 29 AllocationContextTracker* AllocationContextTracker::GetThreadLocalTracker() { | 43 AllocationContextTracker* AllocationContextTracker::GetThreadLocalTracker() { |
| 30 auto tracker = | 44 auto tracker = |
| 31 static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get()); | 45 static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get()); |
| 32 | 46 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // If there is room for more, fill the remaining slots with nullptr keys. | 137 // If there is room for more, fill the remaining slots with nullptr keys. |
| 124 for (; dst != dst_end; dst++) | 138 for (; dst != dst_end; dst++) |
| 125 dst->first = nullptr; | 139 dst->first = nullptr; |
| 126 } | 140 } |
| 127 | 141 |
| 128 return ctx; | 142 return ctx; |
| 129 } | 143 } |
| 130 | 144 |
| 131 } // namespace trace_event | 145 } // namespace trace_event |
| 132 } // namespace base | 146 } // namespace base |
| OLD | NEW |