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

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: mfomitchev responses, rebase Created 3 years, 7 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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 EXPECT_THAT(histogram_tester().GetAllSamples( 892 EXPECT_THAT(histogram_tester().GetAllSamples(
893 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), 893 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"),
894 ElementsAre(Bucket( 894 ElementsAre(Bucket(
895 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 895 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
896 EXPECT_THAT(histogram_tester().GetAllSamples( 896 EXPECT_THAT(histogram_tester().GetAllSamples(
897 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), 897 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"),
898 ElementsAre(Bucket( 898 ElementsAre(Bucket(
899 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 899 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
900 } 900 }
901 901
902 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyBlockingAndQueueingTime) {
903 // These numbers are sensitive to where the histogram buckets are.
904 int event_timestamps_ms[] = {11, 25, 35};
905
906 for (InputEventAckState blocking :
907 {INPUT_EVENT_ACK_STATE_NOT_CONSUMED, INPUT_EVENT_ACK_STATE_CONSUMED}) {
908 {
909 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::kKeyDown,
910 blink::WebInputEvent::kNoModifiers,
911 base::TimeTicks::Now());
912 ui::LatencyInfo latency_info;
913 tracker()->OnInputEvent(event, &latency_info);
914
915 ui::LatencyInfo fake_latency;
916 fake_latency.AddLatencyNumberWithTimestamp(
917 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
918 tracker()->latency_component_id(), 0,
919 base::TimeTicks() +
920 base::TimeDelta::FromMilliseconds(event_timestamps_ms[0]),
921 1);
922
923 fake_latency.AddLatencyNumberWithTimestamp(
924 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
925 base::TimeTicks() +
926 base::TimeDelta::FromMilliseconds(event_timestamps_ms[1]),
927 1);
928
929 fake_latency.AddLatencyNumberWithTimestamp(
930 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
931 base::TimeTicks() +
932 base::TimeDelta::FromMilliseconds(event_timestamps_ms[2]),
933 1);
934
935 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
936 // overwriting components.
937 tracker()->ComputeInputLatencyHistograms(
938 event.GetType(), tracker()->latency_component_id(), fake_latency,
939 blocking);
940
941 tracker()->OnInputEventAck(event, &latency_info, blocking);
942 }
943 }
944
945 EXPECT_THAT(
946 histogram_tester().GetAllSamples(
947 "Event.Latency.QueueingTime.KeyEventDefaultPrevented"),
948 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1)));
949 EXPECT_THAT(
950 histogram_tester().GetAllSamples(
951 "Event.Latency.QueueingTime.KeyEventDefaultAllowed"),
952 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1)));
953 EXPECT_THAT(
954 histogram_tester().GetAllSamples(
955 "Event.Latency.BlockingTime.KeyEventDefaultPrevented"),
956 ElementsAre(Bucket(event_timestamps_ms[2] - event_timestamps_ms[1], 1)));
957 EXPECT_THAT(
958 histogram_tester().GetAllSamples(
959 "Event.Latency.BlockingTime.KeyEventDefaultAllowed"),
960 ElementsAre(Bucket(event_timestamps_ms[2] - event_timestamps_ms[1], 1)));
961 }
962
963 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyUILatency) {
964 // These numbers are sensitive to where the histogram buckets are.
965 int event_timestamps_microseconds[] = {100, 185};
966
967 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::kKeyDown,
968 blink::WebInputEvent::kNoModifiers,
969 base::TimeTicks::Now());
970 ui::LatencyInfo latency_info;
971 latency_info.AddLatencyNumberWithTimestamp(
972 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0,
973 base::TimeTicks() +
974 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
975 1);
976
977 latency_info.AddLatencyNumberWithTimestamp(
978 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
979 tracker()->latency_component_id(), 0,
980 base::TimeTicks() +
981 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
982 1);
983
984 tracker()->OnInputEvent(event, &latency_info);
985 tracker()->OnInputEventAck(event, &latency_info,
986 InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN);
987 EXPECT_THAT(histogram_tester().GetAllSamples("Event.Latency.Browser.KeyUI"),
988 ElementsAre(Bucket(event_timestamps_microseconds[1] -
989 event_timestamps_microseconds[0],
990 1)));
991 }
992
993 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyAckedLatency) {
994 // These numbers are sensitive to where the histogram buckets are.
995 int event_timestamps_microseconds[] = {11, 24};
996
997 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::kKeyDown,
998 blink::WebInputEvent::kNoModifiers,
999 base::TimeTicks::Now());
1000 ui::LatencyInfo latency_info;
1001
1002 latency_info.AddLatencyNumberWithTimestamp(
1003 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1004 tracker()->latency_component_id(), 0,
1005 base::TimeTicks() +
1006 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1007 1);
1008
1009 latency_info.AddLatencyNumberWithTimestamp(
1010 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
1011 base::TimeTicks() +
1012 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1013 1);
1014
1015 tracker()->OnInputEvent(event, &latency_info);
1016 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
1017 // overwriting components.
1018 tracker()->ComputeInputLatencyHistograms(
1019 event.GetType(), tracker()->latency_component_id(), latency_info,
1020 InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN);
1021
1022 EXPECT_THAT(
1023 histogram_tester().GetAllSamples("Event.Latency.Browser.KeyAcked"),
1024 ElementsAre(Bucket(
1025 event_timestamps_microseconds[1] - event_timestamps_microseconds[0],
1026 1)));
1027 }
1028
1029 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyEndToEndLatency) {
1030 // These numbers are sensitive to where the histogram buckets are.
1031 int event_timestamps_microseconds[] = {11, 24};
1032
1033 ui::LatencyInfo latency_info;
1034 latency_info.set_source_event_type(ui::SourceEventType::KEY);
1035 latency_info.AddLatencyNumberWithTimestamp(
1036 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0,
1037 base::TimeTicks() +
1038 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1039 1);
1040
1041 latency_info.AddLatencyNumberWithTimestamp(
1042 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1043 tracker()->latency_component_id(), 0,
1044 base::TimeTicks() +
1045 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1046 1);
1047
1048 latency_info.AddLatencyNumberWithTimestamp(
1049 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0,
1050 base::TimeTicks() +
1051 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1052 1);
1053
1054 latency_info.AddLatencyNumberWithTimestamp(
1055 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
1056 base::TimeTicks() +
1057 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1058 1);
1059
1060 tracker()->OnGpuSwapBuffersCompleted(latency_info);
1061
1062 EXPECT_THAT(histogram_tester().GetAllSamples("Event.Latency.EndToEnd.Key"),
1063 ElementsAre(Bucket(event_timestamps_microseconds[1] -
1064 event_timestamps_microseconds[0],
1065 1)));
1066 }
1067
902 // Event.Latency.(Queueing|Blocking)Time.* histograms shouldn't be reported for 1068 // Event.Latency.(Queueing|Blocking)Time.* histograms shouldn't be reported for
903 // multi-finger touch. 1069 // multi-finger touch.
904 TEST_F(RenderWidgetHostLatencyTrackerTest, 1070 TEST_F(RenderWidgetHostLatencyTrackerTest,
905 MultiFingerTouchIgnoredForQueueingAndBlockingTimeMetrics) { 1071 MultiFingerTouchIgnoredForQueueingAndBlockingTimeMetrics) {
906 SyntheticWebTouchEvent event; 1072 SyntheticWebTouchEvent event;
907 InputEventAckState ack_state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; 1073 InputEventAckState ack_state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
908 1074
909 { 1075 {
910 // First touch start. 1076 // First touch start.
911 ui::LatencyInfo latency; 1077 ui::LatencyInfo latency;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1179
1014 tracker()->OnInputEventAck(wheel_event, &latency, ack_state); 1180 tracker()->OnInputEventAck(wheel_event, &latency, ack_state);
1015 } 1181 }
1016 1182
1017 EXPECT_THAT(histogram_tester().GetAllSamples( 1183 EXPECT_THAT(histogram_tester().GetAllSamples(
1018 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"), 1184 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"),
1019 ElementsAre(Bucket(14, 1))); 1185 ElementsAre(Bucket(14, 1)));
1020 } 1186 }
1021 1187
1022 } // namespace content 1188 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698