Chromium Code Reviews| Index: base/trace_event/heap_profiler_allocation_context_tracker.cc |
| diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.cc b/base/trace_event/heap_profiler_allocation_context_tracker.cc |
| index 2877d2af91b27ace28839ebaac7468322cf4823f..0aa54a84ed380f8ee7e8f669bd78532041943e14 100644 |
| --- a/base/trace_event/heap_profiler_allocation_context_tracker.cc |
| +++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc |
| @@ -49,12 +49,19 @@ AllocationContextTracker::GetInstanceForCurrentThread() { |
| return tracker; |
| } |
| -AllocationContextTracker::AllocationContextTracker() { |
| +AllocationContextTracker::AllocationContextTracker() : thread_name_(nullptr) { |
| pseudo_stack_.reserve(kMaxStackDepth); |
| } |
| AllocationContextTracker::~AllocationContextTracker() {} |
| // static |
| +void AllocationContextTracker::SetCurrentThreadName(const char* name) { |
| + if (name && capture_enabled()) { |
| + GetInstanceForCurrentThread()->thread_name_ = name; |
| + } |
| +} |
| + |
| +// static |
| void AllocationContextTracker::SetCaptureEnabled(bool enabled) { |
| // When enabling capturing, also initialize the TLS slot. This does not create |
| // a TLS instance yet. |
| @@ -103,6 +110,12 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() { |
| auto src_end = pseudo_stack_.end(); |
| auto dst_end = std::end(ctx.backtrace.frames); |
| + // Add the thread name as the first enrty in the backtrace. |
| + if (thread_name_) { |
| + *dst = thread_name_; |
|
petrcermak
2016/03/29 13:07:46
I think that you should DCHECK that dst < dst_end
ssid
2016/03/29 18:19:11
Done.
|
| + ++dst; |
| + } |
| + |
| // Copy as much of the bottom of the pseudo stack into the backtrace as |
| // possible. |
| for (; src != src_end && dst != dst_end; src++, dst++) |