| 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 } // namespace | 333 } // namespace |
| 334 | 334 |
| 335 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 335 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() |
| 336 : last_event_id_(0), | 336 : last_event_id_(0), |
| 337 latency_component_id_(0), | 337 latency_component_id_(0), |
| 338 device_scale_factor_(1), | 338 device_scale_factor_(1), |
| 339 has_seen_first_gesture_scroll_update_(false), | 339 has_seen_first_gesture_scroll_update_(false), |
| 340 multi_finger_gesture_(false), | 340 active_multi_finger_gesture_(false), |
| 341 touch_start_default_prevented_(false), | 341 touch_start_default_prevented_(false), |
| 342 render_widget_host_delegate_(nullptr) {} | 342 render_widget_host_delegate_(nullptr) {} |
| 343 | 343 |
| 344 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} | 344 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} |
| 345 | 345 |
| 346 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 346 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
| 347 int process_id) { | 347 int process_id) { |
| 348 DCHECK_EQ(0, last_event_id_); | 348 DCHECK_EQ(0, last_event_id_); |
| 349 DCHECK_EQ(0, latency_component_id_); | 349 DCHECK_EQ(0, latency_component_id_); |
| 350 last_event_id_ = static_cast<int64_t>(process_id) << 32; | 350 last_event_id_ = static_cast<int64_t>(process_id) << 32; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 | 368 |
| 369 LatencyInfo::LatencyComponent rwh_component; | 369 LatencyInfo::LatencyComponent rwh_component; |
| 370 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 370 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 371 latency_component_id, &rwh_component)) { | 371 latency_component_id, &rwh_component)) { |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 DCHECK_EQ(rwh_component.event_count, 1u); | 374 DCHECK_EQ(rwh_component.event_count, 1u); |
| 375 | 375 |
| 376 bool multi_finger_touch_gesture = |
| 377 WebInputEvent::isTouchEventType(type) && active_multi_finger_gesture_; |
| 378 |
| 376 LatencyInfo::LatencyComponent ui_component; | 379 LatencyInfo::LatencyComponent ui_component; |
| 377 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, | 380 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, |
| 378 &ui_component)) { | 381 &ui_component)) { |
| 379 DCHECK_EQ(ui_component.event_count, 1u); | 382 DCHECK_EQ(ui_component.event_count, 1u); |
| 380 base::TimeDelta ui_delta = | 383 base::TimeDelta ui_delta = |
| 381 rwh_component.last_event_time - ui_component.first_event_time; | 384 rwh_component.last_event_time - ui_component.first_event_time; |
| 382 | 385 |
| 383 if (type == blink::WebInputEvent::MouseWheel) { | 386 if (type == blink::WebInputEvent::MouseWheel) { |
| 384 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.WheelUI", | 387 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser.WheelUI", |
| 385 ui_delta.InMicroseconds(), 1, 20000, 100); | 388 ui_delta.InMicroseconds(), 1, 20000, 100); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 398 | 401 |
| 399 std::string event_name = WebInputEvent::GetName(type); | 402 std::string event_name = WebInputEvent::GetName(type); |
| 400 | 403 |
| 401 std::string default_action_status = | 404 std::string default_action_status = |
| 402 action_prevented ? "DefaultPrevented" : "DefaultAllowed"; | 405 action_prevented ? "DefaultPrevented" : "DefaultAllowed"; |
| 403 | 406 |
| 404 LatencyInfo::LatencyComponent main_component; | 407 LatencyInfo::LatencyComponent main_component; |
| 405 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, | 408 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, |
| 406 &main_component)) { | 409 &main_component)) { |
| 407 DCHECK_EQ(main_component.event_count, 1u); | 410 DCHECK_EQ(main_component.event_count, 1u); |
| 408 if (!multi_finger_gesture_) { | 411 if (!multi_finger_touch_gesture) { |
| 409 UMA_HISTOGRAM_INPUT_LATENCY_MILLISECONDS( | 412 UMA_HISTOGRAM_INPUT_LATENCY_MILLISECONDS( |
| 410 "Event.Latency.QueueingTime." + event_name + default_action_status, | 413 "Event.Latency.QueueingTime." + event_name + default_action_status, |
| 411 rwh_component, main_component); | 414 rwh_component, main_component); |
| 412 } | 415 } |
| 413 } | 416 } |
| 414 | 417 |
| 415 LatencyInfo::LatencyComponent acked_component; | 418 LatencyInfo::LatencyComponent acked_component; |
| 416 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, | 419 if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, |
| 417 &acked_component)) { | 420 &acked_component)) { |
| 418 DCHECK_EQ(acked_component.event_count, 1u); | 421 DCHECK_EQ(acked_component.event_count, 1u); |
| 419 if (!multi_finger_gesture_ && | 422 if (!multi_finger_touch_gesture && |
| 420 main_component.event_time != base::TimeTicks()) { | 423 main_component.event_time != base::TimeTicks()) { |
| 421 UMA_HISTOGRAM_INPUT_LATENCY_MILLISECONDS( | 424 UMA_HISTOGRAM_INPUT_LATENCY_MILLISECONDS( |
| 422 "Event.Latency.BlockingTime." + event_name + default_action_status, | 425 "Event.Latency.BlockingTime." + event_name + default_action_status, |
| 423 main_component, acked_component); | 426 main_component, acked_component); |
| 424 } | 427 } |
| 425 | 428 |
| 426 std::string input_modality = WebInputEventTypeToInputModalityString(type); | 429 std::string input_modality = WebInputEventTypeToInputModalityString(type); |
| 427 if (input_modality != "") { | 430 if (input_modality != "") { |
| 428 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS( | 431 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS( |
| 429 "Event.Latency.Browser." + input_modality + "Acked", rwh_component, | 432 "Event.Latency.Browser." + input_modality + "Acked", rwh_component, |
| 430 acked_component); | 433 acked_component); |
| 431 } | 434 } |
| 432 } | 435 } |
| 433 } | 436 } |
| 434 | 437 |
| 435 void RenderWidgetHostLatencyTracker::OnInputEvent( | 438 void RenderWidgetHostLatencyTracker::OnInputEvent( |
| 436 const blink::WebInputEvent& event, | 439 const blink::WebInputEvent& event, |
| 437 LatencyInfo* latency) { | 440 LatencyInfo* latency) { |
| 438 DCHECK(latency); | 441 DCHECK(latency); |
| 442 |
| 443 if (event.type() == WebInputEvent::TouchStart) { |
| 444 const WebTouchEvent& touch_event = |
| 445 *static_cast<const WebTouchEvent*>(&event); |
| 446 DCHECK(touch_event.touchesLength >= 1); |
| 447 active_multi_finger_gesture_ = touch_event.touchesLength != 1; |
| 448 } |
| 449 |
| 439 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 450 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 440 latency_component_id_, NULL)) { | 451 latency_component_id_, NULL)) { |
| 441 return; | 452 return; |
| 442 } | 453 } |
| 443 | 454 |
| 444 if (event.timeStampSeconds() && | 455 if (event.timeStampSeconds() && |
| 445 !latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, | 456 !latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, |
| 446 NULL)) { | 457 NULL)) { |
| 447 base::TimeTicks timestamp_now = base::TimeTicks::Now(); | 458 base::TimeTicks timestamp_now = base::TimeTicks::Now(); |
| 448 base::TimeTicks timestamp_original = | 459 base::TimeTicks timestamp_original = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 // Latency ends if an event is acked but does not cause render scheduling. | 510 // Latency ends if an event is acked but does not cause render scheduling. |
| 500 bool rendering_scheduled = latency->FindLatency( | 511 bool rendering_scheduled = latency->FindLatency( |
| 501 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, nullptr); | 512 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0, nullptr); |
| 502 rendering_scheduled |= latency->FindLatency( | 513 rendering_scheduled |= latency->FindLatency( |
| 503 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, nullptr); | 514 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, nullptr); |
| 504 | 515 |
| 505 if (WebInputEvent::isTouchEventType(event.type())) { | 516 if (WebInputEvent::isTouchEventType(event.type())) { |
| 506 const WebTouchEvent& touch_event = | 517 const WebTouchEvent& touch_event = |
| 507 *static_cast<const WebTouchEvent*>(&event); | 518 *static_cast<const WebTouchEvent*>(&event); |
| 508 if (event.type() == WebInputEvent::TouchStart) { | 519 if (event.type() == WebInputEvent::TouchStart) { |
| 509 DCHECK(touch_event.touchesLength >= 1); | |
| 510 multi_finger_gesture_ = touch_event.touchesLength != 1; | |
| 511 touch_start_default_prevented_ = | 520 touch_start_default_prevented_ = |
| 512 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; | 521 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |
| 522 } else if (event.type() == WebInputEvent::TouchEnd || |
| 523 event.type() == WebInputEvent::TouchCancel) { |
| 524 active_multi_finger_gesture_ = touch_event.touchesLength > 2; |
| 513 } | 525 } |
| 514 } | 526 } |
| 515 | 527 |
| 516 latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); | 528 latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0); |
| 517 // If this event couldn't have caused a gesture event, and it didn't trigger | 529 // If this event couldn't have caused a gesture event, and it didn't trigger |
| 518 // rendering, we're done processing it. | 530 // rendering, we're done processing it. |
| 519 if (!rendering_scheduled) { | 531 if (!rendering_scheduled) { |
| 520 latency->AddLatencyNumber( | 532 latency->AddLatencyNumber( |
| 521 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, 0); | 533 ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT, 0, 0); |
| 522 } | 534 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 latency_component_id_, latency); | 597 latency_component_id_, latency); |
| 586 } | 598 } |
| 587 } | 599 } |
| 588 | 600 |
| 589 void RenderWidgetHostLatencyTracker::SetDelegate( | 601 void RenderWidgetHostLatencyTracker::SetDelegate( |
| 590 RenderWidgetHostDelegate* delegate) { | 602 RenderWidgetHostDelegate* delegate) { |
| 591 render_widget_host_delegate_ = delegate; | 603 render_widget_host_delegate_ = delegate; |
| 592 } | 604 } |
| 593 | 605 |
| 594 } // namespace content | 606 } // namespace content |
| OLD | NEW |