Chromium Code Reviews| Index: base/trace_event/memory_profiler_allocation_context.cc |
| diff --git a/base/trace_event/memory_profiler_allocation_context.cc b/base/trace_event/memory_profiler_allocation_context.cc |
| index 3aea93518c633aa667d1b21f0ff028ce1f117819..c1397dff7971c7b1197d9ca83466b9465f473d8c 100644 |
| --- a/base/trace_event/memory_profiler_allocation_context.cc |
| +++ b/base/trace_event/memory_profiler_allocation_context.cc |
| @@ -75,16 +75,52 @@ void AllocationContextTracker::UnsetContextField(const char* key) { |
| tracker->context_.erase(key); |
| } |
| -// static |
| -AllocationStack* AllocationContextTracker::GetPseudoStackForTesting() { |
| - auto tracker = AllocationContextTracker::GetThreadLocalTracker(); |
| - return &tracker->pseudo_stack_; |
| +// Returns a pointer past the end of the fixed-size array |array| of |T| of |
| +// length |N|, identical to C++11 |std::end|. |
| +template <typename T, int N> |
| +const T* End(const T(&array)[N]) { |
| + return array + N; |
| } |
| // static |
| AllocationContext AllocationContextTracker::GetContext() { |
| - // TODO(ruuda): Implement this in a follow-up CL. |
| - return AllocationContext(); |
| + auto tracker = GetThreadLocalTracker(); |
| + AllocationContext ctx; |
| + |
| + // Fill the backtrace. |
| + { |
| + auto src = tracker->pseudo_stack_.top(); |
| + auto dst = ctx.backtrace; |
| + auto src_end = tracker->pseudo_stack_.bottom(); |
| + auto dst_end = End(ctx.backtrace); |
| + |
| + // Copy as much of the top of the pseudo stack into the backtrace as |
| + // possible. |
| + for (; src != src_end && dst != dst_end; src++, dst++) |
| + *dst = *src; |
| + |
| + // If there is room for more, fill the remaining slots with empty frames. |
| + for (; dst != dst_end; dst++) |
| + *dst = nullptr; |
|
picksi
2015/09/25 09:44:35
Q:Is the performance overhead for clearing all the
Ruud van Asseldonk
2015/09/25 11:46:19
It would, but I am not sure how that would affect
picksi
2015/09/25 12:31:26
No, leave it as it is! You make some good points :
|
| + } |
| + |
| + // Fill the context fields. |
| + { |
| + auto src = tracker->context_.begin(); |
| + auto dst = ctx.fields; |
| + auto src_end = tracker->context_.end(); |
| + auto dst_end = End(ctx.fields); |
| + |
| + // Copy as much (key, value) pairs as possible. |
| + for (; src != src_end && dst != dst_end; src++, dst++) |
| + *dst = *src; |
|
picksi
2015/09/25 09:44:35
nit: This code is duplicated from 99-100, should i
Ruud van Asseldonk
2015/09/25 11:46:19
Ideally there would be an |std::copy| that copies
|
| + |
| + // If there is room for more, fill the remaining slots with nullptr keys. |
| + for (; dst != dst_end; dst++) |
| + dst->first = nullptr; |
| + } |
| + |
| + return ctx; |
| } |
| } // namespace trace_event |