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/render_widget_host_latency_tracker.h" | 5 #include "content/browser/renderer_host/render_widget_host_latency_tracker.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 | 10 |
11 using blink::WebGestureEvent; | 11 using blink::WebGestureEvent; |
12 using blink::WebInputEvent; | 12 using blink::WebInputEvent; |
13 using blink::WebMouseEvent; | 13 using blink::WebMouseEvent; |
14 using blink::WebMouseWheelEvent; | 14 using blink::WebMouseWheelEvent; |
15 using blink::WebTouchEvent; | 15 using blink::WebTouchEvent; |
16 using ui::LatencyInfo; | 16 using ui::LatencyInfo; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 namespace { | 19 namespace { |
20 | 20 |
21 const uint32 kMaxInputCoordinates = LatencyInfo::kMaxInputCoordinates; | 21 const uint32 kMaxInputCoordinates = LatencyInfo::kMaxInputCoordinates; |
| 22 const size_t kBrowserCompositeLatencyHistorySize = 60; |
| 23 const double kBrowserCompositeLatencyEstimationPercentile = 90.0; |
| 24 const double kBrowserCompositeLatencyEstimationSlack = 1.1; |
22 | 25 |
23 void UpdateLatencyCoordinatesImpl(const blink::WebTouchEvent& touch, | 26 void UpdateLatencyCoordinatesImpl(const blink::WebTouchEvent& touch, |
24 LatencyInfo* latency) { | 27 LatencyInfo* latency) { |
25 latency->input_coordinates_size = | 28 latency->input_coordinates_size = |
26 std::min(kMaxInputCoordinates, touch.touchesLength); | 29 std::min(kMaxInputCoordinates, touch.touchesLength); |
27 for (uint32 i = 0; i < latency->input_coordinates_size; ++i) { | 30 for (uint32 i = 0; i < latency->input_coordinates_size; ++i) { |
28 latency->input_coordinates[i] = LatencyInfo::InputCoordinate( | 31 latency->input_coordinates[i] = LatencyInfo::InputCoordinate( |
29 touch.touches[i].position.x, touch.touches[i].position.y); | 32 touch.touches[i].position.x, touch.touches[i].position.y); |
30 } | 33 } |
31 } | 34 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 159 |
157 // Add newly generated components into the latency info | 160 // Add newly generated components into the latency info |
158 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { | 161 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { |
159 latency->latency_components[lc->first] = lc->second; | 162 latency->latency_components[lc->first] = lc->second; |
160 } | 163 } |
161 } | 164 } |
162 | 165 |
163 } // namespace | 166 } // namespace |
164 | 167 |
165 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 168 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() |
166 : last_event_id_(0), latency_component_id_(0), device_scale_factor_(1) { | 169 : last_event_id_(0), |
| 170 latency_component_id_(0), |
| 171 device_scale_factor_(1), |
| 172 browser_composite_latency_history_(kBrowserCompositeLatencyHistorySize) { |
167 } | 173 } |
168 | 174 |
169 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() { | 175 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() { |
170 } | 176 } |
171 | 177 |
172 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 178 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
173 int process_id) { | 179 int process_id) { |
174 DCHECK_EQ(0, last_event_id_); | 180 DCHECK_EQ(0, last_event_id_); |
175 DCHECK_EQ(0, latency_component_id_); | 181 DCHECK_EQ(0, latency_component_id_); |
176 last_event_id_ = static_cast<int64>(process_id) << 32; | 182 last_event_id_ = static_cast<int64>(process_id) << 32; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 return; | 256 return; |
251 } | 257 } |
252 | 258 |
253 // TODO(jdduke): Determine if mouse and keyboard events are worth hooking | 259 // TODO(jdduke): Determine if mouse and keyboard events are worth hooking |
254 // into LatencyInfo. | 260 // into LatencyInfo. |
255 } | 261 } |
256 | 262 |
257 void RenderWidgetHostLatencyTracker::OnSwapCompositorFrame( | 263 void RenderWidgetHostLatencyTracker::OnSwapCompositorFrame( |
258 std::vector<LatencyInfo>* latencies) { | 264 std::vector<LatencyInfo>* latencies) { |
259 DCHECK(latencies); | 265 DCHECK(latencies); |
260 for (LatencyInfo& latency : *latencies) | 266 for (LatencyInfo& latency : *latencies) { |
261 AddLatencyInfoComponentIds(&latency, latency_component_id_); | 267 AddLatencyInfoComponentIds(&latency, latency_component_id_); |
| 268 latency.AddLatencyNumber( |
| 269 ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT, 0, 0); |
| 270 } |
262 } | 271 } |
263 | 272 |
264 void RenderWidgetHostLatencyTracker::OnFrameSwapped( | 273 void RenderWidgetHostLatencyTracker::OnFrameSwapped( |
265 const ui::LatencyInfo& latency) { | 274 const ui::LatencyInfo& latency) { |
266 LatencyInfo::LatencyComponent swap_component; | 275 LatencyInfo::LatencyComponent swap_component; |
267 if (!latency.FindLatency( | 276 if (!latency.FindLatency( |
268 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, | 277 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, |
269 &swap_component)) { | 278 &swap_component)) { |
270 return; | 279 return; |
271 } | 280 } |
(...skipping 24 matching lines...) Expand all Loading... |
296 for (size_t i = 0; i < original_component.event_count; i++) { | 305 for (size_t i = 0; i < original_component.event_count; i++) { |
297 UMA_HISTOGRAM_CUSTOM_COUNTS( | 306 UMA_HISTOGRAM_CUSTOM_COUNTS( |
298 "Event.Latency.TouchToScrollUpdateSwap", | 307 "Event.Latency.TouchToScrollUpdateSwap", |
299 (swap_component.event_time - original_component.event_time) | 308 (swap_component.event_time - original_component.event_time) |
300 .InMicroseconds(), | 309 .InMicroseconds(), |
301 1, | 310 1, |
302 1000000, | 311 1000000, |
303 100); | 312 100); |
304 } | 313 } |
305 } | 314 } |
| 315 |
| 316 ui::LatencyInfo::LatencyComponent gpu_swap_component; |
| 317 if (!latency.FindLatency(ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, |
| 318 &gpu_swap_component)) { |
| 319 return; |
| 320 } |
| 321 |
| 322 ui::LatencyInfo::LatencyComponent browser_swap_component; |
| 323 if (latency.FindLatency( |
| 324 ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT, 0, |
| 325 &browser_swap_component)) { |
| 326 base::TimeDelta delta = |
| 327 gpu_swap_component.event_time - browser_swap_component.event_time; |
| 328 browser_composite_latency_history_.InsertSample(delta); |
| 329 } |
| 330 } |
| 331 |
| 332 base::TimeDelta |
| 333 RenderWidgetHostLatencyTracker::GetEstimatedBrowserCompositeTime() const { |
| 334 // TODO(brianderson): Remove lower bound on estimate once we're sure it won't |
| 335 // cause regressions. |
| 336 return std::max( |
| 337 browser_composite_latency_history_.Percentile( |
| 338 kBrowserCompositeLatencyEstimationPercentile) * |
| 339 kBrowserCompositeLatencyEstimationSlack, |
| 340 base::TimeDelta::FromMicroseconds( |
| 341 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60))); |
306 } | 342 } |
307 | 343 |
308 } // namespace content | 344 } // namespace content |
OLD | NEW |