Commit 128d1c67 authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

latency: Stop using a component-id for BEGIN_RWH component.

The component-id for BEGIN_RWH component is currently generated from the
process-id and routing-id of the associated RenderWidgetHostImpl, so
that it is possible to find the RenderWidgetHostImpl from the
LatencyInfo after gpu-swap happens. However, the BEGIN_RWH component is
unused at that time (only LatencyInfos that have snapshot requests are
processed after gpu-swap, and the snapshot requests already carry the
identifier for the RenderWidgetHostImpl separately), except for in a
test. So, the changes in this CL:
 . Use zero as the component-id for BEGIN_RWH component.
 . Introduce a SetLatencyInfoProcessorForTesting() method to install a
   callback that receives all the LatencyInfo after a gpu-swap happens,
   and use that in the tests that needed this.

BUG=849729

Change-Id: I19beb790931cfe8e708d0eb4223a3ba23d51e4c1
Reviewed-on: https://chromium-review.googlesource.com/1089583Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565488}
parent b587039b
...@@ -83,11 +83,18 @@ class TracingRenderWidgetHost : public RenderWidgetHostImpl { ...@@ -83,11 +83,18 @@ class TracingRenderWidgetHost : public RenderWidgetHostImpl {
process, process,
routing_id, routing_id,
std::move(widget), std::move(widget),
hidden) {} hidden) {
void OnGpuSwapBuffersCompletedInternal( SetLatencyInfoProcessorForTesting(base::BindRepeating(
const ui::LatencyInfo& latency_info) override { &TracingRenderWidgetHost::HandleLatencyInfoAfterGpuSwap,
RenderWidgetHostImpl::OnGpuSwapBuffersCompletedInternal(latency_info); base::Unretained(this)));
RunClosureIfNecessary(latency_info); }
void HandleLatencyInfoAfterGpuSwap(
const std::vector<ui::LatencyInfo>& latency_infos) {
for (const auto& latency_info : latency_infos) {
if (latency_info.terminated())
RunClosureIfNecessary(latency_info);
}
} }
void OnMouseEventAck(const MouseEventWithLatencyInfo& event, void OnMouseEventAck(const MouseEventWithLatencyInfo& event,
......
...@@ -57,7 +57,6 @@ void RenderWidgetHostLatencyTracker::Initialize(int routing_id, ...@@ -57,7 +57,6 @@ void RenderWidgetHostLatencyTracker::Initialize(int routing_id,
void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms( void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms(
WebInputEvent::Type type, WebInputEvent::Type type,
int64_t latency_component_id,
const LatencyInfo& latency, const LatencyInfo& latency,
InputEventAckState ack_result) { InputEventAckState ack_result) {
// If this event was coalesced into another event, ignore it, as the event it // If this event was coalesced into another event, ignore it, as the event it
...@@ -73,9 +72,8 @@ void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms( ...@@ -73,9 +72,8 @@ void RenderWidgetHostLatencyTracker::ComputeInputLatencyHistograms(
// The event will have gone through OnInputEvent(). So the BEGIN_RWH component // The event will have gone through OnInputEvent(). So the BEGIN_RWH component
// should always be available here. // should always be available here.
LatencyInfo::LatencyComponent rwh_component; LatencyInfo::LatencyComponent rwh_component;
bool found_component = bool found_component = latency.FindLatency(
latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, &rwh_component);
latency_component_id, &rwh_component);
DCHECK(found_component); DCHECK(found_component);
DCHECK_EQ(rwh_component.event_count, 1u); DCHECK_EQ(rwh_component.event_count, 1u);
...@@ -150,9 +148,8 @@ void RenderWidgetHostLatencyTracker::OnInputEvent( ...@@ -150,9 +148,8 @@ void RenderWidgetHostLatencyTracker::OnInputEvent(
// This is the only place to add the BEGIN_RWH component. So this component // This is the only place to add the BEGIN_RWH component. So this component
// should not already be present in the latency info. // should not already be present in the latency info.
bool found_component = bool found_component = latency->FindLatency(
latency->FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, nullptr);
latency_component_id_, nullptr);
DCHECK(!found_component); DCHECK(!found_component);
if (!event.TimeStamp().is_null() && if (!event.TimeStamp().is_null() &&
...@@ -176,7 +173,7 @@ void RenderWidgetHostLatencyTracker::OnInputEvent( ...@@ -176,7 +173,7 @@ void RenderWidgetHostLatencyTracker::OnInputEvent(
} }
latency->AddLatencyNumberWithTraceName( latency->AddLatencyNumberWithTraceName(
ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0,
WebInputEvent::GetName(event.GetType())); WebInputEvent::GetName(event.GetType()));
if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) { if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) {
...@@ -234,8 +231,7 @@ void RenderWidgetHostLatencyTracker::OnInputEventAck( ...@@ -234,8 +231,7 @@ void RenderWidgetHostLatencyTracker::OnInputEventAck(
latency->Terminate(); latency->Terminate();
} }
ComputeInputLatencyHistograms(event.GetType(), latency_component_id_, ComputeInputLatencyHistograms(event.GetType(), *latency, ack_result);
*latency, ack_result);
} }
void RenderWidgetHostLatencyTracker::OnEventStart(ui::LatencyInfo* latency) { void RenderWidgetHostLatencyTracker::OnEventStart(ui::LatencyInfo* latency) {
......
...@@ -32,7 +32,6 @@ class CONTENT_EXPORT RenderWidgetHostLatencyTracker { ...@@ -32,7 +32,6 @@ class CONTENT_EXPORT RenderWidgetHostLatencyTracker {
void Initialize(int routing_id, int process_id); void Initialize(int routing_id, int process_id);
void ComputeInputLatencyHistograms(blink::WebInputEvent::Type type, void ComputeInputLatencyHistograms(blink::WebInputEvent::Type type,
int64_t latency_component_id,
const ui::LatencyInfo& latency, const ui::LatencyInfo& latency,
InputEventAckState ack_result); InputEventAckState ack_result);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -184,6 +185,12 @@ class RenderWidgetHostIteratorImpl : public RenderWidgetHostIterator { ...@@ -184,6 +185,12 @@ class RenderWidgetHostIteratorImpl : public RenderWidgetHostIterator {
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostIteratorImpl); DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostIteratorImpl);
}; };
RenderWidgetHostImpl::LatencyInfoProcessor& GetLatencyInfoProcessor() {
static base::NoDestructor<RenderWidgetHostImpl::LatencyInfoProcessor>
processor;
return *processor;
}
inline blink::WebGestureEvent CreateScrollBeginForWrapping( inline blink::WebGestureEvent CreateScrollBeginForWrapping(
const blink::WebGestureEvent& gesture_event) { const blink::WebGestureEvent& gesture_event) {
DCHECK(gesture_event.GetType() == blink::WebInputEvent::kGestureScrollUpdate); DCHECK(gesture_event.GetType() == blink::WebInputEvent::kGestureScrollUpdate);
...@@ -1974,6 +1981,11 @@ bool RenderWidgetHostImpl::IsMouseLocked() const { ...@@ -1974,6 +1981,11 @@ bool RenderWidgetHostImpl::IsMouseLocked() const {
return view_ ? view_->IsMouseLocked() : false; return view_ ? view_->IsMouseLocked() : false;
} }
void RenderWidgetHostImpl::SetLatencyInfoProcessorForTesting(
const LatencyInfoProcessor& processor) {
GetLatencyInfoProcessor() = processor;
}
void RenderWidgetHostImpl::SetAutoResize(bool enable, void RenderWidgetHostImpl::SetAutoResize(bool enable,
const gfx::Size& min_size, const gfx::Size& min_size,
const gfx::Size& max_size) { const gfx::Size& max_size) {
...@@ -2056,7 +2068,7 @@ void RenderWidgetHostImpl::ClearDisplayedGraphics() { ...@@ -2056,7 +2068,7 @@ void RenderWidgetHostImpl::ClearDisplayedGraphics() {
view_->ClearCompositorFrame(); view_->ClearCompositorFrame();
} }
void RenderWidgetHostImpl::OnGpuSwapBuffersCompletedInternal( void RenderWidgetHostImpl::ProcessSnapshotResponses(
const ui::LatencyInfo& latency_info) { const ui::LatencyInfo& latency_info) {
// Note that a compromised renderer can send LatencyInfo to a // Note that a compromised renderer can send LatencyInfo to a
// RenderWidgetHostImpl other than its own. Be mindful of security // RenderWidgetHostImpl other than its own. Be mindful of security
...@@ -2745,20 +2757,17 @@ void RenderWidgetHostImpl::NotifyCorrespondingRenderWidgetHost( ...@@ -2745,20 +2757,17 @@ void RenderWidgetHostImpl::NotifyCorrespondingRenderWidgetHost(
return; return;
RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
if (notified_hosts.insert(rwhi).second) if (notified_hosts.insert(rwhi).second)
rwhi->OnGpuSwapBuffersCompletedInternal(latency_info); rwhi->ProcessSnapshotResponses(latency_info);
} }
// static // static
void RenderWidgetHostImpl::OnGpuSwapBuffersCompleted( void RenderWidgetHostImpl::OnGpuSwapBuffersCompleted(
const std::vector<ui::LatencyInfo>& latency_info) { const std::vector<ui::LatencyInfo>& latency_info) {
auto& callback = GetLatencyInfoProcessor();
if (!callback.is_null())
callback.Run(latency_info);
for (size_t i = 0; i < latency_info.size(); i++) { for (size_t i = 0; i < latency_info.size(); i++) {
std::set<RenderWidgetHostImpl*> rwhi_set; std::set<RenderWidgetHostImpl*> rwhi_set;
for (const auto& lc : latency_info[i].latency_components()) {
if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) {
NotifyCorrespondingRenderWidgetHost(lc.first.second, rwhi_set,
latency_info[i]);
}
}
for (const auto& snapshot : latency_info[i].Snapshots()) for (const auto& snapshot : latency_info[i].Snapshots())
NotifyCorrespondingRenderWidgetHost(snapshot.first, rwhi_set, NotifyCorrespondingRenderWidgetHost(snapshot.first, rwhi_set,
latency_info[i]); latency_info[i]);
......
...@@ -722,6 +722,11 @@ class CONTENT_EXPORT RenderWidgetHostImpl ...@@ -722,6 +722,11 @@ class CONTENT_EXPORT RenderWidgetHostImpl
void GetContentRenderingTimeoutFrom(RenderWidgetHostImpl* other); void GetContentRenderingTimeoutFrom(RenderWidgetHostImpl* other);
using LatencyInfoProcessor =
base::RepeatingCallback<void(const std::vector<ui::LatencyInfo>&)>;
static void SetLatencyInfoProcessorForTesting(
const LatencyInfoProcessor& processor);
protected: protected:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// The following method is overridden by RenderViewHost to send upwards to // The following method is overridden by RenderViewHost to send upwards to
...@@ -731,9 +736,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl ...@@ -731,9 +736,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl
// from a newly loaded page. Used for testing. // from a newly loaded page. Used for testing.
virtual void NotifyNewContentRenderingTimeoutForTesting() {} virtual void NotifyNewContentRenderingTimeoutForTesting() {}
// Can be overriden for subclass based testing. void ProcessSnapshotResponses(const ui::LatencyInfo& latency_info);
virtual void OnGpuSwapBuffersCompletedInternal(
const ui::LatencyInfo& latency_info);
// InputAckHandler // InputAckHandler
void OnKeyboardEventAck(const NativeWebKeyboardEventWithLatencyInfo& event, void OnKeyboardEventAck(const NativeWebKeyboardEventWithLatencyInfo& event,
......
...@@ -2054,7 +2054,7 @@ void CheckLatencyInfoComponentInMessage( ...@@ -2054,7 +2054,7 @@ void CheckLatencyInfoComponentInMessage(
expected_type); expected_type);
EXPECT_TRUE( EXPECT_TRUE(
dispatched_events[0]->ToEvent()->Event()->latency_info.FindLatency( dispatched_events[0]->ToEvent()->Event()->latency_info.FindLatency(
ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, nullptr)); ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, nullptr));
dispatched_events[0]->ToEvent()->CallCallback(INPUT_EVENT_ACK_STATE_CONSUMED); dispatched_events[0]->ToEvent()->CallCallback(INPUT_EVENT_ACK_STATE_CONSUMED);
} }
...@@ -2071,7 +2071,7 @@ void CheckLatencyInfoComponentInGestureScrollUpdate( ...@@ -2071,7 +2071,7 @@ void CheckLatencyInfoComponentInGestureScrollUpdate(
dispatched_events[1]->ToEvent()->Event()->web_event->GetType()); dispatched_events[1]->ToEvent()->Event()->web_event->GetType());
EXPECT_TRUE( EXPECT_TRUE(
dispatched_events[1]->ToEvent()->Event()->latency_info.FindLatency( dispatched_events[1]->ToEvent()->Event()->latency_info.FindLatency(
ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, component_id, nullptr)); ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, nullptr));
dispatched_events[1]->ToEvent()->CallCallback(INPUT_EVENT_ACK_STATE_CONSUMED); dispatched_events[1]->ToEvent()->CallCallback(INPUT_EVENT_ACK_STATE_CONSUMED);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment