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/trace_event/trace_event_synthetic_delay.h" | 5 #include "base/trace_event/trace_event_synthetic_delay.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include "base/macros.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
8 | 11 |
9 namespace base { | 12 namespace base { |
10 namespace trace_event { | 13 namespace trace_event { |
11 namespace { | 14 namespace { |
12 | 15 |
13 const int kTargetDurationMs = 100; | 16 const int kTargetDurationMs = 100; |
14 // Allow some leeway in timings to make it possible to run these tests with a | 17 // Allow some leeway in timings to make it possible to run these tests with a |
15 // wall clock time source too. | 18 // wall clock time source too. |
16 const int kShortDurationMs = 10; | 19 const int kShortDurationMs = 10; |
(...skipping 15 matching lines...) Expand all Loading... |
32 TraceEventSyntheticDelay* ConfigureDelay(const char* name) { | 35 TraceEventSyntheticDelay* ConfigureDelay(const char* name) { |
33 TraceEventSyntheticDelay* delay = TraceEventSyntheticDelay::Lookup(name); | 36 TraceEventSyntheticDelay* delay = TraceEventSyntheticDelay::Lookup(name); |
34 delay->SetClock(this); | 37 delay->SetClock(this); |
35 delay->SetTargetDuration( | 38 delay->SetTargetDuration( |
36 base::TimeDelta::FromMilliseconds(kTargetDurationMs)); | 39 base::TimeDelta::FromMilliseconds(kTargetDurationMs)); |
37 return delay; | 40 return delay; |
38 } | 41 } |
39 | 42 |
40 void AdvanceTime(base::TimeDelta delta) { now_ += delta; } | 43 void AdvanceTime(base::TimeDelta delta) { now_ += delta; } |
41 | 44 |
42 int64 TestFunction() { | 45 int64_t TestFunction() { |
43 base::TimeTicks start = Now(); | 46 base::TimeTicks start = Now(); |
44 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); } | 47 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); } |
45 return (Now() - start).InMilliseconds(); | 48 return (Now() - start).InMilliseconds(); |
46 } | 49 } |
47 | 50 |
48 int64 AsyncTestFunctionBegin() { | 51 int64_t AsyncTestFunctionBegin() { |
49 base::TimeTicks start = Now(); | 52 base::TimeTicks start = Now(); |
50 { TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("test.AsyncDelay"); } | 53 { TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("test.AsyncDelay"); } |
51 return (Now() - start).InMilliseconds(); | 54 return (Now() - start).InMilliseconds(); |
52 } | 55 } |
53 | 56 |
54 int64 AsyncTestFunctionEnd() { | 57 int64_t AsyncTestFunctionEnd() { |
55 base::TimeTicks start = Now(); | 58 base::TimeTicks start = Now(); |
56 { TRACE_EVENT_SYNTHETIC_DELAY_END("test.AsyncDelay"); } | 59 { TRACE_EVENT_SYNTHETIC_DELAY_END("test.AsyncDelay"); } |
57 return (Now() - start).InMilliseconds(); | 60 return (Now() - start).InMilliseconds(); |
58 } | 61 } |
59 | 62 |
60 private: | 63 private: |
61 base::TimeTicks now_; | 64 base::TimeTicks now_; |
62 | 65 |
63 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest); | 66 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest); |
64 }; | 67 }; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 delay->EndParallel(end_times[0]); | 148 delay->EndParallel(end_times[0]); |
146 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs); | 149 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs); |
147 | 150 |
148 start_time = Now(); | 151 start_time = Now(); |
149 delay->EndParallel(end_times[1]); | 152 delay->EndParallel(end_times[1]); |
150 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs); | 153 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs); |
151 } | 154 } |
152 | 155 |
153 } // namespace trace_event | 156 } // namespace trace_event |
154 } // namespace base | 157 } // namespace base |
OLD | NEW |