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_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "components/rappor/public/rappor_utils.h" |
| 13 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 14 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/common/content_client.h" |
13 #include "ui/events/blink/web_input_event_traits.h" | 16 #include "ui/events/blink/web_input_event_traits.h" |
14 | 17 |
15 using blink::WebGestureEvent; | 18 using blink::WebGestureEvent; |
16 using blink::WebInputEvent; | 19 using blink::WebInputEvent; |
17 using blink::WebMouseEvent; | 20 using blink::WebMouseEvent; |
18 using blink::WebMouseWheelEvent; | 21 using blink::WebMouseWheelEvent; |
19 using blink::WebTouchEvent; | 22 using blink::WebTouchEvent; |
20 using ui::LatencyInfo; | 23 using ui::LatencyInfo; |
21 | 24 |
22 namespace content { | 25 namespace content { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 UMA_HISTOGRAM_SCROLL_LATENCY_LONG( | 234 UMA_HISTOGRAM_SCROLL_LATENCY_LONG( |
232 "Event.Latency.ScrollUpdate.BrowserNotifiedToBeforeGpuSwap", | 235 "Event.Latency.ScrollUpdate.BrowserNotifiedToBeforeGpuSwap", |
233 browser_received_swap_component, gpu_swap_begin_component); | 236 browser_received_swap_component, gpu_swap_begin_component); |
234 | 237 |
235 UMA_HISTOGRAM_SCROLL_LATENCY_SHORT("Event.Latency.ScrollUpdate.GpuSwap", | 238 UMA_HISTOGRAM_SCROLL_LATENCY_SHORT("Event.Latency.ScrollUpdate.GpuSwap", |
236 gpu_swap_begin_component, | 239 gpu_swap_begin_component, |
237 gpu_swap_end_component); | 240 gpu_swap_end_component); |
238 } | 241 } |
239 | 242 |
240 void ComputeTouchAndWheelScrollLatencyHistograms( | 243 void ComputeTouchAndWheelScrollLatencyHistograms( |
| 244 RenderWidgetHostDelegate* render_widget_host_delegate, |
241 const ui::LatencyInfo::LatencyComponent& gpu_swap_begin_component, | 245 const ui::LatencyInfo::LatencyComponent& gpu_swap_begin_component, |
242 const ui::LatencyInfo::LatencyComponent& gpu_swap_end_component, | 246 const ui::LatencyInfo::LatencyComponent& gpu_swap_end_component, |
243 int64_t latency_component_id, | 247 int64_t latency_component_id, |
244 const ui::LatencyInfo& latency, | 248 const ui::LatencyInfo& latency, |
245 const std::string event_type_name) { | 249 const std::string event_type_name) { |
246 DCHECK(!latency.coalesced()); | 250 DCHECK(!latency.coalesced()); |
247 if (latency.coalesced()) | 251 if (latency.coalesced()) |
248 return; | 252 return; |
249 | 253 |
250 LatencyInfo::LatencyComponent original_component; | 254 LatencyInfo::LatencyComponent original_component; |
(...skipping 21 matching lines...) Expand all Loading... |
272 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 276 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
273 latency_component_id, &original_component)) { | 277 latency_component_id, &original_component)) { |
274 // This UMA metric tracks the time from when the original touch event is | 278 // This UMA metric tracks the time from when the original touch event is |
275 // created to when the scroll gesture results in final frame swap. | 279 // created to when the scroll gesture results in final frame swap. |
276 // First scroll events are excluded from this metric. | 280 // First scroll events are excluded from this metric. |
277 if (event_type_name == "Touch") { | 281 if (event_type_name == "Touch") { |
278 UMA_HISTOGRAM_TOUCH_WHEEL_TO_SCROLL_LATENCY( | 282 UMA_HISTOGRAM_TOUCH_WHEEL_TO_SCROLL_LATENCY( |
279 "Event.Latency.ScrollUpdate." + event_type_name + | 283 "Event.Latency.ScrollUpdate." + event_type_name + |
280 ".TimeToScrollUpdateSwapBegin2", | 284 ".TimeToScrollUpdateSwapBegin2", |
281 original_component, gpu_swap_begin_component); | 285 original_component, gpu_swap_begin_component); |
| 286 |
| 287 rappor::RapporService* rappor_service = |
| 288 GetContentClient()->browser()->GetRapporService(); |
| 289 if (rappor_service && render_widget_host_delegate) { |
| 290 std::unique_ptr<rappor::Sample> sample = |
| 291 rappor_service->CreateSample(rappor::UMA_RAPPOR_TYPE); |
| 292 render_widget_host_delegate->AddDomainInfoToRapporSample(sample.get()); |
| 293 sample->SetUInt64Field("Latency", |
| 294 (gpu_swap_begin_component.last_event_time - |
| 295 original_component.first_event_time) |
| 296 .InMicroseconds(), |
| 297 rappor::NO_NOISE); |
| 298 rappor_service->RecordSample( |
| 299 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", |
| 300 std::move(sample)); |
| 301 } |
282 } | 302 } |
283 } else { | 303 } else { |
284 // No original component found. | 304 // No original component found. |
285 return; | 305 return; |
286 } | 306 } |
287 | 307 |
288 LatencyInfo::LatencyComponent rendering_scheduled_component; | 308 LatencyInfo::LatencyComponent rendering_scheduled_component; |
289 bool rendering_scheduled_on_main = latency.FindLatency( | 309 bool rendering_scheduled_on_main = latency.FindLatency( |
290 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, | 310 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, |
291 &rendering_scheduled_component); | 311 &rendering_scheduled_component); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } | 385 } |
366 | 386 |
367 } // namespace | 387 } // namespace |
368 | 388 |
369 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 389 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() |
370 : last_event_id_(0), | 390 : last_event_id_(0), |
371 latency_component_id_(0), | 391 latency_component_id_(0), |
372 device_scale_factor_(1), | 392 device_scale_factor_(1), |
373 has_seen_first_gesture_scroll_update_(false), | 393 has_seen_first_gesture_scroll_update_(false), |
374 multi_finger_gesture_(false), | 394 multi_finger_gesture_(false), |
375 touch_start_default_prevented_(false) {} | 395 touch_start_default_prevented_(false), |
| 396 render_widget_host_delegate_(nullptr) {} |
376 | 397 |
377 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} | 398 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} |
378 | 399 |
379 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 400 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
380 int process_id) { | 401 int process_id) { |
381 DCHECK_EQ(0, last_event_id_); | 402 DCHECK_EQ(0, last_event_id_); |
382 DCHECK_EQ(0, latency_component_id_); | 403 DCHECK_EQ(0, latency_component_id_); |
383 last_event_id_ = static_cast<int64_t>(process_id) << 32; | 404 last_event_id_ = static_cast<int64_t>(process_id) << 32; |
384 latency_component_id_ = routing_id | last_event_id_; | 405 latency_component_id_ = routing_id | last_event_id_; |
385 } | 406 } |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 | 725 |
705 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 726 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
706 latency_component_id_, nullptr)) { | 727 latency_component_id_, nullptr)) { |
707 return; | 728 return; |
708 } | 729 } |
709 | 730 |
710 ui::SourceEventType source_event_type = latency.source_event_type(); | 731 ui::SourceEventType source_event_type = latency.source_event_type(); |
711 if (source_event_type == ui::SourceEventType::WHEEL || | 732 if (source_event_type == ui::SourceEventType::WHEEL || |
712 source_event_type == ui::SourceEventType::TOUCH) { | 733 source_event_type == ui::SourceEventType::TOUCH) { |
713 ComputeTouchAndWheelScrollLatencyHistograms( | 734 ComputeTouchAndWheelScrollLatencyHistograms( |
714 gpu_swap_begin_component, gpu_swap_end_component, latency_component_id_, | 735 render_widget_host_delegate_, gpu_swap_begin_component, |
715 latency, | 736 gpu_swap_end_component, latency_component_id_, latency, |
716 source_event_type == ui::SourceEventType::WHEEL ? "Wheel" : "Touch"); | 737 source_event_type == ui::SourceEventType::WHEEL ? "Wheel" : "Touch"); |
717 } | 738 } |
718 | 739 |
719 // Compute the old scroll update latency metrics. They are exclusively | 740 // Compute the old scroll update latency metrics. They are exclusively |
720 // calculated for touch scrolls, and will be deprecated on M56. | 741 // calculated for touch scrolls, and will be deprecated on M56. |
721 // (https://crbug.com/649754) | 742 // (https://crbug.com/649754) |
722 LatencyInfo::LatencyComponent mouse_wheel_scroll_update_component; | 743 LatencyInfo::LatencyComponent mouse_wheel_scroll_update_component; |
723 if (!latency.FindLatency( | 744 if (!latency.FindLatency( |
724 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, | 745 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, |
725 &mouse_wheel_scroll_update_component)) { | 746 &mouse_wheel_scroll_update_component)) { |
726 ComputeScrollLatencyHistograms( | 747 ComputeScrollLatencyHistograms( |
727 gpu_swap_begin_component, gpu_swap_end_component, latency_component_id_, | 748 gpu_swap_begin_component, gpu_swap_end_component, latency_component_id_, |
728 latency, is_running_navigation_hint_task); | 749 latency, is_running_navigation_hint_task); |
729 } | 750 } |
730 } | 751 } |
731 | 752 |
| 753 void RenderWidgetHostLatencyTracker::SetDelegate( |
| 754 RenderWidgetHostDelegate* delegate) { |
| 755 render_widget_host_delegate_ = delegate; |
| 756 } |
| 757 |
732 } // namespace content | 758 } // namespace content |
OLD | NEW |