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