Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: base/trace_event/memory_profiler_allocation_context.cc

Issue 1372523002: [tracing] Implement trace_event::AllocationContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@alloccontext
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory_profiler_allocation_context.h" 5 #include "base/trace_event/memory_profiler_allocation_context.h"
6 6
7 #include "base/threading/thread_local_storage.h" 7 #include "base/threading/thread_local_storage.h"
8 8
9 namespace base { 9 namespace base {
10 namespace trace_event { 10 namespace trace_event {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 auto tracker = AllocationContextTracker::GetThreadLocalTracker(); 68 auto tracker = AllocationContextTracker::GetThreadLocalTracker();
69 tracker->context_[key] = value; 69 tracker->context_[key] = value;
70 } 70 }
71 71
72 // static 72 // static
73 void AllocationContextTracker::UnsetContextField(const char* key) { 73 void AllocationContextTracker::UnsetContextField(const char* key) {
74 auto tracker = AllocationContextTracker::GetThreadLocalTracker(); 74 auto tracker = AllocationContextTracker::GetThreadLocalTracker();
75 tracker->context_.erase(key); 75 tracker->context_.erase(key);
76 } 76 }
77 77
78 // static 78 // Returns a pointer past the end of the fixed-size array |array| of |T| of
79 AllocationStack* AllocationContextTracker::GetPseudoStackForTesting() { 79 // length |N|, identical to C++11 |std::end|.
80 auto tracker = AllocationContextTracker::GetThreadLocalTracker(); 80 template <typename T, int N>
81 return &tracker->pseudo_stack_; 81 const T* End(const T(&array)[N]) {
82 return array + N;
82 } 83 }
83 84
84 // static 85 // static
85 AllocationContext AllocationContextTracker::GetContext() { 86 AllocationContext AllocationContextTracker::GetContext() {
86 // TODO(ruuda): Implement this in a follow-up CL. 87 auto tracker = GetThreadLocalTracker();
87 return AllocationContext(); 88 AllocationContext ctx;
89
90 // Fill the backtrace.
91 {
92 auto src = tracker->pseudo_stack_.top();
93 auto dst = ctx.backtrace;
94 auto src_end = tracker->pseudo_stack_.bottom();
95 auto dst_end = End(ctx.backtrace);
96
97 // Copy as much of the top of the pseudo stack into the backtrace as
98 // possible.
99 for (; src != src_end && dst != dst_end; src++, dst++)
100 *dst = *src;
101
102 // If there is room for more, fill the remaining slots with empty frames.
103 for (; dst != dst_end; dst++)
104 *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 :
105 }
106
107 // Fill the context fields.
108 {
109 auto src = tracker->context_.begin();
110 auto dst = ctx.fields;
111 auto src_end = tracker->context_.end();
112 auto dst_end = End(ctx.fields);
113
114 // Copy as much (key, value) pairs as possible.
115 for (; src != src_end && dst != dst_end; src++, dst++)
116 *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
117
118 // If there is room for more, fill the remaining slots with nullptr keys.
119 for (; dst != dst_end; dst++)
120 dst->first = nullptr;
121 }
122
123 return ctx;
88 } 124 }
89 125
90 } // namespace trace_event 126 } // namespace trace_event
91 } // namespace base 127 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_profiler_allocation_context.h ('k') | base/trace_event/memory_profiler_allocation_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698