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

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

Issue 2756893002: Add Keyboard Latency UMA Metrics. (Closed)
Patch Set: Fix test issue Created 3 years, 8 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 "components/rappor/public/rappor_utils.h" 6 #include "components/rappor/public/rappor_utils.h"
7 #include "components/rappor/test_rappor_service.h" 7 #include "components/rappor/test_rappor_service.h"
8 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h" 8 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h"
9 #include "content/common/input/synthetic_web_input_event_builders.h" 9 #include "content/common/input/synthetic_web_input_event_builders.h"
10 #include "content/public/browser/native_web_keyboard_event.h" 10 #include "content/public/browser/native_web_keyboard_event.h"
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 EXPECT_THAT(histogram_tester().GetAllSamples( 959 EXPECT_THAT(histogram_tester().GetAllSamples(
960 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), 960 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"),
961 ElementsAre(Bucket( 961 ElementsAre(Bucket(
962 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 962 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
963 EXPECT_THAT(histogram_tester().GetAllSamples( 963 EXPECT_THAT(histogram_tester().GetAllSamples(
964 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), 964 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"),
965 ElementsAre(Bucket( 965 ElementsAre(Bucket(
966 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 966 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
967 } 967 }
968 968
969 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyBlockingAndQueueingTime) {
970 // These numbers are sensitive to where the histogram buckets are.
971 int event_timestamps_ms[] = {11, 25, 35};
972
973 for (InputEventAckState blocking :
974 {INPUT_EVENT_ACK_STATE_NOT_CONSUMED, INPUT_EVENT_ACK_STATE_CONSUMED}) {
975 {
976 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::KeyDown,
977 blink::WebInputEvent::NoModifiers,
978 base::TimeTicks::Now());
979 ui::LatencyInfo latency_info;
980 tracker()->OnInputEvent(event, &latency_info);
981
982 ui::LatencyInfo fake_latency;
983 fake_latency.AddLatencyNumberWithTimestamp(
984 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
985 tracker()->latency_component_id(), 0,
986 base::TimeTicks() +
987 base::TimeDelta::FromMilliseconds(event_timestamps_ms[0]),
988 1);
989
990 fake_latency.AddLatencyNumberWithTimestamp(
991 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
992 base::TimeTicks() +
993 base::TimeDelta::FromMilliseconds(event_timestamps_ms[1]),
994 1);
995
996 fake_latency.AddLatencyNumberWithTimestamp(
997 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
998 base::TimeTicks() +
999 base::TimeDelta::FromMilliseconds(event_timestamps_ms[2]),
1000 1);
1001
1002 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
1003 // overwriting components.
1004 tracker()->ComputeInputLatencyHistograms(
1005 event.type(), tracker()->latency_component_id(), fake_latency,
1006 blocking);
1007
1008 tracker()->OnInputEventAck(event, &latency_info, blocking);
1009 }
1010 }
1011
1012 EXPECT_THAT(
1013 histogram_tester().GetAllSamples(
1014 "Event.Latency.QueueingTime.KeyEventDefaultPrevented"),
1015 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1)));
1016 EXPECT_THAT(
1017 histogram_tester().GetAllSamples(
1018 "Event.Latency.QueueingTime.KeyEventDefaultAllowed"),
1019 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1)));
1020 EXPECT_THAT(
1021 histogram_tester().GetAllSamples(
1022 "Event.Latency.BlockingTime.KeyEventDefaultPrevented"),
1023 ElementsAre(Bucket(event_timestamps_ms[2] - event_timestamps_ms[1], 1)));
1024 EXPECT_THAT(
1025 histogram_tester().GetAllSamples(
1026 "Event.Latency.BlockingTime.KeyEventDefaultAllowed"),
1027 ElementsAre(Bucket(event_timestamps_ms[2] - event_timestamps_ms[1], 1)));
1028 }
1029
1030 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyUILatency) {
1031 // These numbers are sensitive to where the histogram buckets are.
1032 int event_timestamps_microseconds[] = {100, 185};
1033
1034 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::KeyDown,
1035 blink::WebInputEvent::NoModifiers,
1036 base::TimeTicks::Now());
1037 ui::LatencyInfo latency_info;
1038 latency_info.AddLatencyNumberWithTimestamp(
1039 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0,
1040 base::TimeTicks() +
1041 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1042 1);
1043
1044 latency_info.AddLatencyNumberWithTimestamp(
1045 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1046 tracker()->latency_component_id(), 0,
1047 base::TimeTicks() +
1048 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1049 1);
1050
1051 tracker()->OnInputEvent(event, &latency_info);
1052 tracker()->OnInputEventAck(event, &latency_info,
1053 InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN);
1054 EXPECT_THAT(histogram_tester().GetAllSamples("Event.Latency.Browser.KeyUI"),
1055 ElementsAre(Bucket(event_timestamps_microseconds[1] -
1056 event_timestamps_microseconds[0],
1057 1)));
1058 }
1059
1060 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyAckedLatency) {
1061 // These numbers are sensitive to where the histogram buckets are.
1062 int event_timestamps_microseconds[] = {11, 24};
1063
1064 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::KeyDown,
1065 blink::WebInputEvent::NoModifiers,
1066 base::TimeTicks::Now());
1067 ui::LatencyInfo latency_info;
1068
1069 latency_info.AddLatencyNumberWithTimestamp(
1070 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1071 tracker()->latency_component_id(), 0,
1072 base::TimeTicks() +
1073 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1074 1);
1075
1076 latency_info.AddLatencyNumberWithTimestamp(
1077 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
1078 base::TimeTicks() +
1079 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1080 1);
1081
1082 tracker()->OnInputEvent(event, &latency_info);
1083 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
1084 // overwriting components.
1085 tracker()->ComputeInputLatencyHistograms(
1086 event.type(), tracker()->latency_component_id(), latency_info,
1087 InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN);
1088
1089 EXPECT_THAT(
1090 histogram_tester().GetAllSamples("Event.Latency.Browser.KeyAcked"),
1091 ElementsAre(Bucket(
1092 event_timestamps_microseconds[1] - event_timestamps_microseconds[0],
1093 1)));
1094 }
1095
1096 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyEndToEndLatency) {
1097 // These numbers are sensitive to where the histogram buckets are.
1098 int event_timestamps_microseconds[] = {11, 24};
1099
1100 ui::LatencyInfo latency_info;
1101 latency_info.set_source_event_type(ui::SourceEventType::KEY);
1102 latency_info.AddLatencyNumberWithTimestamp(
1103 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0,
1104 base::TimeTicks() +
1105 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1106 1);
1107
1108 latency_info.AddLatencyNumberWithTimestamp(
1109 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1110 tracker()->latency_component_id(), 0,
1111 base::TimeTicks() +
1112 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1113 1);
1114
1115 latency_info.AddLatencyNumberWithTimestamp(
1116 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0,
1117 base::TimeTicks() +
1118 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1119 1);
1120
1121 latency_info.AddLatencyNumberWithTimestamp(
1122 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
1123 base::TimeTicks() +
1124 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1125 1);
1126
1127 tracker()->OnFrameSwapped(latency_info);
1128
1129 EXPECT_THAT(histogram_tester().GetAllSamples("Event.Latency.EndToEnd.Key"),
1130 ElementsAre(Bucket(event_timestamps_microseconds[1] -
1131 event_timestamps_microseconds[0],
1132 1)));
1133 }
1134
969 } // namespace content 1135 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698