| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 ignore_scope_depth_--; | 176 ignore_scope_depth_--; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Add the thread name as the first entry in pseudo stack. | 179 // Add the thread name as the first entry in pseudo stack. |
| 180 if (thread_name_) { | 180 if (thread_name_) { |
| 181 *backtrace++ = StackFrame::FromThreadName(thread_name_); | 181 *backtrace++ = StackFrame::FromThreadName(thread_name_); |
| 182 } | 182 } |
| 183 | 183 |
| 184 switch (mode) { | 184 switch (mode) { |
| 185 case CaptureMode::DISABLED: | 185 case CaptureMode::DISABLED: |
| 186 { | 186 case CaptureMode::BACKGROUND: |
| 187 break; | 187 break; |
| 188 } | |
| 189 case CaptureMode::PSEUDO_STACK: | 188 case CaptureMode::PSEUDO_STACK: |
| 190 { | |
| 191 for (const PseudoStackFrame& stack_frame : pseudo_stack_) { | 189 for (const PseudoStackFrame& stack_frame : pseudo_stack_) { |
| 192 if (backtrace == backtrace_end) { | 190 if (backtrace == backtrace_end) { |
| 193 break; | 191 break; |
| 194 } | 192 } |
| 195 *backtrace++ = | 193 *backtrace++ = |
| 196 StackFrame::FromTraceEventName(stack_frame.trace_event_name); | 194 StackFrame::FromTraceEventName(stack_frame.trace_event_name); |
| 197 } | 195 } |
| 198 break; | 196 break; |
| 199 } | |
| 200 case CaptureMode::NATIVE_STACK: | 197 case CaptureMode::NATIVE_STACK: |
| 201 { | |
| 202 // Backtrace contract requires us to return bottom frames, i.e. | 198 // Backtrace contract requires us to return bottom frames, i.e. |
| 203 // from main() and up. Stack unwinding produces top frames, i.e. | 199 // from main() and up. Stack unwinding produces top frames, i.e. |
| 204 // from this point and up until main(). We request many frames to | 200 // 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. | 201 // make sure we reach main(), and then copy bottom portion of them. |
| 206 const void* frames[128]; | 202 const void* frames[128]; |
| 207 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, | 203 static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount, |
| 208 "not requesting enough frames to fill Backtrace"); | 204 "not requesting enough frames to fill Backtrace"); |
| 209 #if HAVE_TRACE_STACK_FRAME_POINTERS && !defined(OS_NACL) | 205 #if HAVE_TRACE_STACK_FRAME_POINTERS && !defined(OS_NACL) |
| 210 size_t frame_count = debug::TraceStackFramePointers( | 206 size_t frame_count = debug::TraceStackFramePointers( |
| 211 frames, | 207 frames, |
| 212 arraysize(frames), | 208 arraysize(frames), |
| 213 1 /* exclude this function from the trace */ ); | 209 1 /* exclude this function from the trace */ ); |
| 214 #else | 210 #else |
| 215 size_t frame_count = 0; | 211 size_t frame_count = 0; |
| 216 NOTREACHED(); | 212 NOTREACHED(); |
| 217 #endif | 213 #endif |
| 218 | 214 |
| 219 // Copy frames backwards | 215 // Copy frames backwards |
| 220 size_t backtrace_capacity = backtrace_end - backtrace; | 216 size_t backtrace_capacity = backtrace_end - backtrace; |
| 221 int32_t top_frame_index = (backtrace_capacity >= frame_count) | 217 int32_t top_frame_index = (backtrace_capacity >= frame_count) |
| 222 ? 0 | 218 ? 0 |
| 223 : frame_count - backtrace_capacity; | 219 : frame_count - backtrace_capacity; |
| 224 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { | 220 for (int32_t i = frame_count - 1; i >= top_frame_index; --i) { |
| 225 const void* frame = frames[i]; | 221 const void* frame = frames[i]; |
| 226 *backtrace++ = StackFrame::FromProgramCounter(frame); | 222 *backtrace++ = StackFrame::FromProgramCounter(frame); |
| 227 } | 223 } |
| 228 break; | 224 break; |
| 229 } | |
| 230 } | 225 } |
| 231 | 226 |
| 232 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); | 227 ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); |
| 233 | 228 |
| 234 // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension | 229 // 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. | 230 // (component name) in the heap profiler and not piggy back on the type name. |
| 236 if (!task_contexts_.empty()) { | 231 if (!task_contexts_.empty()) { |
| 237 ctx->type_name = task_contexts_.back(); | 232 ctx->type_name = task_contexts_.back(); |
| 238 } else if (!pseudo_stack_.empty()) { | 233 } else if (!pseudo_stack_.empty()) { |
| 239 // If task context was unavailable, then the category names are taken from | 234 // If task context was unavailable, then the category names are taken from |
| 240 // trace events. | 235 // trace events. |
| 241 ctx->type_name = pseudo_stack_.back().trace_event_category; | 236 ctx->type_name = pseudo_stack_.back().trace_event_category; |
| 242 } else { | 237 } else { |
| 243 ctx->type_name = nullptr; | 238 ctx->type_name = nullptr; |
| 244 } | 239 } |
| 245 | 240 |
| 246 return true; | 241 return true; |
| 247 } | 242 } |
| 248 | 243 |
| 249 } // namespace trace_event | 244 } // namespace trace_event |
| 250 } // namespace base | 245 } // namespace base |
| OLD | NEW |