| 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" | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   53 void UpdateLatencyCoordinatesImpl(const WebMouseWheelEvent& wheel, |   53 void UpdateLatencyCoordinatesImpl(const WebMouseWheelEvent& wheel, | 
|   54                                   LatencyInfo* latency, |   54                                   LatencyInfo* latency, | 
|   55                                   float device_scale_factor) { |   55                                   float device_scale_factor) { | 
|   56   latency->AddInputCoordinate(gfx::PointF(wheel.x * device_scale_factor, |   56   latency->AddInputCoordinate(gfx::PointF(wheel.x * device_scale_factor, | 
|   57                                           wheel.y * device_scale_factor)); |   57                                           wheel.y * device_scale_factor)); | 
|   58 } |   58 } | 
|   59  |   59  | 
|   60 void UpdateLatencyCoordinates(const WebInputEvent& event, |   60 void UpdateLatencyCoordinates(const WebInputEvent& event, | 
|   61                               float device_scale_factor, |   61                               float device_scale_factor, | 
|   62                               LatencyInfo* latency) { |   62                               LatencyInfo* latency) { | 
|   63   if (WebInputEvent::isMouseEventType(event.type)) { |   63   if (WebInputEvent::isMouseEventType(event.type())) { | 
|   64     UpdateLatencyCoordinatesImpl(static_cast<const WebMouseEvent&>(event), |   64     UpdateLatencyCoordinatesImpl(static_cast<const WebMouseEvent&>(event), | 
|   65                                  latency, device_scale_factor); |   65                                  latency, device_scale_factor); | 
|   66   } else if (WebInputEvent::isGestureEventType(event.type)) { |   66   } else if (WebInputEvent::isGestureEventType(event.type())) { | 
|   67     UpdateLatencyCoordinatesImpl(static_cast<const WebGestureEvent&>(event), |   67     UpdateLatencyCoordinatesImpl(static_cast<const WebGestureEvent&>(event), | 
|   68                                  latency, device_scale_factor); |   68                                  latency, device_scale_factor); | 
|   69   } else if (WebInputEvent::isTouchEventType(event.type)) { |   69   } else if (WebInputEvent::isTouchEventType(event.type())) { | 
|   70     UpdateLatencyCoordinatesImpl(static_cast<const WebTouchEvent&>(event), |   70     UpdateLatencyCoordinatesImpl(static_cast<const WebTouchEvent&>(event), | 
|   71                                  latency, device_scale_factor); |   71                                  latency, device_scale_factor); | 
|   72   } else if (event.type == WebInputEvent::MouseWheel) { |   72   } else if (event.type() == WebInputEvent::MouseWheel) { | 
|   73     UpdateLatencyCoordinatesImpl(static_cast<const WebMouseWheelEvent&>(event), |   73     UpdateLatencyCoordinatesImpl(static_cast<const WebMouseWheelEvent&>(event), | 
|   74                                  latency, device_scale_factor); |   74                                  latency, device_scale_factor); | 
|   75   } |   75   } | 
|   76 } |   76 } | 
|   77  |   77  | 
|   78 // Touch to scroll latency that is mostly under 1 second. |   78 // Touch to scroll latency that is mostly under 1 second. | 
|   79 #define UMA_HISTOGRAM_TOUCH_TO_SCROLL_LATENCY(name, start, end)               \ |   79 #define UMA_HISTOGRAM_TOUCH_TO_SCROLL_LATENCY(name, start, end)               \ | 
|   80   UMA_HISTOGRAM_CUSTOM_COUNTS(                                                \ |   80   UMA_HISTOGRAM_CUSTOM_COUNTS(                                                \ | 
|   81       name, (end.event_time - start.event_time).InMicroseconds(), 1, 1000000, \ |   81       name, (end.event_time - start.event_time).InMicroseconds(), 1, 1000000, \ | 
|   82       100) |   82       100) | 
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  577  |  577  | 
|  578 void RenderWidgetHostLatencyTracker::OnInputEvent( |  578 void RenderWidgetHostLatencyTracker::OnInputEvent( | 
|  579     const blink::WebInputEvent& event, |  579     const blink::WebInputEvent& event, | 
|  580     LatencyInfo* latency) { |  580     LatencyInfo* latency) { | 
|  581   DCHECK(latency); |  581   DCHECK(latency); | 
|  582   if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |  582   if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 
|  583                            latency_component_id_, NULL)) { |  583                            latency_component_id_, NULL)) { | 
|  584     return; |  584     return; | 
|  585   } |  585   } | 
|  586  |  586  | 
|  587   if (event.timeStampSeconds && |  587   if (event.timeStampSeconds() && | 
|  588       !latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |  588       !latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, | 
|  589                             0, NULL)) { |  589                             NULL)) { | 
|  590     base::TimeTicks timestamp_now = base::TimeTicks::Now(); |  590     base::TimeTicks timestamp_now = base::TimeTicks::Now(); | 
|  591     base::TimeTicks timestamp_original = base::TimeTicks() + |  591     base::TimeTicks timestamp_original = | 
|  592         base::TimeDelta::FromSecondsD(event.timeStampSeconds); |  592         base::TimeTicks() + | 
 |  593         base::TimeDelta::FromSecondsD(event.timeStampSeconds()); | 
|  593  |  594  | 
|  594     // Timestamp from platform input can wrap, e.g. 32 bits timestamp |  595     // Timestamp from platform input can wrap, e.g. 32 bits timestamp | 
|  595     // for Xserver and Window MSG time will wrap about 49.6 days. Do a |  596     // for Xserver and Window MSG time will wrap about 49.6 days. Do a | 
|  596     // sanity check here and if wrap does happen, use TimeTicks::Now() |  597     // sanity check here and if wrap does happen, use TimeTicks::Now() | 
|  597     // as the timestamp instead. |  598     // as the timestamp instead. | 
|  598     if ((timestamp_now - timestamp_original).InDays() > 0) |  599     if ((timestamp_now - timestamp_original).InDays() > 0) | 
|  599       timestamp_original = timestamp_now; |  600       timestamp_original = timestamp_now; | 
|  600  |  601  | 
|  601     latency->AddLatencyNumberWithTimestamp( |  602     latency->AddLatencyNumberWithTimestamp( | 
|  602         ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |  603         ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 
|  603         0, |  604         0, | 
|  604         0, |  605         0, | 
|  605         timestamp_original, |  606         timestamp_original, | 
|  606         1); |  607         1); | 
|  607   } |  608   } | 
|  608  |  609  | 
|  609   latency->AddLatencyNumberWithTraceName( |  610   latency->AddLatencyNumberWithTraceName( | 
|  610       ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, |  611       ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, | 
|  611       ++last_event_id_, WebInputEvent::GetName(event.type)); |  612       ++last_event_id_, WebInputEvent::GetName(event.type())); | 
|  612  |  613  | 
|  613   UpdateLatencyCoordinates(event, device_scale_factor_, latency); |  614   UpdateLatencyCoordinates(event, device_scale_factor_, latency); | 
|  614  |  615  | 
|  615   if (event.type == blink::WebInputEvent::GestureScrollBegin) { |  616   if (event.type() == blink::WebInputEvent::GestureScrollBegin) { | 
|  616     has_seen_first_gesture_scroll_update_ = false; |  617     has_seen_first_gesture_scroll_update_ = false; | 
|  617   } else if (event.type == blink::WebInputEvent::GestureScrollUpdate) { |  618   } else if (event.type() == blink::WebInputEvent::GestureScrollUpdate) { | 
|  618     // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a |  619     // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a | 
|  619     // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. |  620     // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. | 
|  620     // So we can track the latency specifically for scroll update events. |  621     // So we can track the latency specifically for scroll update events. | 
|  621     LatencyInfo::LatencyComponent original_component; |  622     LatencyInfo::LatencyComponent original_component; | 
|  622     if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, |  623     if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, | 
|  623                              &original_component)) { |  624                              &original_component)) { | 
|  624       latency->AddLatencyNumberWithTimestamp( |  625       latency->AddLatencyNumberWithTimestamp( | 
|  625           has_seen_first_gesture_scroll_update_ |  626           has_seen_first_gesture_scroll_update_ | 
|  626               ? ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT |  627               ? ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT | 
|  627               : ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, |  628               : ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 
|  628           latency_component_id_, original_component.sequence_number, |  629           latency_component_id_, original_component.sequence_number, | 
|  629           original_component.event_time, original_component.event_count); |  630           original_component.event_time, original_component.event_count); | 
|  630     } |  631     } | 
|  631  |  632  | 
|  632     has_seen_first_gesture_scroll_update_ = true; |  633     has_seen_first_gesture_scroll_update_ = true; | 
|  633   } |  634   } | 
|  634 } |  635 } | 
|  635  |  636  | 
|  636 void RenderWidgetHostLatencyTracker::OnInputEventAck( |  637 void RenderWidgetHostLatencyTracker::OnInputEventAck( | 
|  637     const blink::WebInputEvent& event, |  638     const blink::WebInputEvent& event, | 
|  638     LatencyInfo* latency, InputEventAckState ack_result) { |  639     LatencyInfo* latency, InputEventAckState ack_result) { | 
|  639   DCHECK(latency); |  640   DCHECK(latency); | 
|  640  |  641  | 
|  641   // Latency ends when it is acked but does not cause render scheduling. |  642   // Latency ends when it is acked but does not cause render scheduling. | 
|  642   bool rendering_scheduled = latency->FindLatency( |  643   bool rendering_scheduled = latency->FindLatency( | 
|  643       ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, nullptr); |  644       ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, nullptr); | 
|  644   rendering_scheduled |= latency->FindLatency( |  645   rendering_scheduled |= latency->FindLatency( | 
|  645       ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, nullptr); |  646       ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, nullptr); | 
|  646  |  647  | 
|  647   if (WebInputEvent::isGestureEventType(event.type)) { |  648   if (WebInputEvent::isGestureEventType(event.type())) { | 
|  648     if (!rendering_scheduled) { |  649     if (!rendering_scheduled) { | 
|  649       latency->AddLatencyNumber( |  650       latency->AddLatencyNumber( | 
|  650           ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT, 0, 0); |  651           ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT, 0, 0); | 
|  651       // TODO(jdduke): Consider exposing histograms for gesture event types. |  652       // TODO(jdduke): Consider exposing histograms for gesture event types. | 
|  652     } |  653     } | 
|  653     return; |  654     return; | 
|  654   } |  655   } | 
|  655  |  656  | 
|  656   if (WebInputEvent::isTouchEventType(event.type)) { |  657   if (WebInputEvent::isTouchEventType(event.type())) { | 
|  657     const WebTouchEvent& touch_event = |  658     const WebTouchEvent& touch_event = | 
|  658         *static_cast<const WebTouchEvent*>(&event); |  659         *static_cast<const WebTouchEvent*>(&event); | 
|  659     if (event.type == WebInputEvent::TouchStart) { |  660     if (event.type() == WebInputEvent::TouchStart) { | 
|  660       DCHECK(touch_event.touchesLength >= 1); |  661       DCHECK(touch_event.touchesLength >= 1); | 
|  661       multi_finger_gesture_ = touch_event.touchesLength != 1; |  662       multi_finger_gesture_ = touch_event.touchesLength != 1; | 
|  662       touch_start_default_prevented_ = |  663       touch_start_default_prevented_ = | 
|  663           ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |  664           ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; | 
|  664     } |  665     } | 
|  665  |  666  | 
|  666     latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); |  667     latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); | 
|  667  |  668  | 
|  668     if (!rendering_scheduled) { |  669     if (!rendering_scheduled) { | 
|  669       latency->AddLatencyNumber( |  670       latency->AddLatencyNumber( | 
|  670           ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT, 0, 0); |  671           ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT, 0, 0); | 
|  671     } |  672     } | 
|  672     ComputeInputLatencyHistograms(event.type, latency_component_id_, *latency, |  673     ComputeInputLatencyHistograms(event.type(), latency_component_id_, *latency, | 
|  673                                   ack_result); |  674                                   ack_result); | 
|  674     return; |  675     return; | 
|  675   } |  676   } | 
|  676  |  677  | 
|  677   if (event.type == WebInputEvent::MouseWheel) { |  678   if (event.type() == WebInputEvent::MouseWheel) { | 
|  678     latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); |  679     latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); | 
|  679     if (!rendering_scheduled) { |  680     if (!rendering_scheduled) { | 
|  680       latency->AddLatencyNumber( |  681       latency->AddLatencyNumber( | 
|  681           ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT, 0, 0); |  682           ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT, 0, 0); | 
|  682     } |  683     } | 
|  683     ComputeInputLatencyHistograms(event.type, latency_component_id_, *latency, |  684     ComputeInputLatencyHistograms(event.type(), latency_component_id_, *latency, | 
|  684                                   ack_result); |  685                                   ack_result); | 
|  685     return; |  686     return; | 
|  686   } |  687   } | 
|  687  |  688  | 
|  688   if (WebInputEvent::isMouseEventType(event.type) && !rendering_scheduled) { |  689   if (WebInputEvent::isMouseEventType(event.type()) && !rendering_scheduled) { | 
|  689       latency->AddLatencyNumber( |  690     latency->AddLatencyNumber( | 
|  690           ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT, 0, 0); |  691         ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT, 0, 0); | 
|  691     return; |  692     return; | 
|  692   } |  693   } | 
|  693  |  694  | 
|  694   if (WebInputEvent::isKeyboardEventType(event.type) && !rendering_scheduled) { |  695   if (WebInputEvent::isKeyboardEventType(event.type()) && | 
|  695       latency->AddLatencyNumber( |  696       !rendering_scheduled) { | 
|  696           ui::INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT, 0, 0); |  697     latency->AddLatencyNumber( | 
 |  698         ui::INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT, 0, 0); | 
|  697     return; |  699     return; | 
|  698   } |  700   } | 
|  699 } |  701 } | 
|  700  |  702  | 
|  701 void RenderWidgetHostLatencyTracker::OnSwapCompositorFrame( |  703 void RenderWidgetHostLatencyTracker::OnSwapCompositorFrame( | 
|  702     std::vector<LatencyInfo>* latencies) { |  704     std::vector<LatencyInfo>* latencies) { | 
|  703   DCHECK(latencies); |  705   DCHECK(latencies); | 
|  704   for (LatencyInfo& latency : *latencies) { |  706   for (LatencyInfo& latency : *latencies) { | 
|  705     AddLatencyInfoComponentIds(&latency, latency_component_id_); |  707     AddLatencyInfoComponentIds(&latency, latency_component_id_); | 
|  706     latency.AddLatencyNumber( |  708     latency.AddLatencyNumber( | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  761         latency, is_running_navigation_hint_task); |  763         latency, is_running_navigation_hint_task); | 
|  762   } |  764   } | 
|  763 } |  765 } | 
|  764  |  766  | 
|  765 void RenderWidgetHostLatencyTracker::SetDelegate( |  767 void RenderWidgetHostLatencyTracker::SetDelegate( | 
|  766     RenderWidgetHostDelegate* delegate) { |  768     RenderWidgetHostDelegate* delegate) { | 
|  767   render_widget_host_delegate_ = delegate; |  769   render_widget_host_delegate_ = delegate; | 
|  768 } |  770 } | 
|  769  |  771  | 
|  770 }  // namespace content |  772 }  // namespace content | 
| OLD | NEW |