Commit 28074dba authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

[AW] Added latency tracking.

Using a ui::LatencyTracker to record all collected latency info
after drawing buffers have been swapped. This records a system health
metric (Event.Latency.ScrollBegin.Wheel.TimeToScrollUpdateSwapBegin4)
as well as the recording of latency info for debugging.

Bug: 992026
Change-Id: I904cbec84418426f06c9b237c2ead86566570302
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929264Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Chris Mumford <cmumford@google.com>
Cr-Commit-Position: refs/heads/master@{#718330}
parent 12ba82c6
...@@ -7,5 +7,6 @@ include_rules = [ ...@@ -7,5 +7,6 @@ include_rules = [
"+android_webview/common/aw_switches.h", "+android_webview/common/aw_switches.h",
"+android_webview/public/browser", "+android_webview/public/browser",
"+components/viz/service/main", "+components/viz/service/main",
"+ui/latency",
] ]
...@@ -14,6 +14,21 @@ ...@@ -14,6 +14,21 @@
namespace android_webview { namespace android_webview {
namespace {
void AddLatencyInfoSwapTimes(std::vector<ui::LatencyInfo>* latency_info,
base::TimeTicks swap_start,
base::TimeTicks swap_end) {
for (auto& latency : *latency_info) {
latency.AddLatencyNumberWithTimestamp(
ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, swap_start);
latency.AddLatencyNumberWithTimestamp(
ui::INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT, swap_end);
}
}
} // namespace
ParentOutputSurface::ParentOutputSurface( ParentOutputSurface::ParentOutputSurface(
scoped_refptr<AwGLSurface> gl_surface, scoped_refptr<AwGLSurface> gl_surface,
scoped_refptr<AwRenderThreadContextProvider> context_provider) scoped_refptr<AwRenderThreadContextProvider> context_provider)
...@@ -49,13 +64,20 @@ void ParentOutputSurface::Reshape(const gfx::Size& size, ...@@ -49,13 +64,20 @@ void ParentOutputSurface::Reshape(const gfx::Size& size,
void ParentOutputSurface::SwapBuffers(viz::OutputSurfaceFrame frame) { void ParentOutputSurface::SwapBuffers(viz::OutputSurfaceFrame frame) {
context_provider_->ContextGL()->ShallowFlushCHROMIUM(); context_provider_->ContextGL()->ShallowFlushCHROMIUM();
gl_surface_->SwapBuffers(base::BindOnce(&ParentOutputSurface::OnPresentation, gl_surface_->SwapBuffers(base::BindOnce(
weak_ptr_factory_.GetWeakPtr())); &ParentOutputSurface::OnPresentation, weak_ptr_factory_.GetWeakPtr(),
/*swap_start=*/base::TimeTicks::Now(), std::move(frame.latency_info)));
} }
void ParentOutputSurface::OnPresentation( void ParentOutputSurface::OnPresentation(
base::TimeTicks swap_start,
std::vector<ui::LatencyInfo> latency_info,
const gfx::PresentationFeedback& feedback) { const gfx::PresentationFeedback& feedback) {
DCHECK(client_); DCHECK(client_);
// The start/end swap times are only best-effort. It is not possible to get
// the real swap times for WebView.
AddLatencyInfoSwapTimes(&latency_info, swap_start, base::TimeTicks::Now());
latency_tracker_.OnGpuSwapBuffersCompleted(latency_info);
client_->DidReceivePresentationFeedback(feedback); client_->DidReceivePresentationFeedback(feedback);
} }
......
...@@ -5,11 +5,15 @@ ...@@ -5,11 +5,15 @@
#ifndef ANDROID_WEBVIEW_BROWSER_GFX_PARENT_OUTPUT_SURFACE_H_ #ifndef ANDROID_WEBVIEW_BROWSER_GFX_PARENT_OUTPUT_SURFACE_H_
#define ANDROID_WEBVIEW_BROWSER_GFX_PARENT_OUTPUT_SURFACE_H_ #define ANDROID_WEBVIEW_BROWSER_GFX_PARENT_OUTPUT_SURFACE_H_
#include <vector>
#include "android_webview/browser/gfx/aw_gl_surface.h" #include "android_webview/browser/gfx/aw_gl_surface.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/viz/service/display/output_surface.h" #include "components/viz/service/display/output_surface.h"
#include "ui/latency/latency_info.h"
#include "ui/latency/latency_tracker.h"
namespace gfx { namespace gfx {
struct PresentationFeedback; struct PresentationFeedback;
...@@ -50,12 +54,15 @@ class ParentOutputSurface : public viz::OutputSurface { ...@@ -50,12 +54,15 @@ class ParentOutputSurface : public viz::OutputSurface {
gfx::OverlayTransform GetDisplayTransform() override; gfx::OverlayTransform GetDisplayTransform() override;
private: private:
void OnPresentation(const gfx::PresentationFeedback& feedback); void OnPresentation(base::TimeTicks swap_start,
std::vector<ui::LatencyInfo> latency_info,
const gfx::PresentationFeedback& feedback);
viz::OutputSurfaceClient* client_ = nullptr; viz::OutputSurfaceClient* client_ = nullptr;
// This is really a layering violation but needed for hooking up presentation // This is really a layering violation but needed for hooking up presentation
// feedbacks properly. // feedbacks properly.
scoped_refptr<AwGLSurface> gl_surface_; scoped_refptr<AwGLSurface> gl_surface_;
ui::LatencyTracker latency_tracker_;
base::WeakPtrFactory<ParentOutputSurface> weak_ptr_factory_{this}; base::WeakPtrFactory<ParentOutputSurface> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ParentOutputSurface); DISALLOW_COPY_AND_ASSIGN(ParentOutputSurface);
}; };
......
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