Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: base/debug/trace_event_synthetic_delay_unittest.cc

Issue 83183005: Add synthetic delay points for latency testing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Begin delay on one thread and end it on another. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/debug/trace_event_synthetic_delay.h" 5 #include "base/debug/trace_event_synthetic_delay.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 namespace debug { 10 namespace debug {
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 void AdvanceTime(base::TimeDelta delta) { now_ += delta; } 39 void AdvanceTime(base::TimeDelta delta) { now_ += delta; }
40 40
41 int TestFunction() { 41 int TestFunction() {
42 base::TimeTicks start = Now(); 42 base::TimeTicks start = Now();
43 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); } 43 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); }
44 return (Now() - start).InMilliseconds(); 44 return (Now() - start).InMilliseconds();
45 } 45 }
46 46
47 int AsyncTestFunctionActivate() { 47 int AsyncTestFunctionBegin() {
48 base::TimeTicks start = Now(); 48 base::TimeTicks start = Now();
49 { TRACE_EVENT_SYNTHETIC_DELAY_ACTIVATE("test.AsyncDelay"); } 49 { TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("test.AsyncDelay"); }
50 return (Now() - start).InMilliseconds(); 50 return (Now() - start).InMilliseconds();
51 } 51 }
52 52
53 int AsyncTestFunctionApply() { 53 int AsyncTestFunctionEnd() {
54 base::TimeTicks start = Now(); 54 base::TimeTicks start = Now();
55 { TRACE_EVENT_SYNTHETIC_DELAY_APPLY("test.AsyncDelay"); } 55 { TRACE_EVENT_SYNTHETIC_DELAY_END("test.AsyncDelay"); }
56 return (Now() - start).InMilliseconds(); 56 return (Now() - start).InMilliseconds();
57 } 57 }
58 58
59 private: 59 private:
60 base::TimeTicks now_; 60 base::TimeTicks now_;
61 61
62 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest); 62 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest);
63 }; 63 };
64 64
65 TEST_F(TraceEventSyntheticDelayTest, StaticDelay) { 65 TEST_F(TraceEventSyntheticDelayTest, StaticDelay) {
(...skipping 17 matching lines...) Expand all
83 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay"); 83 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay");
84 delay->SetMode(TraceEventSyntheticDelay::ALTERNATING); 84 delay->SetMode(TraceEventSyntheticDelay::ALTERNATING);
85 EXPECT_GE(TestFunction(), kTargetDurationMs); 85 EXPECT_GE(TestFunction(), kTargetDurationMs);
86 EXPECT_LT(TestFunction(), kShortDurationMs); 86 EXPECT_LT(TestFunction(), kShortDurationMs);
87 EXPECT_GE(TestFunction(), kTargetDurationMs); 87 EXPECT_GE(TestFunction(), kTargetDurationMs);
88 EXPECT_LT(TestFunction(), kShortDurationMs); 88 EXPECT_LT(TestFunction(), kShortDurationMs);
89 } 89 }
90 90
91 TEST_F(TraceEventSyntheticDelayTest, AsyncDelay) { 91 TEST_F(TraceEventSyntheticDelayTest, AsyncDelay) {
92 ConfigureDelay("test.AsyncDelay"); 92 ConfigureDelay("test.AsyncDelay");
93 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 93 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
94 EXPECT_GE(AsyncTestFunctionApply(), kTargetDurationMs / 2); 94 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs / 2);
95 } 95 }
96 96
97 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayExceeded) { 97 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayExceeded) {
98 ConfigureDelay("test.AsyncDelay"); 98 ConfigureDelay("test.AsyncDelay");
99 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 99 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
100 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs)); 100 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs));
101 EXPECT_LT(AsyncTestFunctionApply(), kShortDurationMs); 101 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
102 } 102 }
103 103
104 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNoActivation) { 104 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNoActivation) {
105 ConfigureDelay("test.AsyncDelay"); 105 ConfigureDelay("test.AsyncDelay");
106 EXPECT_LT(AsyncTestFunctionApply(), kShortDurationMs); 106 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
107 } 107 }
108 108
109 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayMultipleActivations) { 109 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNestedActivations) {
110 ConfigureDelay("test.AsyncDelay"); 110 ConfigureDelay("test.AsyncDelay");
111 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 111 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
112 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs)); 112 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
113 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 113 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
114 EXPECT_LT(AsyncTestFunctionApply(), kShortDurationMs); 114 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs / 2);
115 } 115 }
116 116
117 TEST_F(TraceEventSyntheticDelayTest, ResetDelays) { 117 TEST_F(TraceEventSyntheticDelayTest, ResetDelays) {
118 ConfigureDelay("test.Delay"); 118 ConfigureDelay("test.Delay");
119 ResetSyntheticDelays(); 119 ResetTraceEventSyntheticDelays();
120 EXPECT_LT(TestFunction(), kShortDurationMs); 120 EXPECT_LT(TestFunction(), kShortDurationMs);
121 } 121 }
122 122
123 TEST_F(TraceEventSyntheticDelayTest, ResetAndBeginMultiple) {
124 TraceEventSyntheticDelay* delay = ConfigureDelay("test.AsyncDelay");
125
126 delay->ResetAndBeginMultiple(0);
127 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
128
129 delay->ResetAndBeginMultiple(1);
130 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs);
131 }
132
123 } // namespace debug 133 } // namespace debug
124 } // namespace base 134 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698