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 @@
#include "ash/metrics/histogram_macros.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/shelf_config.h"
#include "ash/public/cpp/shelf_types.h"
......@@ -49,11 +49,13 @@
#include "ash/wm/workspace/backdrop_controller.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace_controller.h"
#include "base/bind.h"
#include "base/containers/unique_ptr_adapters.h"
#include "base/numerics/ranges.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/aura_constants.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/vector2d_f.h"
#include "ui/gfx/transform_util.h"
......@@ -123,74 +125,75 @@ template <const char* clamshell_single_name,
const char* tablet_name,
const char* splitview_name,
const char* tablet_minimized_name>
class OverviewFpsCounter : public FpsCounter {
class OverviewMetricsTracker : public OverviewGrid::MetricsTracker {
public:
OverviewFpsCounter(ui::Compositor* compositor,
bool in_split_view,
bool single_animation_in_clamshell,
bool minimized_in_tablet)
: FpsCounter(compositor),
in_split_view_(in_split_view),
single_animation_in_clamshell_(single_animation_in_clamshell),
minimized_in_tablet_(minimized_in_tablet) {}
~OverviewFpsCounter() override {
int smoothness = ComputeSmoothness();
if (smoothness < 0)
return;
if (single_animation_in_clamshell_)
OverviewMetricsTracker(ui::Compositor* compositor,
bool in_split_view,
bool single_animation_in_clamshell,
bool minimized_in_tablet)
: tracker_(compositor->RequestNewThroughputTracker()) {
tracker_.Start(metrics_util::ForSmoothness(base::BindRepeating(
&OverviewMetricsTracker::ReportOverviewSmoothness, in_split_view,
single_animation_in_clamshell, minimized_in_tablet)));
}
OverviewMetricsTracker(const OverviewMetricsTracker&) = delete;
OverviewMetricsTracker& operator=(const OverviewMetricsTracker&) = delete;
~OverviewMetricsTracker() override { tracker_.Stop(); }
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);
else
UMA_HISTOGRAM_PERCENTAGE_IN_CLAMSHELL(clamshell_multi_name, smoothness);
if (minimized_in_tablet_) {
if (minimized_in_tablet) {
UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW(
in_split_view_, tablet_minimized_name, smoothness);
in_split_view, tablet_minimized_name, smoothness);
} else {
UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW(in_split_view_,
UMA_HISTOGRAM_PERCENTAGE_IN_TABLET_NON_SPLITVIEW(in_split_view,
tablet_name, smoothness);
}
UMA_HISTOGRAM_PERCENTAGE_IN_SPLITVIEW(in_split_view_, splitview_name,
UMA_HISTOGRAM_PERCENTAGE_IN_SPLITVIEW(in_split_view, splitview_name,
smoothness);
}
private:
bool in_split_view_;
// 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);
ui::ThroughputTracker tracker_;
};
using OverviewEnterFpsCounter =
OverviewFpsCounter<kOverviewEnterSingleClamshellHistogram,
kOverviewEnterClamshellHistogram,
kOverviewEnterTabletHistogram,
kOverviewEnterSplitViewHistogram,
kOverviewEnterMinimizedTabletHistogram>;
using OverviewExitFpsCounter =
OverviewFpsCounter<kOverviewExitSingleClamshellHistogram,
kOverviewExitClamshellHistogram,
kOverviewExitTabletHistogram,
kOverviewExitSplitViewHistogram,
kOverviewExitMinimizedTabletHistogram>;
class ShutdownAnimationFpsCounterObserver : public OverviewObserver {
using OverviewEnterMetricsTracker =
OverviewMetricsTracker<kOverviewEnterSingleClamshellHistogram,
kOverviewEnterClamshellHistogram,
kOverviewEnterTabletHistogram,
kOverviewEnterSplitViewHistogram,
kOverviewEnterMinimizedTabletHistogram>;
using OverviewExitMetricsTracker =
OverviewMetricsTracker<kOverviewExitSingleClamshellHistogram,
kOverviewExitClamshellHistogram,
kOverviewExitTabletHistogram,
kOverviewExitSplitViewHistogram,
kOverviewExitMinimizedTabletHistogram>;
class ShutdownAnimationMetricsTrackerObserver : public OverviewObserver {
public:
ShutdownAnimationFpsCounterObserver(ui::Compositor* compositor,
bool in_split_view,
bool single_animation,
bool minimized_in_tablet)
: fps_counter_(compositor,
in_split_view,
single_animation,
minimized_in_tablet) {
ShutdownAnimationMetricsTrackerObserver(ui::Compositor* compositor,
bool in_split_view,
bool single_animation,
bool minimized_in_tablet)
: metrics_tracker_(compositor,
in_split_view,
single_animation,
minimized_in_tablet) {
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);
}
......@@ -200,9 +203,7 @@ class ShutdownAnimationFpsCounterObserver : public OverviewObserver {
}
private:
OverviewExitFpsCounter fps_counter_;
DISALLOW_COPY_AND_ASSIGN(ShutdownAnimationFpsCounterObserver);
OverviewExitMetricsTracker metrics_tracker_;
};
// Creates |drop_target_widget_|. It's created when a window or overview item is
......@@ -395,7 +396,7 @@ void OverviewGrid::Shutdown() {
bool minimized_in_tablet = overview_session_->enter_exit_overview_type() ==
OverviewEnterExitType::kFadeOutExit;
// The following instance self-destructs when shutdown animation ends.
new ShutdownAnimationFpsCounterObserver(
new ShutdownAnimationMetricsTrackerObserver(
root_window_->layer()->GetCompositor(), in_split_view,
single_animation_in_clamshell, minimized_in_tablet);
}
......@@ -508,13 +509,13 @@ void OverviewGrid::PositionWindows(
!Shell::Get()->tablet_mode_controller()->InTabletMode();
bool minimized_in_tablet = overview_session_->enter_exit_overview_type() ==
OverviewEnterExitType::kFadeInEnter;
fps_counter_ = std::make_unique<OverviewEnterFpsCounter>(
metrics_tracker_ = std::make_unique<OverviewEnterMetricsTracker>(
window_list_[0]->GetWindow()->layer()->GetCompositor(),
SplitViewController::Get(root_window_)->InSplitViewMode(),
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.
for (size_t i = 0; i < window_list_.size(); ++i) {
if (rects[i].IsEmpty())
......@@ -1000,7 +1001,7 @@ void OverviewGrid::OnWallpaperChanged() {
}
void OverviewGrid::OnStartingAnimationComplete(bool canceled) {
fps_counter_.reset();
metrics_tracker_.reset();
if (canceled)
return;
......
......@@ -31,7 +31,6 @@ class Widget;
namespace ash {
class DesksBarView;
class FpsCounter;
class OverviewGridEventHandler;
class OverviewItem;
class PresentationTimeRecorder;
......@@ -58,6 +57,12 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
public ScreenRotationAnimatorObserver,
public WallpaperControllerObserver {
public:
class MetricsTracker {
public:
MetricsTracker() = default;
virtual ~MetricsTracker() = default;
};
OverviewGrid(aura::Window* root_window,
const std::vector<aura::Window*>& window_list,
OverviewSession* overview_session);
......@@ -488,7 +493,7 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
std::vector<NudgeData> nudge_data_;
// 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
// reposition windows in tablet overview mode.
......
......@@ -4,16 +4,37 @@
#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/shell.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h"
#include "ash/wm/overview/overview_highlight_controller.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"
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
// the key event |count| times.
void SendKey(ui::KeyboardCode key, int flags) {
......@@ -52,6 +73,15 @@ void ToggleOverview(OverviewEnterExitType type) {
overview_controller->StartOverview(type);
}
void WaitForOverviewEnterAnimation() {
WaitForOverviewAnimationState(
OverviewAnimationState::kEnterAnimationComplete);
}
void WaitForOverviewExitAnimation() {
WaitForOverviewAnimationState(OverviewAnimationState::kExitAnimationComplete);
}
OverviewSession* GetOverviewSession() {
auto* session = Shell::Get()->overview_controller()->overview_session();
DCHECK(session);
......
......@@ -25,6 +25,11 @@ const aura::Window* GetOverviewHighlightedWindow();
void ToggleOverview(
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();
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