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

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: Restrict to RawKeyDown and Char events on Android & Mac 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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 582 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
583 EXPECT_TRUE(scroll_latency.FindLatency( 583 EXPECT_TRUE(scroll_latency.FindLatency(
584 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr)); 584 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr));
585 EXPECT_TRUE(scroll_latency.terminated()); 585 EXPECT_TRUE(scroll_latency.terminated());
586 } 586 }
587 587
588 { 588 {
589 auto wheel = SyntheticWebMouseWheelEventBuilder::Build( 589 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
590 blink::WebMouseWheelEvent::kPhaseChanged); 590 blink::WebMouseWheelEvent::kPhaseChanged);
591 ui::LatencyInfo wheel_latency; 591 ui::LatencyInfo wheel_latency;
592 wheel_latency.set_source_event_type(ui::SourceEventType::WHEEL);
592 AddFakeComponents(*tracker(), &wheel_latency); 593 AddFakeComponents(*tracker(), &wheel_latency);
593 tracker()->OnInputEvent(wheel, &wheel_latency); 594 tracker()->OnInputEvent(wheel, &wheel_latency);
594 tracker()->OnInputEventAck(wheel, &wheel_latency, 595 tracker()->OnInputEventAck(wheel, &wheel_latency,
595 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 596 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
596 EXPECT_TRUE(wheel_latency.FindLatency( 597 EXPECT_TRUE(wheel_latency.FindLatency(
597 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr)); 598 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr));
598 EXPECT_TRUE(wheel_latency.terminated()); 599 EXPECT_TRUE(wheel_latency.terminated());
599 } 600 }
600 601
601 { 602 {
602 SyntheticWebTouchEvent touch; 603 SyntheticWebTouchEvent touch;
603 touch.PressPoint(0, 0); 604 touch.PressPoint(0, 0);
604 ui::LatencyInfo touch_latency; 605 ui::LatencyInfo touch_latency;
606 touch_latency.set_source_event_type(ui::SourceEventType::TOUCH);
605 AddFakeComponents(*tracker(), &touch_latency); 607 AddFakeComponents(*tracker(), &touch_latency);
606 tracker()->OnInputEvent(touch, &touch_latency); 608 tracker()->OnInputEvent(touch, &touch_latency);
607 tracker()->OnInputEventAck(touch, &touch_latency, 609 tracker()->OnInputEventAck(touch, &touch_latency,
608 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 610 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
609 EXPECT_TRUE(touch_latency.FindLatency( 611 EXPECT_TRUE(touch_latency.FindLatency(
610 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr)); 612 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr));
611 EXPECT_TRUE(touch_latency.terminated()); 613 EXPECT_TRUE(touch_latency.terminated());
612 tracker()->OnGpuSwapBuffersCompleted(touch_latency); 614 tracker()->OnGpuSwapBuffersCompleted(touch_latency);
613 } 615 }
614 616
615 { 617 {
616 auto mouse_move = 618 auto mouse_move =
617 SyntheticWebMouseEventBuilder::Build(blink::WebMouseEvent::kMouseMove); 619 SyntheticWebMouseEventBuilder::Build(blink::WebMouseEvent::kMouseMove);
618 ui::LatencyInfo mouse_latency; 620 ui::LatencyInfo mouse_latency;
619 AddFakeComponents(*tracker(), &mouse_latency); 621 AddFakeComponents(*tracker(), &mouse_latency);
620 tracker()->OnInputEvent(mouse_move, &mouse_latency); 622 tracker()->OnInputEvent(mouse_move, &mouse_latency);
621 tracker()->OnInputEventAck(mouse_move, &mouse_latency, 623 tracker()->OnInputEventAck(mouse_move, &mouse_latency,
622 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 624 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
623 EXPECT_TRUE(mouse_latency.FindLatency( 625 EXPECT_TRUE(mouse_latency.FindLatency(
624 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr)); 626 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr));
625 EXPECT_TRUE(mouse_latency.terminated()); 627 EXPECT_TRUE(mouse_latency.terminated());
626 } 628 }
627 629
628 { 630 {
629 auto key_event = 631 auto key_event =
630 SyntheticWebKeyboardEventBuilder::Build(blink::WebKeyboardEvent::kChar); 632 SyntheticWebKeyboardEventBuilder::Build(blink::WebKeyboardEvent::kChar);
631 ui::LatencyInfo key_latency; 633 ui::LatencyInfo key_latency;
634 key_latency.set_source_event_type(ui::SourceEventType::KEY_PRESS);
632 AddFakeComponents(*tracker(), &key_latency); 635 AddFakeComponents(*tracker(), &key_latency);
633 tracker()->OnInputEvent(key_event, &key_latency); 636 tracker()->OnInputEvent(key_event, &key_latency);
634 tracker()->OnInputEventAck(key_event, &key_latency, 637 tracker()->OnInputEventAck(key_event, &key_latency,
635 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 638 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
636 EXPECT_TRUE(key_latency.FindLatency( 639 EXPECT_TRUE(key_latency.FindLatency(
637 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr)); 640 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, nullptr));
638 EXPECT_TRUE(key_latency.terminated()); 641 EXPECT_TRUE(key_latency.terminated());
639 } 642 }
640 643
641 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); 644 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 int touchend_timestamps_ms[] = {3, 8, 12}; 721 int touchend_timestamps_ms[] = {3, 8, 12};
719 722
720 for (InputEventAckState blocking : 723 for (InputEventAckState blocking :
721 {INPUT_EVENT_ACK_STATE_NOT_CONSUMED, INPUT_EVENT_ACK_STATE_CONSUMED}) { 724 {INPUT_EVENT_ACK_STATE_NOT_CONSUMED, INPUT_EVENT_ACK_STATE_CONSUMED}) {
722 SyntheticWebTouchEvent event; 725 SyntheticWebTouchEvent event;
723 { 726 {
724 // Touch start. 727 // Touch start.
725 event.PressPoint(1, 1); 728 event.PressPoint(1, 1);
726 729
727 ui::LatencyInfo latency; 730 ui::LatencyInfo latency;
731 latency.set_source_event_type(ui::SourceEventType::TOUCH);
728 tracker()->OnInputEvent(event, &latency); 732 tracker()->OnInputEvent(event, &latency);
729 733
730 ui::LatencyInfo fake_latency; 734 ui::LatencyInfo fake_latency;
735 fake_latency.set_source_event_type(ui::SourceEventType::TOUCH);
731 fake_latency.AddLatencyNumberWithTimestamp( 736 fake_latency.AddLatencyNumberWithTimestamp(
732 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 737 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
733 tracker()->latency_component_id(), 0, 738 tracker()->latency_component_id(), 0,
734 base::TimeTicks() + 739 base::TimeTicks() +
735 base::TimeDelta::FromMilliseconds(touchstart_timestamps_ms[0]), 740 base::TimeDelta::FromMilliseconds(touchstart_timestamps_ms[0]),
736 1); 741 1);
737 742
738 fake_latency.AddLatencyNumberWithTimestamp( 743 fake_latency.AddLatencyNumberWithTimestamp(
739 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0, 744 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
740 base::TimeTicks() + 745 base::TimeTicks() +
(...skipping 12 matching lines...) Expand all
753 event.GetType(), tracker()->latency_component_id(), fake_latency, 758 event.GetType(), tracker()->latency_component_id(), fake_latency,
754 blocking); 759 blocking);
755 760
756 tracker()->OnInputEventAck(event, &latency, 761 tracker()->OnInputEventAck(event, &latency,
757 blocking); 762 blocking);
758 } 763 }
759 764
760 { 765 {
761 // Touch move. 766 // Touch move.
762 ui::LatencyInfo latency; 767 ui::LatencyInfo latency;
768 latency.set_source_event_type(ui::SourceEventType::TOUCH);
763 event.MovePoint(0, 20, 20); 769 event.MovePoint(0, 20, 20);
764 tracker()->OnInputEvent(event, &latency); 770 tracker()->OnInputEvent(event, &latency);
765 771
766 EXPECT_TRUE(latency.FindLatency( 772 EXPECT_TRUE(latency.FindLatency(
767 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); 773 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
768 EXPECT_TRUE( 774 EXPECT_TRUE(
769 latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 775 latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
770 tracker()->latency_component_id(), nullptr)); 776 tracker()->latency_component_id(), nullptr));
771 777
772 EXPECT_EQ(2U, latency.latency_components().size()); 778 EXPECT_EQ(2U, latency.latency_components().size());
773 779
774 ui::LatencyInfo fake_latency; 780 ui::LatencyInfo fake_latency;
781 fake_latency.set_source_event_type(ui::SourceEventType::TOUCH);
775 fake_latency.AddLatencyNumberWithTimestamp( 782 fake_latency.AddLatencyNumberWithTimestamp(
776 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 783 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
777 tracker()->latency_component_id(), 0, 784 tracker()->latency_component_id(), 0,
778 base::TimeTicks() + 785 base::TimeTicks() +
779 base::TimeDelta::FromMilliseconds(touchmove_timestamps_ms[0]), 786 base::TimeDelta::FromMilliseconds(touchmove_timestamps_ms[0]),
780 1); 787 1);
781 788
782 fake_latency.AddLatencyNumberWithTimestamp( 789 fake_latency.AddLatencyNumberWithTimestamp(
783 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0, 790 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
784 base::TimeTicks() + 791 base::TimeTicks() +
785 base::TimeDelta::FromMilliseconds(touchmove_timestamps_ms[1]), 792 base::TimeDelta::FromMilliseconds(touchmove_timestamps_ms[1]),
786 1); 793 1);
787 794
788 fake_latency.AddLatencyNumberWithTimestamp( 795 fake_latency.AddLatencyNumberWithTimestamp(
789 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0, 796 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
790 base::TimeTicks() + 797 base::TimeTicks() +
791 base::TimeDelta::FromMilliseconds(touchmove_timestamps_ms[2]), 798 base::TimeDelta::FromMilliseconds(touchmove_timestamps_ms[2]),
792 1); 799 1);
793 800
794 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck 801 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
795 // overwriting components. 802 // overwriting components.
796 tracker()->ComputeInputLatencyHistograms( 803 tracker()->ComputeInputLatencyHistograms(
797 event.GetType(), tracker()->latency_component_id(), fake_latency, 804 event.GetType(), tracker()->latency_component_id(), fake_latency,
798 blocking); 805 blocking);
799 } 806 }
800 807
801 { 808 {
802 // Touch end. 809 // Touch end.
803 ui::LatencyInfo latency; 810 ui::LatencyInfo latency;
811 latency.set_source_event_type(ui::SourceEventType::TOUCH);
804 event.ReleasePoint(0); 812 event.ReleasePoint(0);
805 tracker()->OnInputEvent(event, &latency); 813 tracker()->OnInputEvent(event, &latency);
806 814
807 EXPECT_TRUE(latency.FindLatency( 815 EXPECT_TRUE(latency.FindLatency(
808 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); 816 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
809 EXPECT_TRUE( 817 EXPECT_TRUE(
810 latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 818 latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
811 tracker()->latency_component_id(), nullptr)); 819 tracker()->latency_component_id(), nullptr));
812 820
813 EXPECT_EQ(2U, latency.latency_components().size()); 821 EXPECT_EQ(2U, latency.latency_components().size());
814 822
815 ui::LatencyInfo fake_latency; 823 ui::LatencyInfo fake_latency;
824 fake_latency.set_source_event_type(ui::SourceEventType::TOUCH);
816 fake_latency.AddLatencyNumberWithTimestamp( 825 fake_latency.AddLatencyNumberWithTimestamp(
817 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 826 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
818 tracker()->latency_component_id(), 0, 827 tracker()->latency_component_id(), 0,
819 base::TimeTicks() + 828 base::TimeTicks() +
820 base::TimeDelta::FromMilliseconds(touchend_timestamps_ms[0]), 829 base::TimeDelta::FromMilliseconds(touchend_timestamps_ms[0]),
821 1); 830 1);
822 831
823 fake_latency.AddLatencyNumberWithTimestamp( 832 fake_latency.AddLatencyNumberWithTimestamp(
824 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0, 833 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
825 base::TimeTicks() + 834 base::TimeTicks() +
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 EXPECT_THAT(histogram_tester().GetAllSamples( 901 EXPECT_THAT(histogram_tester().GetAllSamples(
893 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), 902 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"),
894 ElementsAre(Bucket( 903 ElementsAre(Bucket(
895 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 904 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
896 EXPECT_THAT(histogram_tester().GetAllSamples( 905 EXPECT_THAT(histogram_tester().GetAllSamples(
897 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), 906 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"),
898 ElementsAre(Bucket( 907 ElementsAre(Bucket(
899 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 908 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
900 } 909 }
901 910
911 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyBlockingAndQueueingTime) {
912 // These numbers are sensitive to where the histogram buckets are.
913 int event_timestamps_ms[] = {11, 25, 35};
914
915 for (InputEventAckState blocking :
916 {INPUT_EVENT_ACK_STATE_NOT_CONSUMED, INPUT_EVENT_ACK_STATE_CONSUMED}) {
917 {
918 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::kRawKeyDown,
919 blink::WebInputEvent::kNoModifiers,
920 base::TimeTicks::Now());
921 ui::LatencyInfo latency_info;
922 latency_info.set_source_event_type(ui::SourceEventType::KEY_PRESS);
923 tracker()->OnInputEvent(event, &latency_info);
924
925 ui::LatencyInfo fake_latency;
926 fake_latency.set_source_event_type(ui::SourceEventType::KEY_PRESS);
927 fake_latency.AddLatencyNumberWithTimestamp(
928 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
929 tracker()->latency_component_id(), 0,
930 base::TimeTicks() +
931 base::TimeDelta::FromMilliseconds(event_timestamps_ms[0]),
932 1);
933
934 fake_latency.AddLatencyNumberWithTimestamp(
935 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
936 base::TimeTicks() +
937 base::TimeDelta::FromMilliseconds(event_timestamps_ms[1]),
938 1);
939
940 fake_latency.AddLatencyNumberWithTimestamp(
941 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
942 base::TimeTicks() +
943 base::TimeDelta::FromMilliseconds(event_timestamps_ms[2]),
944 1);
945
946 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
947 // overwriting components.
948 tracker()->ComputeInputLatencyHistograms(
949 event.GetType(), tracker()->latency_component_id(), fake_latency,
950 blocking);
951
952 tracker()->OnInputEventAck(event, &latency_info, blocking);
953 }
954 }
955
956 EXPECT_THAT(
957 histogram_tester().GetAllSamples(
958 "Event.Latency.QueueingTime.KeyPressDefaultPrevented"),
959 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1)));
960 EXPECT_THAT(
961 histogram_tester().GetAllSamples(
962 "Event.Latency.QueueingTime.KeyPressDefaultAllowed"),
963 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1)));
964 EXPECT_THAT(
965 histogram_tester().GetAllSamples(
966 "Event.Latency.BlockingTime.KeyPressDefaultPrevented"),
967 ElementsAre(Bucket(event_timestamps_ms[2] - event_timestamps_ms[1], 1)));
968 EXPECT_THAT(
969 histogram_tester().GetAllSamples(
970 "Event.Latency.BlockingTime.KeyPressDefaultAllowed"),
971 ElementsAre(Bucket(event_timestamps_ms[2] - event_timestamps_ms[1], 1)));
972 }
973
974 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyUILatency) {
975 // These numbers are sensitive to where the histogram buckets are.
976 int event_timestamps_microseconds[] = {100, 185};
977
978 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::kChar,
979 blink::WebInputEvent::kNoModifiers,
980 base::TimeTicks::Now());
981 ui::LatencyInfo latency_info;
982 latency_info.set_source_event_type(ui::SourceEventType::KEY_PRESS);
983 latency_info.AddLatencyNumberWithTimestamp(
984 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0,
985 base::TimeTicks() +
986 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
987 1);
988
989 latency_info.AddLatencyNumberWithTimestamp(
990 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
991 tracker()->latency_component_id(), 0,
992 base::TimeTicks() +
993 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
994 1);
995
996 tracker()->OnInputEvent(event, &latency_info);
997 tracker()->OnInputEventAck(event, &latency_info,
998 InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN);
999 EXPECT_THAT(
1000 histogram_tester().GetAllSamples("Event.Latency.Browser.KeyPressUI"),
1001 ElementsAre(Bucket(
1002 event_timestamps_microseconds[1] - event_timestamps_microseconds[0],
1003 1)));
1004 }
1005
1006 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyAckedLatency) {
1007 // These numbers are sensitive to where the histogram buckets are.
1008 int event_timestamps_microseconds[] = {11, 24};
1009
1010 NativeWebKeyboardEvent event(blink::WebKeyboardEvent::kRawKeyDown,
1011 blink::WebInputEvent::kNoModifiers,
1012 base::TimeTicks::Now());
1013 ui::LatencyInfo latency_info;
1014 latency_info.set_source_event_type(ui::SourceEventType::KEY_PRESS);
1015
1016 latency_info.AddLatencyNumberWithTimestamp(
1017 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1018 tracker()->latency_component_id(), 0,
1019 base::TimeTicks() +
1020 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1021 1);
1022
1023 latency_info.AddLatencyNumberWithTimestamp(
1024 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0,
1025 base::TimeTicks() +
1026 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1027 1);
1028
1029 tracker()->OnInputEvent(event, &latency_info);
1030 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck
1031 // overwriting components.
1032 tracker()->ComputeInputLatencyHistograms(
1033 event.GetType(), tracker()->latency_component_id(), latency_info,
1034 InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN);
1035
1036 EXPECT_THAT(
1037 histogram_tester().GetAllSamples("Event.Latency.Browser.KeyPressAcked"),
1038 ElementsAre(Bucket(
1039 event_timestamps_microseconds[1] - event_timestamps_microseconds[0],
1040 1)));
1041 }
1042
1043 TEST_F(RenderWidgetHostLatencyTrackerTest, KeyEndToEndLatency) {
1044 // These numbers are sensitive to where the histogram buckets are.
1045 int event_timestamps_microseconds[] = {11, 24};
1046
1047 ui::LatencyInfo latency_info;
1048 latency_info.set_source_event_type(ui::SourceEventType::KEY_PRESS);
1049 latency_info.AddLatencyNumberWithTimestamp(
1050 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0,
1051 base::TimeTicks() +
1052 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1053 1);
1054
1055 latency_info.AddLatencyNumberWithTimestamp(
1056 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1057 tracker()->latency_component_id(), 0,
1058 base::TimeTicks() +
1059 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[0]),
1060 1);
1061
1062 latency_info.AddLatencyNumberWithTimestamp(
1063 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0,
1064 base::TimeTicks() +
1065 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1066 1);
1067
1068 latency_info.AddLatencyNumberWithTimestamp(
1069 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
1070 base::TimeTicks() +
1071 base::TimeDelta::FromMicroseconds(event_timestamps_microseconds[1]),
1072 1);
1073
1074 tracker()->OnGpuSwapBuffersCompleted(latency_info);
1075
1076 EXPECT_THAT(
1077 histogram_tester().GetAllSamples("Event.Latency.EndToEnd.KeyPress"),
1078 ElementsAre(Bucket(
1079 event_timestamps_microseconds[1] - event_timestamps_microseconds[0],
1080 1)));
1081 }
1082
902 // Event.Latency.(Queueing|Blocking)Time.* histograms shouldn't be reported for 1083 // Event.Latency.(Queueing|Blocking)Time.* histograms shouldn't be reported for
903 // multi-finger touch. 1084 // multi-finger touch.
904 TEST_F(RenderWidgetHostLatencyTrackerTest, 1085 TEST_F(RenderWidgetHostLatencyTrackerTest,
905 MultiFingerTouchIgnoredForQueueingAndBlockingTimeMetrics) { 1086 MultiFingerTouchIgnoredForQueueingAndBlockingTimeMetrics) {
906 SyntheticWebTouchEvent event; 1087 SyntheticWebTouchEvent event;
907 InputEventAckState ack_state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; 1088 InputEventAckState ack_state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
908 1089
909 { 1090 {
910 // First touch start. 1091 // First touch start.
911 ui::LatencyInfo latency; 1092 ui::LatencyInfo latency;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 // Some touch input histograms aren't reported for multi-finger touch. Other 1140 // Some touch input histograms aren't reported for multi-finger touch. Other
960 // input modalities shouldn't be impacted by there being an active multi-finger 1141 // input modalities shouldn't be impacted by there being an active multi-finger
961 // touch gesture. 1142 // touch gesture.
962 TEST_F(RenderWidgetHostLatencyTrackerTest, WheelDuringMultiFingerTouch) { 1143 TEST_F(RenderWidgetHostLatencyTrackerTest, WheelDuringMultiFingerTouch) {
963 SyntheticWebTouchEvent touch_event; 1144 SyntheticWebTouchEvent touch_event;
964 InputEventAckState ack_state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; 1145 InputEventAckState ack_state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
965 1146
966 { 1147 {
967 // First touch start. 1148 // First touch start.
968 ui::LatencyInfo latency; 1149 ui::LatencyInfo latency;
1150 latency.set_source_event_type(ui::SourceEventType::TOUCH);
969 touch_event.PressPoint(1, 1); 1151 touch_event.PressPoint(1, 1);
970 tracker()->OnInputEvent(touch_event, &latency); 1152 tracker()->OnInputEvent(touch_event, &latency);
971 tracker()->OnInputEventAck(touch_event, &latency, ack_state); 1153 tracker()->OnInputEventAck(touch_event, &latency, ack_state);
972 } 1154 }
973 1155
974 { 1156 {
975 // Second touch start. 1157 // Second touch start.
976 ui::LatencyInfo latency; 1158 ui::LatencyInfo latency;
1159 latency.set_source_event_type(ui::SourceEventType::TOUCH);
977 touch_event.PressPoint(1, 1); 1160 touch_event.PressPoint(1, 1);
978 tracker()->OnInputEvent(touch_event, &latency); 1161 tracker()->OnInputEvent(touch_event, &latency);
979 tracker()->OnInputEventAck(touch_event, &latency, ack_state); 1162 tracker()->OnInputEventAck(touch_event, &latency, ack_state);
980 } 1163 }
981 1164
982 { 1165 {
983 // Wheel event. 1166 // Wheel event.
984 ui::LatencyInfo latency; 1167 ui::LatencyInfo latency;
1168 latency.set_source_event_type(ui::SourceEventType::WHEEL);
985 // These numbers are sensitive to where the histogram buckets are. 1169 // These numbers are sensitive to where the histogram buckets are.
986 int timestamps_ms[] = {11, 25, 35}; 1170 int timestamps_ms[] = {11, 25, 35};
987 auto wheel_event = SyntheticWebMouseWheelEventBuilder::Build( 1171 auto wheel_event = SyntheticWebMouseWheelEventBuilder::Build(
988 blink::WebMouseWheelEvent::kPhaseChanged); 1172 blink::WebMouseWheelEvent::kPhaseChanged);
989 tracker()->OnInputEvent(touch_event, &latency); 1173 tracker()->OnInputEvent(touch_event, &latency);
990 1174
991 ui::LatencyInfo fake_latency; 1175 ui::LatencyInfo fake_latency;
1176 fake_latency.set_source_event_type(ui::SourceEventType::TOUCH);
992 fake_latency.AddLatencyNumberWithTimestamp( 1177 fake_latency.AddLatencyNumberWithTimestamp(
993 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1178 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
994 tracker()->latency_component_id(), 0, 1179 tracker()->latency_component_id(), 0,
995 base::TimeTicks() + base::TimeDelta::FromMilliseconds(timestamps_ms[0]), 1180 base::TimeTicks() + base::TimeDelta::FromMilliseconds(timestamps_ms[0]),
996 1); 1181 1);
997 1182
998 fake_latency.AddLatencyNumberWithTimestamp( 1183 fake_latency.AddLatencyNumberWithTimestamp(
999 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0, 1184 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0,
1000 base::TimeTicks() + base::TimeDelta::FromMilliseconds(timestamps_ms[1]), 1185 base::TimeTicks() + base::TimeDelta::FromMilliseconds(timestamps_ms[1]),
1001 1); 1186 1);
(...skipping 11 matching lines...) Expand all
1013 1198
1014 tracker()->OnInputEventAck(wheel_event, &latency, ack_state); 1199 tracker()->OnInputEventAck(wheel_event, &latency, ack_state);
1015 } 1200 }
1016 1201
1017 EXPECT_THAT(histogram_tester().GetAllSamples( 1202 EXPECT_THAT(histogram_tester().GetAllSamples(
1018 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"), 1203 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"),
1019 ElementsAre(Bucket(14, 1))); 1204 ElementsAre(Bucket(14, 1)));
1020 } 1205 }
1021 1206
1022 } // namespace content 1207 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698