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

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

Issue 2892273003: Produce more useful stack traces for heap profiling. (Closed)
Patch Set: Created 3 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 | « base/trace_event/heap_profiler_allocation_context.h ('k') | no next file » | 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 break; 199 break;
200 } 200 }
201 case CaptureMode::NATIVE_STACK: 201 case CaptureMode::NATIVE_STACK:
202 { 202 {
203 // Backtrace contract requires us to return bottom frames, i.e. 203 // Backtrace contract requires us to return bottom frames, i.e.
204 // from main() and up. Stack unwinding produces top frames, i.e. 204 // from main() and up. Stack unwinding produces top frames, i.e.
205 // from this point and up until main(). We request many frames to 205 // from this point and up until main(). We request many frames to
206 // make sure we reach main(), and then copy bottom portion of them. 206 // make sure we reach main(), and then copy bottom portion of them.
207 #if !defined(OS_NACL) // We don't build base/debug/stack_trace.cc for NaCl. 207 #if !defined(OS_NACL) // We don't build base/debug/stack_trace.cc for NaCl.
208 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) 208 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
209 const void* frames[128]; 209 const void* frames[Backtrace::kMaxFrameCount];
DmitrySkiba 2017/05/20 00:23:23 Indentation is wrong (same below).
210 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, 210 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount,
211 "not requesting enough frames to fill Backtrace"); 211 "not requesting enough frames to fill Backtrace");
212 size_t frame_count = debug::TraceStackFramePointers( 212 size_t frame_count = debug::TraceStackFramePointers(
213 frames, arraysize(frames), 213 frames, arraysize(frames),
214 1 /* exclude this function from the trace */); 214 1 /* exclude this function from the trace */);
215 #else // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) 215 #else // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
216 // Fall-back to capturing the stack with base::debug::StackTrace, 216 // Fall-back to capturing the stack with base::debug::StackTrace,
217 // which is likely slower, but more reliable. 217 // which is likely slower, but more reliable.
218 base::debug::StackTrace stack_trace(Backtrace::kMaxFrameCount); 218 base::debug::StackTrace stack_trace(Backtrace::kMaxFrameCount);
219 size_t frame_count = 0u; 219 size_t frame_count = 0u;
220 const void* const* frames = stack_trace.Addresses(&frame_count); 220 const void* const* frames = stack_trace.Addresses(&frame_count);
221 #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) 221 #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
222 222
223 // Copy frames backwards 223 // If there are too many frames, keep the ones furthest from main().
224 size_t backtrace_capacity = backtrace_end - backtrace; 224 size_t backtrace_capacity = backtrace_end - backtrace;
225 int32_t top_frame_index = (backtrace_capacity >= frame_count) 225 int32_t starting_frame_index = (backtrace_capacity >= frame_count)
226 ? 0 226 ? frame_count
227 : frame_count - backtrace_capacity; 227 : backtrace_capacity;
228 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { 228 for (int32_t i = starting_frame_index - 1; i >= 0; --i) {
229 const void* frame = frames[i]; 229 const void* frame = frames[i];
230 *backtrace++ = StackFrame::FromProgramCounter(frame); 230 *backtrace++ = StackFrame::FromProgramCounter(frame);
231 } 231 }
232 #endif // !defined(OS_NACL) 232 #endif // !defined(OS_NACL)
233 break; 233 break;
234 } 234 }
235 } 235 }
236 236
237 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); 237 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames);
238 238
239 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension 239 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension
240 // (component name) in the heap profiler and not piggy back on the type name. 240 // (component name) in the heap profiler and not piggy back on the type name.
241 if (!task_contexts_.empty()) { 241 if (!task_contexts_.empty()) {
242 ctx->type_name = task_contexts_.back(); 242 ctx->type_name = task_contexts_.back();
243 } else if (!pseudo_stack_.empty()) { 243 } else if (!pseudo_stack_.empty()) {
244 // If task context was unavailable, then the category names are taken from 244 // If task context was unavailable, then the category names are taken from
245 // trace events. 245 // trace events.
246 ctx->type_name = pseudo_stack_.back().trace_event_category; 246 ctx->type_name = pseudo_stack_.back().trace_event_category;
247 } else { 247 } else {
248 ctx->type_name = nullptr; 248 ctx->type_name = nullptr;
249 } 249 }
250 250
251 return true; 251 return true;
252 } 252 }
253 253
254 } // namespace trace_event 254 } // namespace trace_event
255 } // namespace base 255 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698