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