OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/memory/singleton.h" | 5 #include "base/memory/singleton.h" |
6 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 6 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
7 #include "base/trace_event/trace_event_synthetic_delay.h" | 7 #include "base/trace_event/trace_event_synthetic_delay.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 const int kMaxSyntheticDelays = 32; | 10 const int kMaxSyntheticDelays = 32; |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 TraceEventSyntheticDelay* GetOrCreateDelay(const char* name); | 23 TraceEventSyntheticDelay* GetOrCreateDelay(const char* name); |
24 void ResetAllDelays(); | 24 void ResetAllDelays(); |
25 | 25 |
26 // TraceEventSyntheticDelayClock implementation. | 26 // TraceEventSyntheticDelayClock implementation. |
27 base::TimeTicks Now() override; | 27 base::TimeTicks Now() override; |
28 | 28 |
29 private: | 29 private: |
30 TraceEventSyntheticDelayRegistry(); | 30 TraceEventSyntheticDelayRegistry(); |
31 | 31 |
32 friend struct DefaultSingletonTraits<TraceEventSyntheticDelayRegistry>; | 32 friend struct base::DefaultSingletonTraits<TraceEventSyntheticDelayRegistry>; |
33 | 33 |
34 Lock lock_; | 34 Lock lock_; |
35 TraceEventSyntheticDelay delays_[kMaxSyntheticDelays]; | 35 TraceEventSyntheticDelay delays_[kMaxSyntheticDelays]; |
36 TraceEventSyntheticDelay dummy_delay_; | 36 TraceEventSyntheticDelay dummy_delay_; |
37 base::subtle::Atomic32 delay_count_; | 37 base::subtle::Atomic32 delay_count_; |
38 | 38 |
39 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayRegistry); | 39 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayRegistry); |
40 }; | 40 }; |
41 | 41 |
42 TraceEventSyntheticDelay::TraceEventSyntheticDelay() | 42 TraceEventSyntheticDelay::TraceEventSyntheticDelay() |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 void TraceEventSyntheticDelay::ApplyDelay(base::TimeTicks end_time) { | 143 void TraceEventSyntheticDelay::ApplyDelay(base::TimeTicks end_time) { |
144 TRACE_EVENT0("synthetic_delay", name_.c_str()); | 144 TRACE_EVENT0("synthetic_delay", name_.c_str()); |
145 while (clock_->Now() < end_time) { | 145 while (clock_->Now() < end_time) { |
146 // Busy loop. | 146 // Busy loop. |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 TraceEventSyntheticDelayRegistry* | 150 TraceEventSyntheticDelayRegistry* |
151 TraceEventSyntheticDelayRegistry::GetInstance() { | 151 TraceEventSyntheticDelayRegistry::GetInstance() { |
152 return Singleton< | 152 return base::Singleton< |
153 TraceEventSyntheticDelayRegistry, | 153 TraceEventSyntheticDelayRegistry, |
154 LeakySingletonTraits<TraceEventSyntheticDelayRegistry> >::get(); | 154 base::LeakySingletonTraits<TraceEventSyntheticDelayRegistry> >::get(); |
155 } | 155 } |
156 | 156 |
157 TraceEventSyntheticDelayRegistry::TraceEventSyntheticDelayRegistry() | 157 TraceEventSyntheticDelayRegistry::TraceEventSyntheticDelayRegistry() |
158 : delay_count_(0) {} | 158 : delay_count_(0) {} |
159 | 159 |
160 TraceEventSyntheticDelay* TraceEventSyntheticDelayRegistry::GetOrCreateDelay( | 160 TraceEventSyntheticDelay* TraceEventSyntheticDelayRegistry::GetOrCreateDelay( |
161 const char* name) { | 161 const char* name) { |
162 // Try to find an existing delay first without locking to make the common case | 162 // Try to find an existing delay first without locking to make the common case |
163 // fast. | 163 // fast. |
164 int delay_count = base::subtle::Acquire_Load(&delay_count_); | 164 int delay_count = base::subtle::Acquire_Load(&delay_count_); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 delay_impl = | 226 delay_impl = |
227 base::trace_event::TraceEventSyntheticDelayRegistry::GetInstance() | 227 base::trace_event::TraceEventSyntheticDelayRegistry::GetInstance() |
228 ->GetOrCreateDelay(name); | 228 ->GetOrCreateDelay(name); |
229 base::subtle::Release_Store( | 229 base::subtle::Release_Store( |
230 impl_ptr, reinterpret_cast<base::subtle::AtomicWord>(delay_impl)); | 230 impl_ptr, reinterpret_cast<base::subtle::AtomicWord>(delay_impl)); |
231 } | 231 } |
232 return delay_impl; | 232 return delay_impl; |
233 } | 233 } |
234 | 234 |
235 } // namespace trace_event_internal | 235 } // namespace trace_event_internal |
OLD | NEW |