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/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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 StackFrame::FromTraceEventName(stack_frame.trace_event_name); | 197 StackFrame::FromTraceEventName(stack_frame.trace_event_name); |
198 } | 198 } |
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. | |
208 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) | |
207 const void* frames[128]; | 209 const void* frames[128]; |
208 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, | 210 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, |
209 "not requesting enough frames to fill Backtrace"); | 211 "not requesting enough frames to fill Backtrace"); |
210 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) && !defined(OS_NACL) | |
211 size_t frame_count = debug::TraceStackFramePointers( | 212 size_t frame_count = debug::TraceStackFramePointers( |
212 frames, | 213 frames, arraysize(frames), |
213 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 | 216 // Fall-back to capturing the stack with base::debug::StackTrace, |
216 size_t frame_count = 0; | 217 // which is likely slower, but more reliable. |
217 NOTREACHED(); | 218 base::debug::StackTrace stack_trace(Backtrace::kMaxFrameCount); |
218 #endif | 219 size_t frame_count = 0u; |
220 const void* const* frames = stack_trace.Addresses(&frame_count); | |
221 #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) | |
219 | 222 |
220 // Copy frames backwards | 223 // Copy frames backwards |
221 size_t backtrace_capacity = backtrace_end - backtrace; | 224 size_t backtrace_capacity = backtrace_end - backtrace; |
222 int32_t top_frame_index = (backtrace_capacity >= frame_count) | 225 int32_t top_frame_index = (backtrace_capacity >= frame_count) |
223 ? 0 | 226 ? 0 |
224 : frame_count - backtrace_capacity; | 227 : frame_count - backtrace_capacity; |
225 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { | 228 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { |
226 const void* frame = frames[i]; | 229 const void* frame = frames[i]; |
227 *backtrace++ = StackFrame::FromProgramCounter(frame); | 230 *backtrace++ = StackFrame::FromProgramCounter(frame); |
228 } | 231 } |
232 #endif // !defined(OS_NACL) | |
erikchen
2017/04/07 01:47:43
hm. Any reason you moved this #endif?
Wez
2017/04/08 00:11:32
Moving the #endif means not having to have a dummy
| |
229 break; | 233 break; |
230 } | 234 } |
231 } | 235 } |
232 | 236 |
233 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); | 237 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); |
234 | 238 |
235 // 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 |
236 // (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. |
237 if (!task_contexts_.empty()) { | 241 if (!task_contexts_.empty()) { |
238 ctx->type_name = task_contexts_.back(); | 242 ctx->type_name = task_contexts_.back(); |
239 } else if (!pseudo_stack_.empty()) { | 243 } else if (!pseudo_stack_.empty()) { |
240 // 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 |
241 // trace events. | 245 // trace events. |
242 ctx->type_name = pseudo_stack_.back().trace_event_category; | 246 ctx->type_name = pseudo_stack_.back().trace_event_category; |
243 } else { | 247 } else { |
244 ctx->type_name = nullptr; | 248 ctx->type_name = nullptr; |
245 } | 249 } |
246 | 250 |
247 return true; | 251 return true; |
248 } | 252 } |
249 | 253 |
250 } // namespace trace_event | 254 } // namespace trace_event |
251 } // namespace base | 255 } // namespace base |
OLD | NEW |