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 // The synthetic delay framework makes it possible to dynamically inject | 5 // The synthetic delay framework makes it possible to dynamically inject |
6 // arbitrary delays into into different parts of the codebase. This can be used, | 6 // arbitrary delays into into different parts of the codebase. This can be used, |
7 // for instance, for testing various task scheduling algorithms. | 7 // for instance, for testing various task scheduling algorithms. |
8 // | 8 // |
9 // The delays are specified in terms of a target duration for a given block of | 9 // The delays are specified in terms of a target duration for a given block of |
10 // code. If the code executes faster than the duration, the thread is made to | 10 // code. If the code executes faster than the duration, the thread is made to |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #define TRACE_EVENT_SYNTHETIC_DELAY_END(name) \ | 58 #define TRACE_EVENT_SYNTHETIC_DELAY_END(name) \ |
59 do { \ | 59 do { \ |
60 static base::subtle::AtomicWord impl_ptr = 0; \ | 60 static base::subtle::AtomicWord impl_ptr = 0; \ |
61 trace_event_internal::GetOrCreateDelay(name, &impl_ptr)->End(); \ | 61 trace_event_internal::GetOrCreateDelay(name, &impl_ptr)->End(); \ |
62 } while (false) | 62 } while (false) |
63 | 63 |
64 template <typename Type> | 64 template <typename Type> |
65 struct DefaultSingletonTraits; | 65 struct DefaultSingletonTraits; |
66 | 66 |
67 namespace base { | 67 namespace base { |
68 namespace debug { | 68 namespace trace_event { |
69 | 69 |
70 // Time source for computing delay durations. Used for testing. | 70 // Time source for computing delay durations. Used for testing. |
71 class TRACE_EVENT_API_CLASS_EXPORT TraceEventSyntheticDelayClock { | 71 class TRACE_EVENT_API_CLASS_EXPORT TraceEventSyntheticDelayClock { |
72 public: | 72 public: |
73 TraceEventSyntheticDelayClock(); | 73 TraceEventSyntheticDelayClock(); |
74 virtual ~TraceEventSyntheticDelayClock(); | 74 virtual ~TraceEventSyntheticDelayClock(); |
75 virtual base::TimeTicks Now() = 0; | 75 virtual base::TimeTicks Now() = 0; |
76 | 76 |
77 private: | 77 private: |
78 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayClock); | 78 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayClock); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 base::TimeTicks end_time_; | 131 base::TimeTicks end_time_; |
132 base::TimeDelta target_duration_; | 132 base::TimeDelta target_duration_; |
133 TraceEventSyntheticDelayClock* clock_; | 133 TraceEventSyntheticDelayClock* clock_; |
134 | 134 |
135 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelay); | 135 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelay); |
136 }; | 136 }; |
137 | 137 |
138 // Set the target durations of all registered synthetic delay points to zero. | 138 // Set the target durations of all registered synthetic delay points to zero. |
139 TRACE_EVENT_API_CLASS_EXPORT void ResetTraceEventSyntheticDelays(); | 139 TRACE_EVENT_API_CLASS_EXPORT void ResetTraceEventSyntheticDelays(); |
140 | 140 |
141 } // namespace debug | 141 } // namespace trace_event |
142 } // namespace base | 142 } // namespace base |
143 | 143 |
144 namespace trace_event_internal { | 144 namespace trace_event_internal { |
145 | 145 |
146 // Helper class for scoped delays. Do not use directly. | 146 // Helper class for scoped delays. Do not use directly. |
147 class TRACE_EVENT_API_CLASS_EXPORT ScopedSyntheticDelay { | 147 class TRACE_EVENT_API_CLASS_EXPORT ScopedSyntheticDelay { |
148 public: | 148 public: |
149 explicit ScopedSyntheticDelay(const char* name, | 149 explicit ScopedSyntheticDelay(const char* name, |
150 base::subtle::AtomicWord* impl_ptr); | 150 base::subtle::AtomicWord* impl_ptr); |
151 ~ScopedSyntheticDelay(); | 151 ~ScopedSyntheticDelay(); |
152 | 152 |
153 private: | 153 private: |
154 base::debug::TraceEventSyntheticDelay* delay_impl_; | 154 base::trace_event::TraceEventSyntheticDelay* delay_impl_; |
155 base::TimeTicks end_time_; | 155 base::TimeTicks end_time_; |
156 | 156 |
157 DISALLOW_COPY_AND_ASSIGN(ScopedSyntheticDelay); | 157 DISALLOW_COPY_AND_ASSIGN(ScopedSyntheticDelay); |
158 }; | 158 }; |
159 | 159 |
160 // Helper for registering delays. Do not use directly. | 160 // Helper for registering delays. Do not use directly. |
161 TRACE_EVENT_API_CLASS_EXPORT base::debug::TraceEventSyntheticDelay* | 161 TRACE_EVENT_API_CLASS_EXPORT base::trace_event::TraceEventSyntheticDelay* |
162 GetOrCreateDelay(const char* name, base::subtle::AtomicWord* impl_ptr); | 162 GetOrCreateDelay(const char* name, base::subtle::AtomicWord* impl_ptr); |
163 | 163 |
164 } // namespace trace_event_internal | 164 } // namespace trace_event_internal |
165 | 165 |
166 #endif /* BASE_TRACE_EVENT_TRACE_EVENT_SYNTHETIC_DELAY_H_ */ | 166 #endif /* BASE_TRACE_EVENT_TRACE_EVENT_SYNTHETIC_DELAY_H_ */ |
OLD | NEW |