Commit 4aab8648 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

ash: Use ThroughputTracker for homescreen smoothness

Bug: 1021774
Change-Id: I1fa60f4f920e2cade3b2fd9249f85cf049c8564b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2268085Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782651}
parent d2261f38
......@@ -12,7 +12,7 @@
#include "ash/home_screen/home_screen_delegate.h"
#include "ash/home_screen/window_scale_animation.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/fps_counter.h"
#include "ash/public/cpp/metrics_util.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/scoped_animation_disabler.h"
......@@ -28,11 +28,13 @@
#include "ash/wm/window_transient_descendant_iterator.h"
#include "ash/wm/window_util.h"
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/check.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/throughput_tracker.h"
#include "ui/display/manager/display_manager.h"
#include "ui/wm/core/window_animations.h"
......@@ -302,16 +304,18 @@ void HomeScreenController::StartTrackingAnimationSmoothness(
int64_t display_id) {
auto* root_window = Shell::GetRootWindowForDisplayId(display_id);
auto* compositor = root_window->layer()->GetCompositor();
fps_counter_ = std::make_unique<FpsCounter>(compositor);
smoothness_tracker_ = compositor->RequestNewThroughputTracker();
smoothness_tracker_->Start(
metrics_util::ForSmoothness(base::BindRepeating([](int smoothness) {
UMA_HISTOGRAM_PERCENTAGE(kHomescreenAnimationHistogram, smoothness);
})));
}
void HomeScreenController::RecordAnimationSmoothness() {
if (!fps_counter_)
if (!smoothness_tracker_)
return;
int smoothness = fps_counter_->ComputeSmoothness();
if (smoothness >= 0)
UMA_HISTOGRAM_PERCENTAGE(kHomescreenAnimationHistogram, smoothness);
fps_counter_.reset();
smoothness_tracker_->Stop();
smoothness_tracker_.reset();
}
void HomeScreenController::OnAppListViewShown() {
......
......@@ -19,9 +19,12 @@
#include "base/optional.h"
#include "base/scoped_observer.h"
namespace ui {
class ThroughputTracker;
}
namespace ash {
class FpsCounter;
class HomeLauncherGestureHandler;
class HomeScreenDelegate;
......@@ -56,7 +59,7 @@ class ASH_EXPORT HomeScreenController : public OverviewObserver,
// True if home screen is visible.
bool IsHomeScreenVisible() const;
// Responsible to starting or stopping |fps_counter_|.
// Responsible to starting or stopping |smoothness_tracker_|.
void StartTrackingAnimationSmoothness(int64_t display_id);
void RecordAnimationSmoothness();
......@@ -134,7 +137,7 @@ class ASH_EXPORT HomeScreenController : public OverviewObserver,
// Responsible for recording smoothness related UMA stats for homescreen
// animations.
std::unique_ptr<FpsCounter> fps_counter_;
base::Optional<ui::ThroughputTracker> smoothness_tracker_;
ScopedObserver<SplitViewController, SplitViewObserver> split_view_observer_{
this};
......
......@@ -152,6 +152,13 @@ TEST_P(HomeScreenControllerTest, DraggingHistograms) {
// should have a animation smoothness histogram recorded.
if (drag_enabled) {
ShellTestApi().WaitForWindowFinishAnimating(window.get());
// Wait for one more frame presented for the metrics to get recorded.
// ignore_result() and timeout is because the frame could already be
// presented.
ignore_result(ui::WaitForNextFrameToBePresented(
compositor, base::TimeDelta::FromMilliseconds(500)));
tester.ExpectTotalCount(kHomescreenAnimationHistogram, 1);
}
}
......
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