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/trace_event/trace_event_synthetic_delay.h" | 6 #include "base/trace_event/trace_event_synthetic_delay.h" |
7 | 7 |
8 namespace { | 8 namespace { |
9 const int kMaxSyntheticDelays = 32; | 9 const int kMaxSyntheticDelays = 32; |
10 } // namespace | 10 } // namespace |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace debug { | 13 namespace trace_event { |
14 | 14 |
15 TraceEventSyntheticDelayClock::TraceEventSyntheticDelayClock() {} | 15 TraceEventSyntheticDelayClock::TraceEventSyntheticDelayClock() {} |
16 TraceEventSyntheticDelayClock::~TraceEventSyntheticDelayClock() {} | 16 TraceEventSyntheticDelayClock::~TraceEventSyntheticDelayClock() {} |
17 | 17 |
18 class TraceEventSyntheticDelayRegistry : public TraceEventSyntheticDelayClock { | 18 class TraceEventSyntheticDelayRegistry : public TraceEventSyntheticDelayClock { |
19 public: | 19 public: |
20 static TraceEventSyntheticDelayRegistry* GetInstance(); | 20 static TraceEventSyntheticDelayRegistry* GetInstance(); |
21 | 21 |
22 TraceEventSyntheticDelay* GetOrCreateDelay(const char* name); | 22 TraceEventSyntheticDelay* GetOrCreateDelay(const char* name); |
23 void ResetAllDelays(); | 23 void ResetAllDelays(); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 for (int i = 0; i < delay_count; ++i) { | 193 for (int i = 0; i < delay_count; ++i) { |
194 delays_[i].SetTargetDuration(base::TimeDelta()); | 194 delays_[i].SetTargetDuration(base::TimeDelta()); |
195 delays_[i].SetClock(this); | 195 delays_[i].SetClock(this); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 void ResetTraceEventSyntheticDelays() { | 199 void ResetTraceEventSyntheticDelays() { |
200 TraceEventSyntheticDelayRegistry::GetInstance()->ResetAllDelays(); | 200 TraceEventSyntheticDelayRegistry::GetInstance()->ResetAllDelays(); |
201 } | 201 } |
202 | 202 |
203 } // namespace debug | 203 } // namespace trace_event |
204 } // namespace base | 204 } // namespace base |
205 | 205 |
206 namespace trace_event_internal { | 206 namespace trace_event_internal { |
207 | 207 |
208 ScopedSyntheticDelay::ScopedSyntheticDelay(const char* name, | 208 ScopedSyntheticDelay::ScopedSyntheticDelay(const char* name, |
209 base::subtle::AtomicWord* impl_ptr) | 209 base::subtle::AtomicWord* impl_ptr) |
210 : delay_impl_(GetOrCreateDelay(name, impl_ptr)) { | 210 : delay_impl_(GetOrCreateDelay(name, impl_ptr)) { |
211 delay_impl_->BeginParallel(&end_time_); | 211 delay_impl_->BeginParallel(&end_time_); |
212 } | 212 } |
213 | 213 |
214 ScopedSyntheticDelay::~ScopedSyntheticDelay() { | 214 ScopedSyntheticDelay::~ScopedSyntheticDelay() { |
215 delay_impl_->EndParallel(end_time_); | 215 delay_impl_->EndParallel(end_time_); |
216 } | 216 } |
217 | 217 |
218 base::debug::TraceEventSyntheticDelay* GetOrCreateDelay( | 218 base::trace_event::TraceEventSyntheticDelay* GetOrCreateDelay( |
219 const char* name, | 219 const char* name, |
220 base::subtle::AtomicWord* impl_ptr) { | 220 base::subtle::AtomicWord* impl_ptr) { |
221 base::debug::TraceEventSyntheticDelay* delay_impl = | 221 base::trace_event::TraceEventSyntheticDelay* delay_impl = |
222 reinterpret_cast<base::debug::TraceEventSyntheticDelay*>( | 222 reinterpret_cast<base::trace_event::TraceEventSyntheticDelay*>( |
223 base::subtle::Acquire_Load(impl_ptr)); | 223 base::subtle::Acquire_Load(impl_ptr)); |
224 if (!delay_impl) { | 224 if (!delay_impl) { |
225 delay_impl = base::debug::TraceEventSyntheticDelayRegistry::GetInstance() | 225 delay_impl = |
226 ->GetOrCreateDelay(name); | 226 base::trace_event::TraceEventSyntheticDelayRegistry::GetInstance() |
| 227 ->GetOrCreateDelay(name); |
227 base::subtle::Release_Store( | 228 base::subtle::Release_Store( |
228 impl_ptr, reinterpret_cast<base::subtle::AtomicWord>(delay_impl)); | 229 impl_ptr, reinterpret_cast<base::subtle::AtomicWord>(delay_impl)); |
229 } | 230 } |
230 return delay_impl; | 231 return delay_impl; |
231 } | 232 } |
232 | 233 |
233 } // namespace trace_event_internal | 234 } // namespace trace_event_internal |
OLD | NEW |