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

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

Issue 2757123002: Cleaner fall-back stack capture for --enable-heap-profiling=native. (Closed)
Patch Set: Revert to non-function-style macro Created 3 years, 9 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 | « base/debug/stack_trace_unittest.cc ('k') | base/trace_event/memory_dump_manager.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"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 StackFrame::FromTraceEventName(stack_frame.trace_event_name); 196 StackFrame::FromTraceEventName(stack_frame.trace_event_name);
197 } 197 }
198 break; 198 break;
199 } 199 }
200 case CaptureMode::NATIVE_STACK: 200 case CaptureMode::NATIVE_STACK:
201 { 201 {
202 // Backtrace contract requires us to return bottom frames, i.e. 202 // Backtrace contract requires us to return bottom frames, i.e.
203 // from main() and up. Stack unwinding produces top frames, i.e. 203 // from main() and up. Stack unwinding produces top frames, i.e.
204 // from this point and up until main(). We request many frames to 204 // from this point and up until main(). We request many frames to
205 // make sure we reach main(), and then copy bottom portion of them. 205 // make sure we reach main(), and then copy bottom portion of them.
206 const void* frames[128]; 206 #if !defined(OS_NACL) // We don't build base/debug/stack_trace.cc for NaCl.
207 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, 207 #if HAVE_TRACE_STACK_FRAME_POINTERS
208 "not requesting enough frames to fill Backtrace"); 208 const void* frames[128];
209 #if HAVE_TRACE_STACK_FRAME_POINTERS && !defined(OS_NACL) 209 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount,
210 size_t frame_count = debug::TraceStackFramePointers( 210 "not requesting enough frames to fill Backtrace");
211 frames, 211 size_t frame_count = debug::TraceStackFramePointers(
212 arraysize(frames), 212 frames, arraysize(frames),
213 1 /* exclude this function from the trace */ ); 213 1 /* exclude this function from the trace */);
214 #else 214 #else // HAVE_TRACE_STACK_FRAME_POINTERS
215 size_t frame_count = 0; 215 // Fall-back to capturing the stack with base::debug::StackTrace,
216 NOTREACHED(); 216 // which is likely slower, but more reliable.
217 #endif 217 base::debug::StackTrace stack_trace(Backtrace::kMaxFrameCount);
218 size_t frame_count = 0u;
219 const void* const* frames = stack_trace.Addresses(&frame_count);
dcheng 2017/03/28 06:16:23 Nit: this will capture the constructor for StackTr
Wez 2017/03/28 06:38:21 That is a fair point; it doesn't affect the functi
220 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
218 221
219 // Copy frames backwards 222 // Copy frames backwards
220 size_t backtrace_capacity = backtrace_end - backtrace; 223 size_t backtrace_capacity = backtrace_end - backtrace;
221 int32_t top_frame_index = (backtrace_capacity >= frame_count) 224 int32_t top_frame_index = (backtrace_capacity >= frame_count)
222 ? 0 225 ? 0
223 : frame_count - backtrace_capacity; 226 : frame_count - backtrace_capacity;
224 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { 227 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) {
225 const void* frame = frames[i]; 228 const void* frame = frames[i];
226 *backtrace++ = StackFrame::FromProgramCounter(frame); 229 *backtrace++ = StackFrame::FromProgramCounter(frame);
227 }
228 break;
229 } 230 }
231 #endif // !defined(OS_NACL)
232 break;
233 }
230 } 234 }
231 235
232 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); 236 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames);
233 237
234 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension 238 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension
235 // (component name) in the heap profiler and not piggy back on the type name. 239 // (component name) in the heap profiler and not piggy back on the type name.
236 if (!task_contexts_.empty()) { 240 if (!task_contexts_.empty()) {
237 ctx->type_name = task_contexts_.back(); 241 ctx->type_name = task_contexts_.back();
238 } else if (!pseudo_stack_.empty()) { 242 } else if (!pseudo_stack_.empty()) {
239 // If task context was unavailable, then the category names are taken from 243 // If task context was unavailable, then the category names are taken from
240 // trace events. 244 // trace events.
241 ctx->type_name = pseudo_stack_.back().trace_event_category; 245 ctx->type_name = pseudo_stack_.back().trace_event_category;
242 } else { 246 } else {
243 ctx->type_name = nullptr; 247 ctx->type_name = nullptr;
244 } 248 }
245 249
246 return true; 250 return true;
247 } 251 }
248 252
249 } // namespace trace_event 253 } // namespace trace_event
250 } // namespace base 254 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/stack_trace_unittest.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698