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 "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" | 5 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" |
6 #include "base/metrics/metrics_hashes.h" | 6 #include "base/metrics/metrics_hashes.h" |
7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
8 #include "components/metrics/proto/ukm/entry.pb.h" | 8 #include "components/metrics/proto/ukm/entry.pb.h" |
9 #include "components/rappor/public/rappor_utils.h" | 9 #include "components/rappor/public/rappor_utils.h" |
10 #include "components/rappor/test_rappor_service.h" | 10 #include "components/rappor/test_rappor_service.h" |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 fake_latency, ack_state); | 1290 fake_latency, ack_state); |
1291 | 1291 |
1292 tracker()->OnInputEventAck(wheel_event, &latency, ack_state); | 1292 tracker()->OnInputEventAck(wheel_event, &latency, ack_state); |
1293 } | 1293 } |
1294 | 1294 |
1295 EXPECT_THAT(histogram_tester().GetAllSamples( | 1295 EXPECT_THAT(histogram_tester().GetAllSamples( |
1296 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"), | 1296 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"), |
1297 ElementsAre(Bucket(14, 1))); | 1297 ElementsAre(Bucket(14, 1))); |
1298 } | 1298 } |
1299 | 1299 |
| 1300 TEST_F(RenderWidgetHostLatencyTrackerTest, ExpectedQueueingTimeAccuracy) { |
| 1301 // These numbers are sensitive to where the histogram buckets are. |
| 1302 int event_timestamps_ms[] = {11, 25, 35}; |
| 1303 |
| 1304 for (float expected_queueing_time_ms : {2, 15, 200, 400}) { |
| 1305 base::TimeDelta expected_queueing_time = |
| 1306 base::TimeDelta::FromMilliseconds(expected_queueing_time_ms); |
| 1307 SyntheticWebTouchEvent event; |
| 1308 // Touch start. |
| 1309 event.PressPoint(1, 1); |
| 1310 |
| 1311 ui::LatencyInfo latency; |
| 1312 latency.set_source_event_type(ui::SourceEventType::TOUCH); |
| 1313 tracker()->OnInputEvent(event, &latency); |
| 1314 |
| 1315 ui::LatencyInfo fake_latency; |
| 1316 fake_latency.set_trace_id(kTraceEventId); |
| 1317 fake_latency.set_expected_queueing_time_on_dispatch(expected_queueing_time); |
| 1318 fake_latency.set_source_event_type(ui::SourceEventType::TOUCH); |
| 1319 fake_latency.AddLatencyNumberWithTimestamp( |
| 1320 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 1321 tracker()->latency_component_id(), 0, |
| 1322 base::TimeTicks() + |
| 1323 base::TimeDelta::FromMilliseconds(event_timestamps_ms[0]), |
| 1324 1); |
| 1325 |
| 1326 fake_latency.AddLatencyNumberWithTimestamp( |
| 1327 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0, |
| 1328 base::TimeTicks() + |
| 1329 base::TimeDelta::FromMilliseconds(event_timestamps_ms[1]), |
| 1330 1); |
| 1331 |
| 1332 fake_latency.AddLatencyNumberWithTimestamp( |
| 1333 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0, |
| 1334 base::TimeTicks() + |
| 1335 base::TimeDelta::FromMilliseconds(event_timestamps_ms[2]), |
| 1336 1); |
| 1337 |
| 1338 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck |
| 1339 // overwriting components. |
| 1340 tracker()->ComputeInputLatencyHistograms( |
| 1341 event.GetType(), tracker()->latency_component_id(), fake_latency, |
| 1342 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1343 |
| 1344 tracker()->OnInputEventAck(event, &latency, |
| 1345 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1346 } |
| 1347 |
| 1348 EXPECT_THAT( |
| 1349 histogram_tester().GetAllSamples( |
| 1350 "RendererScheduler." |
| 1351 "QueueingDurationWhenExpectedQueueingTime_LessThan.10ms"), |
| 1352 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1))); |
| 1353 |
| 1354 EXPECT_THAT( |
| 1355 histogram_tester().GetAllSamples( |
| 1356 "RendererScheduler." |
| 1357 "QueueingDurationWhenExpectedQueueingTime_LessThan.150ms"), |
| 1358 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 2))); |
| 1359 |
| 1360 EXPECT_THAT( |
| 1361 histogram_tester().GetAllSamples( |
| 1362 "RendererScheduler." |
| 1363 "QueueingDurationWhenExpectedQueueingTime_LessThan.300ms"), |
| 1364 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 3))); |
| 1365 |
| 1366 EXPECT_THAT( |
| 1367 histogram_tester().GetAllSamples( |
| 1368 "RendererScheduler." |
| 1369 "QueueingDurationWhenExpectedQueueingTime_LessThan.450ms"), |
| 1370 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 4))); |
| 1371 |
| 1372 EXPECT_THAT( |
| 1373 histogram_tester().GetAllSamples( |
| 1374 "RendererScheduler." |
| 1375 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.10ms"), |
| 1376 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 3))); |
| 1377 |
| 1378 EXPECT_THAT( |
| 1379 histogram_tester().GetAllSamples( |
| 1380 "RendererScheduler." |
| 1381 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.150ms"), |
| 1382 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 2))); |
| 1383 |
| 1384 EXPECT_THAT( |
| 1385 histogram_tester().GetAllSamples( |
| 1386 "RendererScheduler." |
| 1387 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.300ms"), |
| 1388 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1))); |
| 1389 |
| 1390 EXPECT_THAT(histogram_tester().GetAllSamples( |
| 1391 "RendererScheduler." |
| 1392 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.450ms"), |
| 1393 ElementsAre()); |
| 1394 } |
| 1395 |
1300 } // namespace content | 1396 } // namespace content |
OLD | NEW |