Commit b02925e4 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

ash: Use ThroughputTracker for overview metrics

Replace FpsCounter with ThroughputTracker for overview metrics.

Bug: 1021774
Change-Id: I4ae1dcf01ba092d55a46aa2d4d9f6c7ce3a9534f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264939
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782869}
parent a3f2f247
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "ash/metrics/histogram_macros.h" #include "ash/metrics/histogram_macros.h"
#include "ash/public/cpp/ash_features.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/presentation_time_recorder.h" #include "ash/public/cpp/presentation_time_recorder.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
...@@ -49,11 +49,13 @@ ...@@ -49,11 +49,13 @@
#include "ash/wm/workspace/backdrop_controller.h" #include "ash/wm/workspace/backdrop_controller.h"
#include "ash/wm/workspace/workspace_layout_manager.h" #include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace_controller.h" #include "ash/wm/workspace_controller.h"
#include "base/bind.h"
#include "base/containers/unique_ptr_adapters.h" #include "base/containers/unique_ptr_adapters.h"
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/throughput_tracker.h"
#include "ui/gfx/geometry/safe_integer_conversions.h" #include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/transform_util.h" #include "ui/gfx/transform_util.h"
...@@ -123,74 +125,75 @@ template <const char* clamshell_single_name, ...@@ -123,74 +125,75 @@ template <const char* clamshell_single_name,
const char* tablet_name, const char* tablet_name,
const char* splitview_name, const char* splitview_name,
const char* tablet_minimized_name> const char* tablet_minimized_name>
class OverviewFpsCounter : public FpsCounter { class OverviewMetricsTracker : public OverviewGrid::MetricsTracker {
public: public:
OverviewFpsCounter(ui::Compositor* compositor, OverviewMetricsTracker(ui::Compositor* compositor,
bool in_split_view, bool in_split_view,
bool single_animation_in_clamshell, bool single_animation_in_clamshell,
bool minimized_in_tablet) bool minimized_in_tablet)
: FpsCounter(compositor), : tracker_(compositor->RequestNewThroughputTracker()) {
in_split_view_(in_split_view), tracker_.Start(metrics_util::ForSmoothness(base::BindRepeating(
single_animation_in_clamshell_(single_animation_in_clamshell), &OverviewMetricsTracker::ReportOverviewSmoothness, in_split_view,
minimized_in_tablet_(minimized_in_tablet) {} single_animation_in_clamshell, minimized_in_tablet)));
~OverviewFpsCounter() override { }
int smoothness = ComputeSmoothness(); OverviewMetricsTracker(const OverviewMetricsTracker&) = delete;
if (smoothness < 0) OverviewMetricsTracker& operator=(const OverviewMetricsTracker&) = delete;
return; ~OverviewMetricsTracker() override { tracker_.Stop(); }
if (single_animation_in_clamshell_)
static void ReportOverviewSmoothness(bool in_split_view,
bool single_animation_in_clamshell,
bool minimized_in_tablet,
int smoothness) {
if (single_animation_in_clamshell)
UMA_HISTOGRAM_PERCENTAGE_IN_CLAMSHELL(clamshell_single_name, smoothness); UMA_HISTOGRAM_PERCENTAGE_IN_CLAMSHELL(clamshell_single_name, smoothness);
else else
UMA_HISTOGRAM_PERCENTAGE_IN_CLAMSHELL(clamshell_multi_name, smoothness); UMA_HISTOGRAM_PERCENTAGE_IN_CLAMSHELL(clamshell_multi_name, smoothness);
if (minimized_in_tablet_) { if (minimized_in_tablet) {
UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW( UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW(
in_split_view_, tablet_minimized_name, smoothness); in_split_view, tablet_minimized_name, smoothness);
} else { } else {
UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW(in_split_view_, UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW(in_split_view,
tablet_name, smoothness); tablet_name, smoothness);
} }
UMA_HISTOGRAM_PERCENTAGE_IN_SPLITVIEW(in_split_view_, splitview_name, UMA_HISTOGRAM_PERCENTAGE_IN_SPLITVIEW(in_split_view, splitview_name,
smoothness); smoothness);
} }
private: private:
bool in_split_view_; ui::ThroughputTracker tracker_;
// True if only top window animates upon enter/exit overview in clamshell.
bool single_animation_in_clamshell_;
// True if all windows are minimized in tablet.
bool minimized_in_tablet_;
DISALLOW_COPY_AND_ASSIGN(OverviewFpsCounter);
}; };
using OverviewEnterFpsCounter = using OverviewEnterMetricsTracker =
OverviewFpsCounter<kOverviewEnterSingleClamshellHistogram, OverviewMetricsTracker<kOverviewEnterSingleClamshellHistogram,
kOverviewEnterClamshellHistogram, kOverviewEnterClamshellHistogram,
kOverviewEnterTabletHistogram, kOverviewEnterTabletHistogram,
kOverviewEnterSplitViewHistogram, kOverviewEnterSplitViewHistogram,
kOverviewEnterMinimizedTabletHistogram>; kOverviewEnterMinimizedTabletHistogram>;
using OverviewExitFpsCounter = using OverviewExitMetricsTracker =
OverviewFpsCounter<kOverviewExitSingleClamshellHistogram, OverviewMetricsTracker<kOverviewExitSingleClamshellHistogram,
kOverviewExitClamshellHistogram, kOverviewExitClamshellHistogram,
kOverviewExitTabletHistogram, kOverviewExitTabletHistogram,
kOverviewExitSplitViewHistogram, kOverviewExitSplitViewHistogram,
kOverviewExitMinimizedTabletHistogram>; kOverviewExitMinimizedTabletHistogram>;
class ShutdownAnimationFpsCounterObserver : public OverviewObserver { class ShutdownAnimationMetricsTrackerObserver : public OverviewObserver {
public: public:
ShutdownAnimationFpsCounterObserver(ui::Compositor* compositor, ShutdownAnimationMetricsTrackerObserver(ui::Compositor* compositor,
bool in_split_view, bool in_split_view,
bool single_animation, bool single_animation,
bool minimized_in_tablet) bool minimized_in_tablet)
: fps_counter_(compositor, : metrics_tracker_(compositor,
in_split_view, in_split_view,
single_animation, single_animation,
minimized_in_tablet) { minimized_in_tablet) {
Shell::Get()->overview_controller()->AddObserver(this); Shell::Get()->overview_controller()->AddObserver(this);
} }
~ShutdownAnimationFpsCounterObserver() override { ShutdownAnimationMetricsTrackerObserver(
const ShutdownAnimationMetricsTrackerObserver&) = delete;
ShutdownAnimationMetricsTrackerObserver& operator=(
const ShutdownAnimationMetricsTrackerObserver&) = delete;
~ShutdownAnimationMetricsTrackerObserver() override {
Shell::Get()->overview_controller()->RemoveObserver(this); Shell::Get()->overview_controller()->RemoveObserver(this);
} }
...@@ -200,9 +203,7 @@ class ShutdownAnimationFpsCounterObserver : public OverviewObserver { ...@@ -200,9 +203,7 @@ class ShutdownAnimationFpsCounterObserver : public OverviewObserver {
} }
private: private:
OverviewExitFpsCounter fps_counter_; OverviewExitMetricsTracker metrics_tracker_;
DISALLOW_COPY_AND_ASSIGN(ShutdownAnimationFpsCounterObserver);
}; };
// Creates |drop_target_widget_|. It's created when a window or overview item is // Creates |drop_target_widget_|. It's created when a window or overview item is
...@@ -395,7 +396,7 @@ void OverviewGrid::Shutdown() { ...@@ -395,7 +396,7 @@ void OverviewGrid::Shutdown() {
bool minimized_in_tablet = overview_session_->enter_exit_overview_type() == bool minimized_in_tablet = overview_session_->enter_exit_overview_type() ==
OverviewEnterExitType::kFadeOutExit; OverviewEnterExitType::kFadeOutExit;
// The following instance self-destructs when shutdown animation ends. // The following instance self-destructs when shutdown animation ends.
new ShutdownAnimationFpsCounterObserver( new ShutdownAnimationMetricsTrackerObserver(
root_window_->layer()->GetCompositor(), in_split_view, root_window_->layer()->GetCompositor(), in_split_view,
single_animation_in_clamshell, minimized_in_tablet); single_animation_in_clamshell, minimized_in_tablet);
} }
...@@ -508,13 +509,13 @@ void OverviewGrid::PositionWindows( ...@@ -508,13 +509,13 @@ void OverviewGrid::PositionWindows(
!Shell::Get()->tablet_mode_controller()->InTabletMode(); !Shell::Get()->tablet_mode_controller()->InTabletMode();
bool minimized_in_tablet = overview_session_->enter_exit_overview_type() == bool minimized_in_tablet = overview_session_->enter_exit_overview_type() ==
OverviewEnterExitType::kFadeInEnter; OverviewEnterExitType::kFadeInEnter;
fps_counter_ = std::make_unique<OverviewEnterFpsCounter>( metrics_tracker_ = std::make_unique<OverviewEnterMetricsTracker>(
window_list_[0]->GetWindow()->layer()->GetCompositor(), window_list_[0]->GetWindow()->layer()->GetCompositor(),
SplitViewController::Get(root_window_)->InSplitViewMode(), SplitViewController::Get(root_window_)->InSplitViewMode(),
single_animation_in_clamshell, minimized_in_tablet); single_animation_in_clamshell, minimized_in_tablet);
} }
// Apply the animation after creating fps_counter_ so that unit test // Apply the animation after creating metrics_tracker_ so that unit test
// can correctly count the measure requests. // can correctly count the measure requests.
for (size_t i = 0; i < window_list_.size(); ++i) { for (size_t i = 0; i < window_list_.size(); ++i) {
if (rects[i].IsEmpty()) if (rects[i].IsEmpty())
...@@ -1000,7 +1001,7 @@ void OverviewGrid::OnWallpaperChanged() { ...@@ -1000,7 +1001,7 @@ void OverviewGrid::OnWallpaperChanged() {
} }
void OverviewGrid::OnStartingAnimationComplete(bool canceled) { void OverviewGrid::OnStartingAnimationComplete(bool canceled) {
fps_counter_.reset(); metrics_tracker_.reset();
if (canceled) if (canceled)
return; return;
......
...@@ -31,7 +31,6 @@ class Widget; ...@@ -31,7 +31,6 @@ class Widget;
namespace ash { namespace ash {
class DesksBarView; class DesksBarView;
class FpsCounter;
class OverviewGridEventHandler; class OverviewGridEventHandler;
class OverviewItem; class OverviewItem;
class PresentationTimeRecorder; class PresentationTimeRecorder;
...@@ -58,6 +57,12 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver, ...@@ -58,6 +57,12 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
public ScreenRotationAnimatorObserver, public ScreenRotationAnimatorObserver,
public WallpaperControllerObserver { public WallpaperControllerObserver {
public: public:
class MetricsTracker {
public:
MetricsTracker() = default;
virtual ~MetricsTracker() = default;
};
OverviewGrid(aura::Window* root_window, OverviewGrid(aura::Window* root_window,
const std::vector<aura::Window*>& window_list, const std::vector<aura::Window*>& window_list,
OverviewSession* overview_session); OverviewSession* overview_session);
...@@ -488,7 +493,7 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver, ...@@ -488,7 +493,7 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
std::vector<NudgeData> nudge_data_; std::vector<NudgeData> nudge_data_;
// Measures the animation smoothness of overview animation. // Measures the animation smoothness of overview animation.
std::unique_ptr<FpsCounter> fps_counter_; std::unique_ptr<MetricsTracker> metrics_tracker_;
// True to skip |PositionWindows()|. Used to avoid O(n^2) layout when // True to skip |PositionWindows()|. Used to avoid O(n^2) layout when
// reposition windows in tablet overview mode. // reposition windows in tablet overview mode.
......
...@@ -4,16 +4,37 @@ ...@@ -4,16 +4,37 @@
#include "ash/wm/overview/overview_test_util.h" #include "ash/wm/overview/overview_test_util.h"
#include "ash/public/cpp/overview_test_api.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/overview/overview_controller.h" #include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h" #include "ash/wm/overview/overview_grid.h"
#include "ash/wm/overview/overview_highlight_controller.h" #include "ash/wm/overview/overview_highlight_controller.h"
#include "ash/wm/overview/overview_item.h" #include "ash/wm/overview/overview_item.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
namespace ash { namespace ash {
namespace {
void WaitForOverviewAnimationState(OverviewAnimationState state) {
// Early out if animations are disabled.
if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() ==
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) {
return;
}
base::RunLoop run_loop;
OverviewTestApi().WaitForOverviewState(
state, base::BindLambdaForTesting([&](bool) { run_loop.Quit(); }));
run_loop.Run();
}
} // namespace
// TODO(sammiequon): Consider adding an overload for this function to trigger // TODO(sammiequon): Consider adding an overload for this function to trigger
// the key event |count| times. // the key event |count| times.
void SendKey(ui::KeyboardCode key, int flags) { void SendKey(ui::KeyboardCode key, int flags) {
...@@ -52,6 +73,15 @@ void ToggleOverview(OverviewEnterExitType type) { ...@@ -52,6 +73,15 @@ void ToggleOverview(OverviewEnterExitType type) {
overview_controller->StartOverview(type); overview_controller->StartOverview(type);
} }
void WaitForOverviewEnterAnimation() {
WaitForOverviewAnimationState(
OverviewAnimationState::kEnterAnimationComplete);
}
void WaitForOverviewExitAnimation() {
WaitForOverviewAnimationState(OverviewAnimationState::kExitAnimationComplete);
}
OverviewSession* GetOverviewSession() { OverviewSession* GetOverviewSession() {
auto* session = Shell::Get()->overview_controller()->overview_session(); auto* session = Shell::Get()->overview_controller()->overview_session();
DCHECK(session); DCHECK(session);
......
...@@ -25,6 +25,11 @@ const aura::Window* GetOverviewHighlightedWindow(); ...@@ -25,6 +25,11 @@ const aura::Window* GetOverviewHighlightedWindow();
void ToggleOverview( void ToggleOverview(
OverviewEnterExitType type = OverviewEnterExitType::kNormal); OverviewEnterExitType type = OverviewEnterExitType::kNormal);
// Waits for the overview enter/exit anmations to finish. No-op and immediately
// return if animations are disabled.
void WaitForOverviewEnterAnimation();
void WaitForOverviewExitAnimation();
OverviewSession* GetOverviewSession(); OverviewSession* GetOverviewSession();
const std::vector<std::unique_ptr<OverviewItem>>& GetOverviewItemsForRoot( const std::vector<std::unique_ptr<OverviewItem>>& GetOverviewItemsForRoot(
......
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