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

Side by Side Diff: content/browser/renderer_host/input/render_widget_host_latency_tracker_unittest.cc

Issue 2341413002: New scroll latency metrics added for touch and wheel. (Closed)
Patch Set: Use thread_name to compute _MAin, _Impl only once. Created 4 years, 2 months 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
OLDNEW
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/test/histogram_tester.h" 5 #include "base/test/histogram_tester.h"
6 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h" 6 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h"
7 #include "content/common/input/synthetic_web_input_event_builders.h" 7 #include "content/common/input/synthetic_web_input_event_builders.h"
8 #include "content/public/browser/native_web_keyboard_event.h" 8 #include "content/public/browser/native_web_keyboard_event.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using base::Bucket; 12 using base::Bucket;
13 using blink::WebInputEvent; 13 using blink::WebInputEvent;
14 using testing::ElementsAre; 14 using testing::ElementsAre;
15 15
16 namespace content { 16 namespace content {
17 namespace { 17 namespace {
18 18
19 void AddFakeComponentsWithTimeStamp(
20 const RenderWidgetHostLatencyTracker& tracker,
21 ui::LatencyInfo* latency,
22 base::TimeTicks time_stamp) {
23 latency->AddLatencyNumberWithTimestamp(ui::INPUT_EVENT_LATENCY_UI_COMPONENT,
24 0, 0, time_stamp, 1);
25 latency->AddLatencyNumberWithTimestamp(
26 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, time_stamp,
27 1);
28 latency->AddLatencyNumberWithTimestamp(
29 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, time_stamp, 1);
30 latency->AddLatencyNumberWithTimestamp(
31 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
32 tracker.latency_component_id(), 0, time_stamp, 1);
33 latency->AddLatencyNumberWithTimestamp(
34 ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 0, 0, time_stamp, 1);
35 latency->AddLatencyNumberWithTimestamp(
36 ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT, 0, 0,
37 time_stamp, 1);
38 }
39
19 void AddFakeComponents(const RenderWidgetHostLatencyTracker& tracker, 40 void AddFakeComponents(const RenderWidgetHostLatencyTracker& tracker,
20 ui::LatencyInfo* latency) { 41 ui::LatencyInfo* latency) {
21 latency->AddLatencyNumberWithTimestamp( 42 AddFakeComponentsWithTimeStamp(tracker, latency, base::TimeTicks::Now());
22 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0, base::TimeTicks::Now(), 1);
23 latency->AddLatencyNumberWithTimestamp(
24 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
25 base::TimeTicks::Now(), 1);
26 latency->AddLatencyNumberWithTimestamp(
27 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0,
28 base::TimeTicks::Now(), 1);
29 latency->AddLatencyNumberWithTimestamp(
30 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
31 tracker.latency_component_id(), 0, base::TimeTicks::Now(), 1);
32 latency->AddLatencyNumberWithTimestamp(
33 ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 0, 0,
34 base::TimeTicks::Now(), 1);
35 latency->AddLatencyNumberWithTimestamp(
36 ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT, 0, 0,
37 base::TimeTicks::Now(), 1);
38 } 43 }
39 44
40 void AddRenderingScheduledComponent(ui::LatencyInfo* latency, bool main) { 45 void AddRenderingScheduledComponent(ui::LatencyInfo* latency,
46 bool main,
47 base::TimeTicks time_stamp) {
41 if (main) { 48 if (main) {
42 latency->AddLatencyNumberWithTimestamp( 49 latency->AddLatencyNumberWithTimestamp(
43 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, 0, 50 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, 0,
44 base::TimeTicks::Now(), 1); 51 time_stamp, 1);
45 52
46 } else { 53 } else {
47 latency->AddLatencyNumberWithTimestamp( 54 latency->AddLatencyNumberWithTimestamp(
48 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, 0, 55 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, 0,
49 base::TimeTicks::Now(), 1); 56 time_stamp, 1);
50 } 57 }
51 } 58 }
52 59
53 } // namespace 60 } // namespace
54 61
55 class RenderWidgetHostLatencyTrackerTest : public testing::Test { 62 class RenderWidgetHostLatencyTrackerTest : public testing::Test {
56 public: 63 public:
57 RenderWidgetHostLatencyTrackerTest() { 64 RenderWidgetHostLatencyTrackerTest() {
58 tracker_.Initialize(kTestRoutingId, kTestProcessId); 65 tracker_.Initialize(kTestRoutingId, kTestProcessId);
59 ResetHistograms(); 66 ResetHistograms();
(...skipping 21 matching lines...) Expand all
81 return *histogram_tester_; 88 return *histogram_tester_;
82 } 89 }
83 90
84 private: 91 private:
85 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest); 92 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest);
86 const int kTestRoutingId = 3; 93 const int kTestRoutingId = 3;
87 const int kTestProcessId = 1; 94 const int kTestProcessId = 1;
88 std::unique_ptr<base::HistogramTester> histogram_tester_; 95 std::unique_ptr<base::HistogramTester> histogram_tester_;
89 RenderWidgetHostLatencyTracker tracker_; 96 RenderWidgetHostLatencyTracker tracker_;
90 }; 97 };
98 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelHistograms) {
99 for (bool rendering_on_main : {false, true}) {
100 for (bool is_running_navigation_hint_task : {false, true}) {
101 ResetHistograms();
102 {
103 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
104 blink::WebMouseWheelEvent::PhaseChanged);
105 base::TimeTicks now = base::TimeTicks::Now();
106 wheel.timeStampSeconds = (now - base::TimeTicks()).InSecondsF();
107 ui::LatencyInfo wheel_latency(ui::SourceEventType::WHEEL);
108 AddFakeComponentsWithTimeStamp(*tracker(), &wheel_latency, now);
109 AddRenderingScheduledComponent(&wheel_latency, rendering_on_main, now);
110 tracker()->OnInputEvent(wheel, &wheel_latency);
111 EXPECT_TRUE(wheel_latency.FindLatency(
112 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
113 tracker()->latency_component_id(), nullptr));
114 EXPECT_TRUE(wheel_latency.FindLatency(
115 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
116 EXPECT_EQ(1U, wheel_latency.input_coordinates_size());
117 tracker()->OnInputEventAck(wheel, &wheel_latency,
118 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
119 tracker()->OnFrameSwapped(wheel_latency,
120 is_running_navigation_hint_task);
121 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1));
122 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1));
91 123
92 TEST_F(RenderWidgetHostLatencyTrackerTest, TestHistograms) { 124 EXPECT_TRUE(HistogramSizeEq(
93 for (bool rendering_on_main : { false, true }) { 125 "Event.Latency.Wheel.TimeToFirstScrollUpdateSwapBegin2", 1));
126
127 EXPECT_TRUE(HistogramSizeEq(
128 "Event.Latency.ScrollUpdate.Wheel.TimeToHandled2_Main",
129 rendering_on_main ? 1 : 0));
130 EXPECT_TRUE(HistogramSizeEq(
131 "Event.Latency.ScrollUpdate.Wheel.TimeToHandled2_Impl",
132 rendering_on_main ? 0 : 1));
133 EXPECT_TRUE(HistogramSizeEq(
134 "Event.Latency.ScrollUpdate.Wheel.HandledToRendererSwap2_Main",
135 rendering_on_main ? 1 : 0));
136 EXPECT_TRUE(HistogramSizeEq(
137 "Event.Latency.ScrollUpdate.Wheel.HandledToRendererSwap2_Impl",
138 rendering_on_main ? 0 : 1));
139 EXPECT_TRUE(HistogramSizeEq(
140 "Event.Latency.ScrollUpdate.Wheel.RendererSwapToBrowserNotified2",
141 1));
142 EXPECT_TRUE(HistogramSizeEq(
143 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2",
144 1));
145 EXPECT_TRUE(
146 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1));
147 }
148 }
149 }
150 }
151
152 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchHistograms) {
153 for (bool rendering_on_main : {false, true}) {
94 for (bool is_running_navigation_hint_task : {false, true}) { 154 for (bool is_running_navigation_hint_task : {false, true}) {
95 ResetHistograms(); 155 ResetHistograms();
96 { 156 {
97 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( 157 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
98 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); 158 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen);
99 scroll.timeStampSeconds = 159 base::TimeTicks now = base::TimeTicks::Now();
100 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 160 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF();
101 ui::LatencyInfo scroll_latency; 161 ui::LatencyInfo scroll_latency;
102 AddFakeComponents(*tracker(), &scroll_latency); 162 AddFakeComponentsWithTimeStamp(*tracker(), &scroll_latency, now);
103 AddRenderingScheduledComponent(&scroll_latency, rendering_on_main); 163 AddRenderingScheduledComponent(&scroll_latency, rendering_on_main, now);
104 tracker()->OnInputEvent(scroll, &scroll_latency); 164 tracker()->OnInputEvent(scroll, &scroll_latency);
105 EXPECT_TRUE(scroll_latency.FindLatency( 165 EXPECT_TRUE(scroll_latency.FindLatency(
106 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 166 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
107 tracker()->latency_component_id(), nullptr)); 167 tracker()->latency_component_id(), nullptr));
108 EXPECT_TRUE(scroll_latency.FindLatency( 168 EXPECT_TRUE(scroll_latency.FindLatency(
109 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); 169 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
110 EXPECT_EQ(1U, scroll_latency.input_coordinates_size()); 170 EXPECT_EQ(1U, scroll_latency.input_coordinates_size());
111 tracker()->OnInputEventAck(scroll, &scroll_latency, 171 tracker()->OnInputEventAck(scroll, &scroll_latency,
112 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 172 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
113 } 173 }
114 174
115 { 175 {
116 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
117 blink::WebMouseWheelEvent::PhaseChanged);
118 wheel.timeStampSeconds =
119 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
120 ui::LatencyInfo wheel_latency;
121 AddFakeComponents(*tracker(), &wheel_latency);
122 AddRenderingScheduledComponent(&wheel_latency, rendering_on_main);
123 tracker()->OnInputEvent(wheel, &wheel_latency);
124 EXPECT_TRUE(wheel_latency.FindLatency(
125 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
126 tracker()->latency_component_id(), nullptr));
127 EXPECT_TRUE(wheel_latency.FindLatency(
128 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
129 EXPECT_EQ(1U, wheel_latency.input_coordinates_size());
130 tracker()->OnInputEventAck(wheel, &wheel_latency,
131 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
132 }
133
134 {
135 SyntheticWebTouchEvent touch; 176 SyntheticWebTouchEvent touch;
136 touch.PressPoint(0, 0); 177 touch.PressPoint(0, 0);
137 touch.PressPoint(1, 1); 178 touch.PressPoint(1, 1);
138 ui::LatencyInfo touch_latency; 179 ui::LatencyInfo touch_latency(ui::SourceEventType::TOUCH);
139 AddFakeComponents(*tracker(), &touch_latency); 180 base::TimeTicks now = base::TimeTicks::Now();
140 AddRenderingScheduledComponent(&touch_latency, rendering_on_main); 181 AddFakeComponentsWithTimeStamp(*tracker(), &touch_latency, now);
182 AddRenderingScheduledComponent(&touch_latency, rendering_on_main, now);
141 tracker()->OnInputEvent(touch, &touch_latency); 183 tracker()->OnInputEvent(touch, &touch_latency);
142 EXPECT_TRUE(touch_latency.FindLatency( 184 EXPECT_TRUE(touch_latency.FindLatency(
143 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 185 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
144 tracker()->latency_component_id(), nullptr)); 186 tracker()->latency_component_id(), nullptr));
145 EXPECT_TRUE(touch_latency.FindLatency( 187 EXPECT_TRUE(touch_latency.FindLatency(
146 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); 188 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
147 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); 189 EXPECT_EQ(2U, touch_latency.input_coordinates_size());
148 tracker()->OnInputEventAck(touch, &touch_latency, 190 tracker()->OnInputEventAck(touch, &touch_latency,
149 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 191 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
150 tracker()->OnFrameSwapped(touch_latency, 192 tracker()->OnFrameSwapped(touch_latency,
151 is_running_navigation_hint_task); 193 is_running_navigation_hint_task);
152 } 194 }
153 195
154 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1));
155 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); 196 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1));
156 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1));
157 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); 197 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1));
158 EXPECT_TRUE(HistogramSizeEq( 198 EXPECT_TRUE(HistogramSizeEq(
159 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); 199 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1));
160 EXPECT_TRUE( 200 EXPECT_TRUE(
161 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" 201 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_"
162 "IsRunningNavigationHintTask", 202 "IsRunningNavigationHintTask",
163 is_running_navigation_hint_task ? 1 : 0)); 203 is_running_navigation_hint_task ? 1 : 0));
164 EXPECT_TRUE( 204 EXPECT_TRUE(
165 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); 205 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1));
166 EXPECT_TRUE( 206 EXPECT_TRUE(
(...skipping 10 matching lines...) Expand all
177 "Event.Latency.ScrollUpdate.HandledToRendererSwap_Main", 217 "Event.Latency.ScrollUpdate.HandledToRendererSwap_Main",
178 rendering_on_main ? 1 : 0)); 218 rendering_on_main ? 1 : 0));
179 EXPECT_TRUE(HistogramSizeEq( 219 EXPECT_TRUE(HistogramSizeEq(
180 "Event.Latency.ScrollUpdate.HandledToRendererSwap_Impl", 220 "Event.Latency.ScrollUpdate.HandledToRendererSwap_Impl",
181 rendering_on_main ? 0 : 1)); 221 rendering_on_main ? 0 : 1));
182 EXPECT_TRUE(HistogramSizeEq( 222 EXPECT_TRUE(HistogramSizeEq(
183 "Event.Latency.ScrollUpdate.RendererSwapToBrowserNotified", 1)); 223 "Event.Latency.ScrollUpdate.RendererSwapToBrowserNotified", 1));
184 EXPECT_TRUE(HistogramSizeEq( 224 EXPECT_TRUE(HistogramSizeEq(
185 "Event.Latency.ScrollUpdate.BrowserNotifiedToBeforeGpuSwap", 1)); 225 "Event.Latency.ScrollUpdate.BrowserNotifiedToBeforeGpuSwap", 1));
186 EXPECT_TRUE(HistogramSizeEq("Event.Latency.ScrollUpdate.GpuSwap", 1)); 226 EXPECT_TRUE(HistogramSizeEq("Event.Latency.ScrollUpdate.GpuSwap", 1));
227 EXPECT_TRUE(HistogramSizeEq(
228 "Event.Latency.Touch.TimeToFirstScrollUpdateSwapBegin2", 1));
229
230 EXPECT_TRUE(HistogramSizeEq(
231 "Event.Latency.Touch.TimeToScrollUpdateSwapBegin2", 0));
232
233 EXPECT_TRUE(HistogramSizeEq(
234 "Event.Latency.ScrollUpdate.Touch.TimeToHandled2_Main",
235 rendering_on_main ? 1 : 0));
236 EXPECT_TRUE(HistogramSizeEq(
237 "Event.Latency.ScrollUpdate.Touch.TimeToHandled2_Impl",
238 rendering_on_main ? 0 : 1));
239 EXPECT_TRUE(HistogramSizeEq(
240 "Event.Latency.ScrollUpdate.Touch.HandledToRendererSwap2_Main",
241 rendering_on_main ? 1 : 0));
242 EXPECT_TRUE(HistogramSizeEq(
243 "Event.Latency.ScrollUpdate.Touch.HandledToRendererSwap2_Impl",
244 rendering_on_main ? 0 : 1));
245 EXPECT_TRUE(HistogramSizeEq(
246 "Event.Latency.ScrollUpdate.Touch.RendererSwapToBrowserNotified2",
247 1));
248 EXPECT_TRUE(HistogramSizeEq(
249 "Event.Latency.ScrollUpdate.Touch.BrowserNotifiedToBeforeGpuSwap2",
250 1));
251 EXPECT_TRUE(
252 HistogramSizeEq("Event.Latency.ScrollUpdate.Touch.GpuSwap2", 1));
187 } 253 }
188 } 254 }
189 } 255 }
190 256
191 TEST_F(RenderWidgetHostLatencyTrackerTest, 257 TEST_F(RenderWidgetHostLatencyTrackerTest,
192 LatencyTerminatedOnAckIfRenderingNotScheduled) { 258 LatencyTerminatedOnAckIfRenderingNotScheduled) {
193 { 259 {
194 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollBegin( 260 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollBegin(
195 5.f, -5.f, blink::WebGestureDeviceTouchscreen); 261 5.f, -5.f, blink::WebGestureDeviceTouchscreen);
196 ui::LatencyInfo scroll_latency; 262 ui::LatencyInfo scroll_latency;
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), 638 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"),
573 ElementsAre(Bucket( 639 ElementsAre(Bucket(
574 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 640 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
575 EXPECT_THAT(histogram_tester().GetAllSamples( 641 EXPECT_THAT(histogram_tester().GetAllSamples(
576 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), 642 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"),
577 ElementsAre(Bucket( 643 ElementsAre(Bucket(
578 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 644 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
579 } 645 }
580 646
581 } // namespace content 647 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/render_widget_host_latency_tracker.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698