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

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

Issue 1900223003: [tracing] Ignore tracing allocations in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes. Created 4 years, 8 months 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 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/heap_profiler_allocation_context_tracker.h" 5 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
11 #include "base/threading/thread_local_storage.h" 11 #include "base/threading/thread_local_storage.h"
12 #include "base/trace_event/heap_profiler_allocation_context.h" 12 #include "base/trace_event/heap_profiler_allocation_context.h"
13 13
14 namespace base { 14 namespace base {
15 namespace trace_event { 15 namespace trace_event {
16 16
17 subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0; 17 subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0;
18 18
19 namespace { 19 namespace {
20 20
21 const size_t kMaxStackDepth = 128u; 21 const size_t kMaxStackDepth = 128u;
22 const size_t kMaxTaskDepth = 16u; 22 const size_t kMaxTaskDepth = 16u;
23 AllocationContextTracker* const kInitializingSentinel = 23 AllocationContextTracker* const kInitializingSentinel =
24 reinterpret_cast<AllocationContextTracker*>(-1); 24 reinterpret_cast<AllocationContextTracker*>(-1);
25 const char kTracingOverhead[] = "tracing_overhead";
25 26
26 ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER; 27 ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER;
27 28
28 // This function is added to the TLS slot to clean up the instance when the 29 // This function is added to the TLS slot to clean up the instance when the
29 // thread exits. 30 // thread exits.
30 void DestructAllocationContextTracker(void* alloc_ctx_tracker) { 31 void DestructAllocationContextTracker(void* alloc_ctx_tracker) {
31 delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker); 32 delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker);
32 } 33 }
33 34
34 } // namespace 35 } // namespace
35 36
36 // static 37 // static
37 AllocationContextTracker* 38 AllocationContextTracker*
38 AllocationContextTracker::GetInstanceForCurrentThread() { 39 AllocationContextTracker::GetInstanceForCurrentThread() {
39 AllocationContextTracker* tracker = 40 AllocationContextTracker* tracker =
40 static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get()); 41 static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get());
41 if (tracker == kInitializingSentinel) 42 if (tracker == kInitializingSentinel)
42 return nullptr; // Re-entrancy case. 43 return nullptr; // Re-entrancy case.
43 44
44 if (!tracker) { 45 if (!tracker) {
45 g_tls_alloc_ctx_tracker.Set(kInitializingSentinel); 46 g_tls_alloc_ctx_tracker.Set(kInitializingSentinel);
46 tracker = new AllocationContextTracker(); 47 tracker = new AllocationContextTracker();
47 g_tls_alloc_ctx_tracker.Set(tracker); 48 g_tls_alloc_ctx_tracker.Set(tracker);
48 } 49 }
49 50
50 return tracker; 51 return tracker;
51 } 52 }
52 53
53 AllocationContextTracker::AllocationContextTracker() : thread_name_(nullptr) { 54 AllocationContextTracker::AllocationContextTracker()
55 : thread_name_(nullptr), ignore_scope_depth_(0) {
54 pseudo_stack_.reserve(kMaxStackDepth); 56 pseudo_stack_.reserve(kMaxStackDepth);
55 task_contexts_.reserve(kMaxTaskDepth); 57 task_contexts_.reserve(kMaxTaskDepth);
56 } 58 }
57 AllocationContextTracker::~AllocationContextTracker() {} 59 AllocationContextTracker::~AllocationContextTracker() {}
58 60
59 // static 61 // static
60 void AllocationContextTracker::SetCurrentThreadName(const char* name) { 62 void AllocationContextTracker::SetCurrentThreadName(const char* name) {
61 if (name && capture_enabled()) { 63 if (name && capture_enabled()) {
62 GetInstanceForCurrentThread()->thread_name_ = name; 64 GetInstanceForCurrentThread()->thread_name_ = name;
63 } 65 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 void AllocationContextTracker::PopCurrentTaskContext(const char* context) { 114 void AllocationContextTracker::PopCurrentTaskContext(const char* context) {
113 DCHECK_EQ(context, task_contexts_.back()) 115 DCHECK_EQ(context, task_contexts_.back())
114 << "Encountered an unmatched context end"; 116 << "Encountered an unmatched context end";
115 task_contexts_.pop_back(); 117 task_contexts_.pop_back();
116 } 118 }
117 119
118 // static 120 // static
119 AllocationContext AllocationContextTracker::GetContextSnapshot() { 121 AllocationContext AllocationContextTracker::GetContextSnapshot() {
120 AllocationContext ctx; 122 AllocationContext ctx;
121 123
124 if (ignore_scope_depth_) {
Primiano Tucci (use gerrit) 2016/04/21 19:47:31 This file doesn't seem rebased. The ToT code is di
ssid 2016/04/22 04:57:12 Done.
125 ctx.backtrace.frames[0] = kTracingOverhead;
126 ctx.type_name = kTracingOverhead;
127 return ctx;
128 }
129
122 // Fill the backtrace. 130 // Fill the backtrace.
123 { 131 {
124 auto src = pseudo_stack_.begin(); 132 auto src = pseudo_stack_.begin();
125 auto dst = std::begin(ctx.backtrace.frames); 133 auto dst = std::begin(ctx.backtrace.frames);
126 auto src_end = pseudo_stack_.end(); 134 auto src_end = pseudo_stack_.end();
127 auto dst_end = std::end(ctx.backtrace.frames); 135 auto dst_end = std::end(ctx.backtrace.frames);
128 136
129 // Add the thread name as the first enrty in the backtrace. 137 // Add the thread name as the first enrty in the backtrace.
130 if (thread_name_) { 138 if (thread_name_) {
131 DCHECK(dst < dst_end); 139 DCHECK(dst < dst_end);
(...skipping 12 matching lines...) Expand all
144 152
145 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension 153 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension
146 // (component name) in the heap profiler and not piggy back on the type name. 154 // (component name) in the heap profiler and not piggy back on the type name.
147 ctx.type_name = task_contexts_.empty() ? nullptr : task_contexts_.back(); 155 ctx.type_name = task_contexts_.empty() ? nullptr : task_contexts_.back();
148 156
149 return ctx; 157 return ctx;
150 } 158 }
151 159
152 } // namespace trace_event 160 } // namespace trace_event
153 } // namespace base 161 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698