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 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_functions.h" | 10 #include "base/metrics/histogram_functions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 using blink::WebTouchEvent; | 24 using blink::WebTouchEvent; |
25 using ui::LatencyInfo; | 25 using ui::LatencyInfo; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 namespace { | 28 namespace { |
29 | 29 |
30 std::string WebInputEventTypeToInputModalityString(WebInputEvent::Type type) { | 30 std::string WebInputEventTypeToInputModalityString(WebInputEvent::Type type) { |
31 if (type == blink::WebInputEvent::kMouseWheel) { | 31 if (type == blink::WebInputEvent::kMouseWheel) { |
32 return "Wheel"; | 32 return "Wheel"; |
33 } else if (WebInputEvent::IsKeyboardEventType(type)) { | 33 } else if (WebInputEvent::IsKeyboardEventType(type)) { |
34 return "Key"; | 34 // We should only be reporting latency for key presses. |
| 35 DCHECK(type == WebInputEvent::kRawKeyDown || type == WebInputEvent::kChar); |
| 36 return "KeyPress"; |
35 } else if (WebInputEvent::IsMouseEventType(type)) { | 37 } else if (WebInputEvent::IsMouseEventType(type)) { |
36 return "Mouse"; | 38 return "Mouse"; |
37 } else if (WebInputEvent::IsTouchEventType(type)) { | 39 } else if (WebInputEvent::IsTouchEventType(type)) { |
38 return "Touch"; | 40 return "Touch"; |
39 } | 41 } |
40 return ""; | 42 return ""; |
41 } | 43 } |
42 | 44 |
43 // LatencyComponents generated in the renderer must have component IDs | 45 // LatencyComponents generated in the renderer must have component IDs |
44 // provided to them by the browser process. This function adds the correct | 46 // provided to them by the browser process. This function adds the correct |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms( | 97 void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms( |
96 WebInputEvent::Type type, | 98 WebInputEvent::Type type, |
97 int64_t latency_component_id, | 99 int64_t latency_component_id, |
98 const LatencyInfo& latency, | 100 const LatencyInfo& latency, |
99 InputEventAckState ack_result) { | 101 InputEventAckState ack_result) { |
100 // If this event was coalesced into another event, ignore it, as the event it | 102 // If this event was coalesced into another event, ignore it, as the event it |
101 // was coalesced into will reflect the full latency. | 103 // was coalesced into will reflect the full latency. |
102 if (latency.coalesced()) | 104 if (latency.coalesced()) |
103 return; | 105 return; |
104 | 106 |
105 if (type != blink::WebInputEvent::kMouseWheel && | 107 if (latency.source_event_type() == ui::SourceEventType::UNKNOWN || |
106 !WebInputEvent::IsTouchEventType(type)) { | 108 latency.source_event_type() == ui::SourceEventType::OTHER) { |
107 return; | 109 return; |
108 } | 110 } |
109 | 111 |
110 LatencyInfo::LatencyComponent rwh_component; | 112 LatencyInfo::LatencyComponent rwh_component; |
111 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 113 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
112 latency_component_id, &rwh_component)) { | 114 latency_component_id, &rwh_component)) { |
113 return; | 115 return; |
114 } | 116 } |
115 DCHECK_EQ(rwh_component.event_count, 1u); | 117 DCHECK_EQ(rwh_component.event_count, 1u); |
116 | 118 |
117 bool multi_finger_touch_gesture = | 119 bool multi_finger_touch_gesture = |
118 WebInputEvent::IsTouchEventType(type) && active_multi_finger_gesture_; | 120 WebInputEvent::IsTouchEventType(type) && active_multi_finger_gesture_; |
119 | 121 |
120 LatencyInfo::LatencyComponent ui_component; | 122 LatencyInfo::LatencyComponent ui_component; |
121 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, | 123 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, |
122 &ui_component)) { | 124 &ui_component)) { |
123 DCHECK_EQ(ui_component.event_count, 1u); | 125 DCHECK_EQ(ui_component.event_count, 1u); |
124 base::TimeDelta ui_delta = | 126 base::TimeDelta ui_delta = |
125 rwh_component.last_event_time - ui_component.first_event_time; | 127 rwh_component.last_event_time - ui_component.first_event_time; |
126 | 128 |
127 if (type == blink::WebInputEvent::kMouseWheel) { | 129 if (latency.source_event_type() == ui::SourceEventType::WHEEL) { |
128 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.WheelUI", | 130 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.WheelUI", |
129 ui_delta.InMicroseconds(), 1, 20000, 100); | 131 ui_delta.InMicroseconds(), 1, 20000, 100); |
130 } else { | 132 } else if (latency.source_event_type() == ui::SourceEventType::TOUCH) { |
131 DCHECK(WebInputEvent::IsTouchEventType(type)); | |
132 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.TouchUI", | 133 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.TouchUI", |
133 ui_delta.InMicroseconds(), 1, 20000, 100); | 134 ui_delta.InMicroseconds(), 1, 20000, 100); |
| 135 } else if (latency.source_event_type() == ui::SourceEventType::KEY_PRESS) { |
| 136 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.KeyPressUI", |
| 137 ui_delta.InMicroseconds(), 1, 20000, 50); |
| 138 } else { |
| 139 // We should only report these histograms for wheel, touch and keyboard. |
| 140 NOTREACHED(); |
134 } | 141 } |
135 } | 142 } |
136 | 143 |
137 // Both tap and scroll gestures depend on the disposition of the touch start | 144 // Touchscreen tap and scroll gestures depend on the disposition of the touch |
138 // and the current touch. For touch start, touch_start_default_prevented_ == | 145 // start and the current touch. For touch start, |
139 // (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED). | 146 // touch_start_default_prevented_ == (ack_result == |
| 147 // INPUT_EVENT_ACK_STATE_CONSUMED). |
140 bool action_prevented = touch_start_default_prevented_ || | 148 bool action_prevented = touch_start_default_prevented_ || |
141 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; | 149 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |
142 | 150 |
143 std::string event_name = WebInputEvent::GetName(type); | 151 std::string event_name = WebInputEvent::GetName(type); |
144 | 152 |
| 153 if (latency.source_event_type() == ui::KEY_PRESS) |
| 154 event_name = "KeyPress"; |
| 155 |
145 std::string default_action_status = | 156 std::string default_action_status = |
146 action_prevented ? "DefaultPrevented" : "DefaultAllowed"; | 157 action_prevented ? "DefaultPrevented" : "DefaultAllowed"; |
147 | 158 |
148 LatencyInfo::LatencyComponent main_component; | 159 LatencyInfo::LatencyComponent main_component; |
149 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, | 160 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, |
150 &main_component)) { | 161 &main_component)) { |
151 DCHECK_EQ(main_component.event_count, 1u); | 162 DCHECK_EQ(main_component.event_count, 1u); |
152 if (!multi_finger_touch_gesture) { | 163 if (!multi_finger_touch_gesture) { |
153 UMA_HISTOGRAM_INPUT_LATENCY_MILLISECONDS( | 164 UMA_HISTOGRAM_INPUT_LATENCY_MILLISECONDS( |
154 "Event.Latency.QueueingTime." + event_name + default_action_status, | 165 "Event.Latency.QueueingTime." + event_name + default_action_status, |
(...skipping 26 matching lines...) Expand all Loading... |
181 LatencyInfo* latency) { | 192 LatencyInfo* latency) { |
182 DCHECK(latency); | 193 DCHECK(latency); |
183 | 194 |
184 if (event.GetType() == WebInputEvent::kTouchStart) { | 195 if (event.GetType() == WebInputEvent::kTouchStart) { |
185 const WebTouchEvent& touch_event = | 196 const WebTouchEvent& touch_event = |
186 *static_cast<const WebTouchEvent*>(&event); | 197 *static_cast<const WebTouchEvent*>(&event); |
187 DCHECK(touch_event.touches_length >= 1); | 198 DCHECK(touch_event.touches_length >= 1); |
188 active_multi_finger_gesture_ = touch_event.touches_length != 1; | 199 active_multi_finger_gesture_ = touch_event.touches_length != 1; |
189 } | 200 } |
190 | 201 |
| 202 if (latency->source_event_type() == ui::KEY_PRESS) { |
| 203 DCHECK(event.GetType() == WebInputEvent::kChar || |
| 204 event.GetType() == WebInputEvent::kRawKeyDown); |
| 205 } |
| 206 |
191 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 207 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
192 latency_component_id_, NULL)) { | 208 latency_component_id_, NULL)) { |
193 return; | 209 return; |
194 } | 210 } |
195 | 211 |
196 if (event.TimeStampSeconds() && | 212 if (event.TimeStampSeconds() && |
197 !latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, | 213 !latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, |
198 NULL)) { | 214 NULL)) { |
199 base::TimeTicks timestamp_now = base::TimeTicks::Now(); | 215 base::TimeTicks timestamp_now = base::TimeTicks::Now(); |
200 base::TimeTicks timestamp_original = | 216 base::TimeTicks timestamp_original = |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 sample->SetUInt64Field( | 319 sample->SetUInt64Field( |
304 "Latency", | 320 "Latency", |
305 (end_component.last_event_time - start_component.first_event_time) | 321 (end_component.last_event_time - start_component.first_event_time) |
306 .InMicroseconds(), | 322 .InMicroseconds(), |
307 rappor::NO_NOISE); | 323 rappor::NO_NOISE); |
308 rappor_service->RecordSample(name, std::move(sample)); | 324 rappor_service->RecordSample(name, std::move(sample)); |
309 } | 325 } |
310 } | 326 } |
311 | 327 |
312 } // namespace content | 328 } // namespace content |
OLD | NEW |