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

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

Issue 1958703002: [tracing] Fix mising thread names in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unittest. Created 4 years, 7 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
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(OS_LINUX) || defined(OS_ANDROID)
15 #include <sys/prctl.h>
16 #endif
17
14 namespace base { 18 namespace base {
15 namespace trace_event { 19 namespace trace_event {
16 20
17 subtle::Atomic32 AllocationContextTracker::capture_mode_ = 21 subtle::Atomic32 AllocationContextTracker::capture_mode_ =
18 static_cast<int32_t>(AllocationContextTracker::CaptureMode::DISABLED); 22 static_cast<int32_t>(AllocationContextTracker::CaptureMode::DISABLED);
19 23
20 namespace { 24 namespace {
21 25
22 const size_t kMaxStackDepth = 128u; 26 const size_t kMaxStackDepth = 128u;
23 const size_t kMaxTaskDepth = 16u; 27 const size_t kMaxTaskDepth = 16u;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ctx.backtrace.frame_count = 1; 139 ctx.backtrace.frame_count = 1;
136 return ctx; 140 return ctx;
137 } 141 }
138 142
139 CaptureMode mode = static_cast<CaptureMode>( 143 CaptureMode mode = static_cast<CaptureMode>(
140 subtle::NoBarrier_Load(&capture_mode_)); 144 subtle::NoBarrier_Load(&capture_mode_));
141 145
142 auto backtrace = std::begin(ctx.backtrace.frames); 146 auto backtrace = std::begin(ctx.backtrace.frames);
143 auto backtrace_end = std::end(ctx.backtrace.frames); 147 auto backtrace_end = std::end(ctx.backtrace.frames);
144 148
145 // Add the thread name as the first entry 149 #if defined(OS_LINUX) || defined(OS_ANDROID)
150 // If the thread name is not set, try to get it from prctl. Thread name might
151 // not be set in cases where the thread started before heap profiling was
152 // enabled.
153 if (!thread_name_) {
154 // Ignore the string allocation and allocations from prctl to avoid
Dmitry Skiba 2016/05/13 18:34:06 prctl is a syscall, there can be no reentrancy.
ssid 2016/05/13 20:48:08 Ah yes, I thought it was causing reentrancy too. F
155 // reentrancy.
156 ignore_scope_depth_++;
157 char* leaked_str = new char[16];
158 int err = prctl(PR_GET_NAME, leaked_str);
159 ignore_scope_depth_--;
160
161 if (err) {
162 // Set thread name to "Unknown" so that we call prctl only once per
163 // thread.
164 thread_name_ = "Unknown";
Dmitry Skiba 2016/05/13 18:34:06 Let's format thread id instead. Hmm, and I think s
ssid 2016/05/13 20:48:08 Hm, do you think it is useful to see a thread id i
165 free(leaked_str);
Dmitry Skiba 2016/05/13 18:34:06 Use 'delete []' here since you allocated with new.
ssid 2016/05/13 20:48:09 Yes, fixed.
166 } else {
167 thread_name_ = leaked_str;
168 }
169 }
170 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
171
172 // Add the thread name as the first entry in pseudo stack.
146 if (thread_name_) { 173 if (thread_name_) {
147 *backtrace++ = StackFrame::FromThreadName(thread_name_); 174 *backtrace++ = StackFrame::FromThreadName(thread_name_);
148 } 175 }
149 176
150 switch (mode) { 177 switch (mode) {
151 case CaptureMode::DISABLED: 178 case CaptureMode::DISABLED:
152 { 179 {
153 break; 180 break;
154 } 181 }
155 case CaptureMode::PSEUDO_STACK: 182 case CaptureMode::PSEUDO_STACK:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 225
199 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension 226 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension
200 // (component name) in the heap profiler and not piggy back on the type name. 227 // (component name) in the heap profiler and not piggy back on the type name.
201 ctx.type_name = task_contexts_.empty() ? nullptr : task_contexts_.back(); 228 ctx.type_name = task_contexts_.empty() ? nullptr : task_contexts_.back();
202 229
203 return ctx; 230 return ctx;
204 } 231 }
205 232
206 } // namespace trace_event 233 } // namespace trace_event
207 } // namespace base 234 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698