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

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

Issue 1471683002: [StyleGuide] Allow begin and end non-member functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add link to discussion thread Created 5 years, 1 month 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
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 9
9 #include "base/atomicops.h" 10 #include "base/atomicops.h"
10 #include "base/threading/thread_local_storage.h" 11 #include "base/threading/thread_local_storage.h"
11 #include "base/trace_event/heap_profiler_allocation_context.h" 12 #include "base/trace_event/heap_profiler_allocation_context.h"
12 13
13 namespace base { 14 namespace base {
14 namespace trace_event { 15 namespace trace_event {
15 16
16 subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0; 17 subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0;
17 18
18 namespace { 19 namespace {
19 20
20 ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER; 21 ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER;
21 22
22 // This function is added to the TLS slot to clean up the instance when the 23 // This function is added to the TLS slot to clean up the instance when the
23 // thread exits. 24 // thread exits.
24 void DestructAllocationContextTracker(void* alloc_ctx_tracker) { 25 void DestructAllocationContextTracker(void* alloc_ctx_tracker) {
25 delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker); 26 delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker);
26 } 27 }
27 28
28 // Returns a pointer past the end of the fixed-size array |array| of |T| of
29 // length |N|, identical to C++11 |std::end|.
30 template <typename T, int N>
31 T* End(T(&array)[N]) {
32 return array + N;
33 }
34
35 } // namespace 29 } // namespace
36 30
37 AllocationContextTracker::AllocationContextTracker() {} 31 AllocationContextTracker::AllocationContextTracker() {}
38 AllocationContextTracker::~AllocationContextTracker() {} 32 AllocationContextTracker::~AllocationContextTracker() {}
39 33
40 // static 34 // static
41 AllocationContextTracker* AllocationContextTracker::GetThreadLocalTracker() { 35 AllocationContextTracker* AllocationContextTracker::GetThreadLocalTracker() {
42 auto tracker = 36 auto tracker =
43 static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get()); 37 static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get());
44 38
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 86 }
93 87
94 // static 88 // static
95 AllocationContext AllocationContextTracker::GetContextSnapshot() { 89 AllocationContext AllocationContextTracker::GetContextSnapshot() {
96 AllocationContextTracker* tracker = GetThreadLocalTracker(); 90 AllocationContextTracker* tracker = GetThreadLocalTracker();
97 AllocationContext ctx; 91 AllocationContext ctx;
98 92
99 // Fill the backtrace. 93 // Fill the backtrace.
100 { 94 {
101 auto src = tracker->pseudo_stack_.begin(); 95 auto src = tracker->pseudo_stack_.begin();
102 auto dst = ctx.backtrace.frames; 96 auto dst = std::begin(ctx.backtrace.frames);
103 auto src_end = tracker->pseudo_stack_.end(); 97 auto src_end = tracker->pseudo_stack_.end();
104 auto dst_end = End(ctx.backtrace.frames); 98 auto dst_end = std::end(ctx.backtrace.frames);
105 99
106 // Copy as much of the bottom of the pseudo stack into the backtrace as 100 // Copy as much of the bottom of the pseudo stack into the backtrace as
107 // possible. 101 // possible.
108 for (; src != src_end && dst != dst_end; src++, dst++) 102 for (; src != src_end && dst != dst_end; src++, dst++)
109 *dst = *src; 103 *dst = *src;
110 104
111 // If there is room for more, fill the remaining slots with empty frames. 105 // If there is room for more, fill the remaining slots with empty frames.
112 std::fill(dst, dst_end, nullptr); 106 std::fill(dst, dst_end, nullptr);
113 } 107 }
114 108
115 ctx.type_id = 0; 109 ctx.type_id = 0;
116 110
117 return ctx; 111 return ctx;
118 } 112 }
119 113
120 } // namespace trace_event 114 } // namespace trace_event
121 } // namespace base 115 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698