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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #if !defined(OS_NACL) // We don't build base/debug/stack_trace.cc for NaCl. | 206 const void* frames[128]; |
207 #if HAVE_TRACE_STACK_FRAME_POINTERS | 207 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, |
208 const void* frames[128]; | 208 "not requesting enough frames to fill Backtrace"); |
209 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, | 209 #if HAVE_TRACE_STACK_FRAME_POINTERS && !defined(OS_NACL) |
210 "not requesting enough frames to fill Backtrace"); | 210 size_t frame_count = debug::TraceStackFramePointers( |
211 size_t frame_count = debug::TraceStackFramePointers( | 211 frames, |
212 frames, arraysize(frames), | 212 arraysize(frames), |
213 1 /* exclude this function from the trace */); | 213 1 /* exclude this function from the trace */ ); |
214 #else // HAVE_TRACE_STACK_FRAME_POINTERS | 214 #else |
215 // Fall-back to capturing the stack with base::debug::StackTrace, | 215 size_t frame_count = 0; |
216 // which is likely slower, but more reliable. | 216 NOTREACHED(); |
217 base::debug::StackTrace stack_trace(Backtrace::kMaxFrameCount); | 217 #endif |
218 size_t frame_count = 0u; | |
219 const void* const* frames = stack_trace.Addresses(&frame_count); | |
220 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | |
221 | 218 |
222 // Copy frames backwards | 219 // Copy frames backwards |
223 size_t backtrace_capacity = backtrace_end - backtrace; | 220 size_t backtrace_capacity = backtrace_end - backtrace; |
224 int32_t top_frame_index = (backtrace_capacity >= frame_count) | 221 int32_t top_frame_index = (backtrace_capacity >= frame_count) |
225 ? 0 | 222 ? 0 |
226 : frame_count - backtrace_capacity; | 223 : frame_count - backtrace_capacity; |
227 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { | 224 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { |
228 const void* frame = frames[i]; | 225 const void* frame = frames[i]; |
229 *backtrace++ = StackFrame::FromProgramCounter(frame); | 226 *backtrace++ = StackFrame::FromProgramCounter(frame); |
| 227 } |
| 228 break; |
230 } | 229 } |
231 #endif // !defined(OS_NACL) | |
232 break; | |
233 } | |
234 } | 230 } |
235 | 231 |
236 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); | 232 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); |
237 | 233 |
238 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension | 234 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension |
239 // (component name) in the heap profiler and not piggy back on the type name. | 235 // (component name) in the heap profiler and not piggy back on the type name. |
240 if (!task_contexts_.empty()) { | 236 if (!task_contexts_.empty()) { |
241 ctx->type_name = task_contexts_.back(); | 237 ctx->type_name = task_contexts_.back(); |
242 } else if (!pseudo_stack_.empty()) { | 238 } else if (!pseudo_stack_.empty()) { |
243 // If task context was unavailable, then the category names are taken from | 239 // If task context was unavailable, then the category names are taken from |
244 // trace events. | 240 // trace events. |
245 ctx->type_name = pseudo_stack_.back().trace_event_category; | 241 ctx->type_name = pseudo_stack_.back().trace_event_category; |
246 } else { | 242 } else { |
247 ctx->type_name = nullptr; | 243 ctx->type_name = nullptr; |
248 } | 244 } |
249 | 245 |
250 return true; | 246 return true; |
251 } | 247 } |
252 | 248 |
253 } // namespace trace_event | 249 } // namespace trace_event |
254 } // namespace base | 250 } // namespace base |
OLD | NEW |