Chromium Code Reviews| 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
| 7 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 7 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 8 #include "base/trace_event/trace_event_synthetic_delay.h" | 8 #include "base/trace_event/trace_event_synthetic_delay.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 AutoLock lock(lock_); | 69 AutoLock lock(lock_); |
| 70 mode_ = mode; | 70 mode_ = mode; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void TraceEventSyntheticDelay::SetClock(TraceEventSyntheticDelayClock* clock) { | 73 void TraceEventSyntheticDelay::SetClock(TraceEventSyntheticDelayClock* clock) { |
| 74 AutoLock lock(lock_); | 74 AutoLock lock(lock_); |
| 75 clock_ = clock; | 75 clock_ = clock; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void TraceEventSyntheticDelay::Begin() { | 78 void TraceEventSyntheticDelay::Begin() { |
| 79 // Note that we check for a non-zero target duration without locking to keep | |
| 80 // things quick for the common case when delays are disabled. Since the delay | |
| 81 // calculation is done with a lock held, it will always be correct. The only | |
| 82 // downside of this is that we may fail to apply some delays when the target | |
| 83 // duration changes. | |
| 84 ANNOTATE_BENIGN_RACE(&target_duration_, "Synthetic delay duration"); | |
|
Sami
2017/03/21 11:52:55
There is actually a race here (SetTargetDuration w
| |
| 85 if (!target_duration_.ToInternalValue()) | 79 if (!target_duration_.ToInternalValue()) |
| 86 return; | 80 return; |
| 87 | 81 |
| 88 TimeTicks start_time = clock_->Now(); | 82 TimeTicks start_time = clock_->Now(); |
| 89 { | 83 { |
| 90 AutoLock lock(lock_); | 84 AutoLock lock(lock_); |
| 91 if (++begin_count_ != 1) | 85 if (++begin_count_ != 1) |
| 92 return; | 86 return; |
| 93 end_time_ = CalculateEndTimeLocked(start_time); | 87 end_time_ = CalculateEndTimeLocked(start_time); |
| 94 } | 88 } |
| 95 } | 89 } |
| 96 | 90 |
| 97 void TraceEventSyntheticDelay::BeginParallel(TimeTicks* out_end_time) { | 91 void TraceEventSyntheticDelay::BeginParallel(TimeTicks* out_end_time) { |
| 98 // See note in Begin(). | |
| 99 ANNOTATE_BENIGN_RACE(&target_duration_, "Synthetic delay duration"); | |
| 100 if (!target_duration_.ToInternalValue()) { | 92 if (!target_duration_.ToInternalValue()) { |
| 101 *out_end_time = TimeTicks(); | 93 *out_end_time = TimeTicks(); |
| 102 return; | 94 return; |
| 103 } | 95 } |
| 104 | 96 |
| 105 TimeTicks start_time = clock_->Now(); | 97 TimeTicks start_time = clock_->Now(); |
| 106 { | 98 { |
| 107 AutoLock lock(lock_); | 99 AutoLock lock(lock_); |
| 108 *out_end_time = CalculateEndTimeLocked(start_time); | 100 *out_end_time = CalculateEndTimeLocked(start_time); |
| 109 } | 101 } |
| 110 } | 102 } |
| 111 | 103 |
| 112 void TraceEventSyntheticDelay::End() { | 104 void TraceEventSyntheticDelay::End() { |
| 113 // See note in Begin(). | |
| 114 ANNOTATE_BENIGN_RACE(&target_duration_, "Synthetic delay duration"); | |
| 115 if (!target_duration_.ToInternalValue()) | 105 if (!target_duration_.ToInternalValue()) |
| 116 return; | 106 return; |
| 117 | 107 |
| 118 TimeTicks end_time; | 108 TimeTicks end_time; |
| 119 { | 109 { |
| 120 AutoLock lock(lock_); | 110 AutoLock lock(lock_); |
| 121 if (!begin_count_ || --begin_count_ != 0) | 111 if (!begin_count_ || --begin_count_ != 0) |
| 122 return; | 112 return; |
| 123 end_time = end_time_; | 113 end_time = end_time_; |
| 124 } | 114 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 delay_impl = | 216 delay_impl = |
| 227 base::trace_event::TraceEventSyntheticDelayRegistry::GetInstance() | 217 base::trace_event::TraceEventSyntheticDelayRegistry::GetInstance() |
| 228 ->GetOrCreateDelay(name); | 218 ->GetOrCreateDelay(name); |
| 229 base::subtle::Release_Store( | 219 base::subtle::Release_Store( |
| 230 impl_ptr, reinterpret_cast<base::subtle::AtomicWord>(delay_impl)); | 220 impl_ptr, reinterpret_cast<base::subtle::AtomicWord>(delay_impl)); |
| 231 } | 221 } |
| 232 return delay_impl; | 222 return delay_impl; |
| 233 } | 223 } |
| 234 | 224 |
| 235 } // namespace trace_event_internal | 225 } // namespace trace_event_internal |
| OLD | NEW |