| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Remove the entries with invalid component IDs. | 63 // Remove the entries with invalid component IDs. |
| 64 latency->RemoveLatency(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT); | 64 latency->RemoveLatency(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT); |
| 65 | 65 |
| 66 // Add newly generated components into the latency info | 66 // Add newly generated components into the latency info |
| 67 for (size_t i = 0; i < new_components_key.size(); i++) { | 67 for (size_t i = 0; i < new_components_key.size(); i++) { |
| 68 latency->AddLatencyNumberWithTimestamp( | 68 latency->AddLatencyNumberWithTimestamp( |
| 69 new_components_key[i].first, | 69 new_components_key[i].first, |
| 70 new_components_key[i].second, | 70 new_components_key[i].second, |
| 71 new_components_value[i].sequence_number, | |
| 72 new_components_value[i].event_time, | 71 new_components_value[i].event_time, |
| 73 new_components_value[i].event_count); | 72 new_components_value[i].event_count); |
| 74 } | 73 } |
| 75 } | 74 } |
| 76 | 75 |
| 77 } // namespace | 76 } // namespace |
| 78 | 77 |
| 79 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 78 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() |
| 80 : ukm_source_id_(-1), | 79 : ukm_source_id_(-1), |
| 81 last_event_id_(0), | |
| 82 latency_component_id_(0), | 80 latency_component_id_(0), |
| 83 device_scale_factor_(1), | 81 device_scale_factor_(1), |
| 84 has_seen_first_gesture_scroll_update_(false), | 82 has_seen_first_gesture_scroll_update_(false), |
| 85 active_multi_finger_gesture_(false), | 83 active_multi_finger_gesture_(false), |
| 86 touch_start_default_prevented_(false), | 84 touch_start_default_prevented_(false), |
| 87 render_widget_host_delegate_(nullptr) {} | 85 render_widget_host_delegate_(nullptr) {} |
| 88 | 86 |
| 89 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} | 87 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} |
| 90 | 88 |
| 91 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 89 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
| 92 int process_id) { | 90 int process_id) { |
| 93 DCHECK_EQ(0, last_event_id_); | |
| 94 DCHECK_EQ(0, latency_component_id_); | 91 DCHECK_EQ(0, latency_component_id_); |
| 95 last_event_id_ = static_cast<int64_t>(process_id) << 32; | 92 latency_component_id_ = routing_id | static_cast<int64_t>(process_id) << 32; |
| 96 latency_component_id_ = routing_id | last_event_id_; | |
| 97 } | 93 } |
| 98 | 94 |
| 99 void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms( | 95 void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms( |
| 100 WebInputEvent::Type type, | 96 WebInputEvent::Type type, |
| 101 int64_t latency_component_id, | 97 int64_t latency_component_id, |
| 102 const LatencyInfo& latency, | 98 const LatencyInfo& latency, |
| 103 InputEventAckState ack_result) { | 99 InputEventAckState ack_result) { |
| 104 // If this event was coalesced into another event, ignore it, as the event it | 100 // If this event was coalesced into another event, ignore it, as the event it |
| 105 // was coalesced into will reflect the full latency. | 101 // was coalesced into will reflect the full latency. |
| 106 if (latency.coalesced()) | 102 if (latency.coalesced()) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // Timestamp from platform input can wrap, e.g. 32 bits timestamp | 218 // Timestamp from platform input can wrap, e.g. 32 bits timestamp |
| 223 // for Xserver and Window MSG time will wrap about 49.6 days. Do a | 219 // for Xserver and Window MSG time will wrap about 49.6 days. Do a |
| 224 // sanity check here and if wrap does happen, use TimeTicks::Now() | 220 // sanity check here and if wrap does happen, use TimeTicks::Now() |
| 225 // as the timestamp instead. | 221 // as the timestamp instead. |
| 226 if ((timestamp_now - timestamp_original).InDays() > 0) | 222 if ((timestamp_now - timestamp_original).InDays() > 0) |
| 227 timestamp_original = timestamp_now; | 223 timestamp_original = timestamp_now; |
| 228 | 224 |
| 229 latency->AddLatencyNumberWithTimestamp( | 225 latency->AddLatencyNumberWithTimestamp( |
| 230 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 226 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 231 0, | 227 0, |
| 232 0, | |
| 233 timestamp_original, | 228 timestamp_original, |
| 234 1); | 229 1); |
| 235 } | 230 } |
| 236 | 231 |
| 237 latency->AddLatencyNumberWithTraceName( | 232 latency->AddLatencyNumberWithTraceName( |
| 238 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, | 233 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, |
| 239 ++last_event_id_, WebInputEvent::GetName(event.GetType())); | 234 WebInputEvent::GetName(event.GetType())); |
| 240 | 235 |
| 241 if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) { | 236 if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) { |
| 242 has_seen_first_gesture_scroll_update_ = false; | 237 has_seen_first_gesture_scroll_update_ = false; |
| 243 } else if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate) { | 238 } else if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate) { |
| 244 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a | 239 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a |
| 245 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. | 240 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. |
| 246 // So we can track the latency specifically for scroll update events. | 241 // So we can track the latency specifically for scroll update events. |
| 247 LatencyInfo::LatencyComponent original_component; | 242 LatencyInfo::LatencyComponent original_component; |
| 248 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, | 243 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, |
| 249 &original_component)) { | 244 &original_component)) { |
| 250 latency->AddLatencyNumberWithTimestamp( | 245 latency->AddLatencyNumberWithTimestamp( |
| 251 has_seen_first_gesture_scroll_update_ | 246 has_seen_first_gesture_scroll_update_ |
| 252 ? ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT | 247 ? ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT |
| 253 : ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 248 : ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 254 latency_component_id_, original_component.sequence_number, | 249 latency_component_id_, original_component.event_time, |
| 255 original_component.event_time, original_component.event_count); | 250 original_component.event_count); |
| 256 } | 251 } |
| 257 | 252 |
| 258 has_seen_first_gesture_scroll_update_ = true; | 253 has_seen_first_gesture_scroll_update_ = true; |
| 259 } | 254 } |
| 260 } | 255 } |
| 261 | 256 |
| 262 void RenderWidgetHostLatencyTracker::OnInputEventAck( | 257 void RenderWidgetHostLatencyTracker::OnInputEventAck( |
| 263 const blink::WebInputEvent& event, | 258 const blink::WebInputEvent& event, |
| 264 LatencyInfo* latency, InputEventAckState ack_result) { | 259 LatencyInfo* latency, InputEventAckState ack_result) { |
| 265 DCHECK(latency); | 260 DCHECK(latency); |
| 266 | 261 |
| 267 // Latency ends if an event is acked but does not cause render scheduling. | 262 // Latency ends if an event is acked but does not cause render scheduling. |
| 268 bool rendering_scheduled = latency->FindLatency( | 263 bool rendering_scheduled = latency->FindLatency( |
| 269 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, nullptr); | 264 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, nullptr); |
| 270 rendering_scheduled |= latency->FindLatency( | 265 rendering_scheduled |= latency->FindLatency( |
| 271 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, nullptr); | 266 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, nullptr); |
| 272 | 267 |
| 273 if (WebInputEvent::IsTouchEventType(event.GetType())) { | 268 if (WebInputEvent::IsTouchEventType(event.GetType())) { |
| 274 const WebTouchEvent& touch_event = | 269 const WebTouchEvent& touch_event = |
| 275 *static_cast<const WebTouchEvent*>(&event); | 270 *static_cast<const WebTouchEvent*>(&event); |
| 276 if (event.GetType() == WebInputEvent::kTouchStart) { | 271 if (event.GetType() == WebInputEvent::kTouchStart) { |
| 277 touch_start_default_prevented_ = | 272 touch_start_default_prevented_ = |
| 278 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; | 273 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |
| 279 } else if (event.GetType() == WebInputEvent::kTouchEnd || | 274 } else if (event.GetType() == WebInputEvent::kTouchEnd || |
| 280 event.GetType() == WebInputEvent::kTouchCancel) { | 275 event.GetType() == WebInputEvent::kTouchCancel) { |
| 281 active_multi_finger_gesture_ = touch_event.touches_length > 2; | 276 active_multi_finger_gesture_ = touch_event.touches_length > 2; |
| 282 } | 277 } |
| 283 } | 278 } |
| 284 | 279 |
| 285 latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); | 280 latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0); |
| 286 // If this event couldn't have caused a gesture event, and it didn't trigger | 281 // If this event couldn't have caused a gesture event, and it didn't trigger |
| 287 // rendering, we're done processing it. | 282 // rendering, we're done processing it. |
| 288 if (!rendering_scheduled) { | 283 if (!rendering_scheduled) { |
| 289 latency->AddLatencyNumber( | 284 latency->AddLatencyNumber( |
| 290 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, 0); | 285 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0); |
| 291 } | 286 } |
| 292 | 287 |
| 293 ComputeInputLatencyHistograms(event.GetType(), latency_component_id_, | 288 ComputeInputLatencyHistograms(event.GetType(), latency_component_id_, |
| 294 *latency, ack_result); | 289 *latency, ack_result); |
| 295 } | 290 } |
| 296 | 291 |
| 297 void RenderWidgetHostLatencyTracker::OnSwapCompositorFrame( | 292 void RenderWidgetHostLatencyTracker::OnSwapCompositorFrame( |
| 298 std::vector<LatencyInfo>* latencies) { | 293 std::vector<LatencyInfo>* latencies) { |
| 299 DCHECK(latencies); | 294 DCHECK(latencies); |
| 300 for (LatencyInfo& latency : *latencies) { | 295 for (LatencyInfo& latency : *latencies) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 if (ukm_source_id == -1 || !ukm_recorder) | 345 if (ukm_source_id == -1 || !ukm_recorder) |
| 351 return; | 346 return; |
| 352 | 347 |
| 353 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 348 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
| 354 ukm_recorder->GetEntryBuilder(ukm_source_id, event_name.c_str()); | 349 ukm_recorder->GetEntryBuilder(ukm_source_id, event_name.c_str()); |
| 355 builder->AddMetric(metric_name.c_str(), (end_component.last_event_time - | 350 builder->AddMetric(metric_name.c_str(), (end_component.last_event_time - |
| 356 start_component.first_event_time) | 351 start_component.first_event_time) |
| 357 .InMicroseconds()); | 352 .InMicroseconds()); |
| 358 } | 353 } |
| 359 } // namespace content | 354 } // namespace content |
| OLD | NEW |