Commit 9c676fbc authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

applist: Use same metrics smoothness formula as ui.

Applist currently has some animations which records first frame number
before animation and uses a same (or really similar) formula at the
end as ui code does to calculate smoothness. These should be merged so
that when the ui code smoothness formula changes, so does applist
metrics smoothnesses.

Test: manual
Bug: 1051490
Change-Id: Iec859afacffd463404cd7630b6e79f04a67c77fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2070739
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744701}
parent 50830a10
...@@ -12,23 +12,12 @@ ...@@ -12,23 +12,12 @@
#include "ash/public/cpp/app_menu_constants.h" #include "ash/public/cpp/app_menu_constants.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
namespace ash { namespace ash {
namespace { namespace {
int CalculateAnimationSmoothness(int actual_frames,
base::TimeDelta ideal_duration,
float refresh_rate) {
int smoothness = 100;
const int ideal_frames = refresh_rate * ideal_duration.InSecondsF();
if (ideal_frames > actual_frames)
smoothness = 100 * actual_frames / ideal_frames;
return smoothness;
}
// These constants affect logging, and should not be changed without // These constants affect logging, and should not be changed without
// deprecating the following UMA histograms: // deprecating the following UMA histograms:
// - Apps.AppListTileClickIndexAndQueryLength // - Apps.AppListTileClickIndexAndQueryLength
...@@ -104,31 +93,6 @@ enum class ApplistSearchResultOpenedSource { ...@@ -104,31 +93,6 @@ enum class ApplistSearchResultOpenedSource {
kMaxApplistSearchResultOpenedSource = 3, kMaxApplistSearchResultOpenedSource = 3,
}; };
void RecordFolderShowHideAnimationSmoothness(int actual_frames,
base::TimeDelta ideal_duration,
float refresh_rate) {
const int smoothness =
CalculateAnimationSmoothness(actual_frames, ideal_duration, refresh_rate);
UMA_HISTOGRAM_PERCENTAGE(kFolderShowHideAnimationSmoothness, smoothness);
}
void RecordPaginationAnimationSmoothness(int actual_frames,
base::TimeDelta ideal_duration,
float refresh_rate,
bool is_tablet_mode) {
const int smoothness =
CalculateAnimationSmoothness(actual_frames, ideal_duration, refresh_rate);
UMA_HISTOGRAM_PERCENTAGE(kPaginationTransitionAnimationSmoothness,
smoothness);
if (is_tablet_mode) {
UMA_HISTOGRAM_PERCENTAGE(kPaginationTransitionAnimationSmoothnessInTablet,
smoothness);
} else {
UMA_HISTOGRAM_PERCENTAGE(
kPaginationTransitionAnimationSmoothnessInClamshell, smoothness);
}
}
void AppListRecordPageSwitcherSourceByEventType(ui::EventType type, void AppListRecordPageSwitcherSourceByEventType(ui::EventType type,
bool is_tablet_mode) { bool is_tablet_mode) {
AppListPageSwitcherSource source; AppListPageSwitcherSource source;
...@@ -346,4 +310,61 @@ bool IsCommandIdAnAppLaunch(int command_id_number) { ...@@ -346,4 +310,61 @@ bool IsCommandIdAnAppLaunch(int command_id_number) {
return false; return false;
} }
FolderShowHideAnimationReporter::FolderShowHideAnimationReporter() = default;
FolderShowHideAnimationReporter::~FolderShowHideAnimationReporter() = default;
void FolderShowHideAnimationReporter::Report(int value) {
UMA_HISTOGRAM_PERCENTAGE(kFolderShowHideAnimationSmoothness, value);
}
PaginationTransitionAnimationReporter::PaginationTransitionAnimationReporter() =
default;
PaginationTransitionAnimationReporter::
~PaginationTransitionAnimationReporter() = default;
void PaginationTransitionAnimationReporter::Report(int value) {
UMA_HISTOGRAM_PERCENTAGE(kPaginationTransitionAnimationSmoothness, value);
if (is_tablet_mode_) {
UMA_HISTOGRAM_PERCENTAGE(kPaginationTransitionAnimationSmoothnessInTablet,
value);
} else {
UMA_HISTOGRAM_PERCENTAGE(
kPaginationTransitionAnimationSmoothnessInClamshell, value);
}
}
AppListAnimationMetricsRecorder::AppListAnimationMetricsRecorder(
ui::AnimationMetricsReporter* reporter)
: ui::AnimationMetricsRecorder(reporter) {}
AppListAnimationMetricsRecorder::~AppListAnimationMetricsRecorder() = default;
void AppListAnimationMetricsRecorder::OnAnimationStart(
base::TimeDelta expected_duration,
ui::Compositor* compositor) {
if (!compositor)
return;
animation_started_ = true;
ui::AnimationMetricsRecorder::OnAnimationStart(
compositor->activated_frame_count(), base::TimeTicks::Now(),
expected_duration);
}
void AppListAnimationMetricsRecorder::OnAnimationEnd(
ui::Compositor* compositor) {
if (!animation_started_)
return;
animation_started_ = false;
if (!compositor)
return;
ui::AnimationMetricsRecorder::OnAnimationEnd(
compositor->activated_frame_count(), compositor->refresh_rate());
}
} // namespace ash } // namespace ash
...@@ -7,8 +7,15 @@ ...@@ -7,8 +7,15 @@
#include "ash/app_list/app_list_export.h" #include "ash/app_list/app_list_export.h"
#include "ash/public/cpp/app_list/app_list_types.h" #include "ash/public/cpp/app_list/app_list_types.h"
#include "base/time/time.h"
#include "ui/compositor/animation_metrics_recorder.h"
#include "ui/compositor/animation_metrics_reporter.h"
#include "ui/events/event.h" #include "ui/events/event.h"
namespace ui {
class Compositor;
}
namespace ash { namespace ash {
class AppListModel; class AppListModel;
...@@ -304,21 +311,12 @@ struct AppLaunchedMetricParams { ...@@ -304,21 +311,12 @@ struct AppLaunchedMetricParams {
bool home_launcher_shown = false; bool home_launcher_shown = false;
}; };
void RecordFolderShowHideAnimationSmoothness(int actual_frames,
base::TimeDelta ideal_duration,
float refresh_rate);
void AppListRecordPageSwitcherSourceByEventType(ui::EventType type, void AppListRecordPageSwitcherSourceByEventType(ui::EventType type,
bool is_tablet_mode); bool is_tablet_mode);
void RecordPageSwitcherSource(AppListPageSwitcherSource source, void RecordPageSwitcherSource(AppListPageSwitcherSource source,
bool is_tablet_mode); bool is_tablet_mode);
void RecordPaginationAnimationSmoothness(int actual_frames,
base::TimeDelta ideal_duration,
float refresh_rate,
bool is_tablet_mode);
void RecordZeroStateSearchResultUserActionHistogram( void RecordZeroStateSearchResultUserActionHistogram(
ZeroStateSearchResultUserActionType action); ZeroStateSearchResultUserActionType action);
...@@ -345,6 +343,56 @@ APP_LIST_EXPORT void RecordAppListAppLaunched(AppListLaunchedFrom launched_from, ...@@ -345,6 +343,56 @@ APP_LIST_EXPORT void RecordAppListAppLaunched(AppListLaunchedFrom launched_from,
APP_LIST_EXPORT bool IsCommandIdAnAppLaunch(int command_id); APP_LIST_EXPORT bool IsCommandIdAnAppLaunch(int command_id);
class FolderShowHideAnimationReporter : public ui::AnimationMetricsReporter {
public:
FolderShowHideAnimationReporter();
FolderShowHideAnimationReporter(FolderShowHideAnimationReporter&) = delete;
FolderShowHideAnimationReporter& operator=(FolderShowHideAnimationReporter&) =
delete;
~FolderShowHideAnimationReporter() override;
// ui:AnimationMetricsReporter:
void Report(int value) override;
};
class PaginationTransitionAnimationReporter
: public ui::AnimationMetricsReporter {
public:
PaginationTransitionAnimationReporter();
PaginationTransitionAnimationReporter(
PaginationTransitionAnimationReporter&) = delete;
PaginationTransitionAnimationReporter& operator=(
PaginationTransitionAnimationReporter&) = delete;
~PaginationTransitionAnimationReporter() override;
// ui:AnimationMetricsReporter:
void Report(int value) override;
void set_is_tablet_mode(bool val) { is_tablet_mode_ = val; }
private:
bool is_tablet_mode_ = false;
};
// App list specific animation metrics recorder which has a pointer to the
// compositor the app list to simplify things for callsites.
class AppListAnimationMetricsRecorder : public ui::AnimationMetricsRecorder {
public:
explicit AppListAnimationMetricsRecorder(
ui::AnimationMetricsReporter* reporter);
AppListAnimationMetricsRecorder(AppListAnimationMetricsRecorder&) = delete;
AppListAnimationMetricsRecorder& operator=(AppListAnimationMetricsRecorder&) =
delete;
~AppListAnimationMetricsRecorder();
void OnAnimationStart(base::TimeDelta expected_duration,
ui::Compositor* compositor);
void OnAnimationEnd(ui::Compositor* compositor);
private:
bool animation_started_ = false;
};
} // namespace ash } // namespace ash
#endif // ASH_APP_LIST_APP_LIST_METRICS_H_ #endif // ASH_APP_LIST_APP_LIST_METRICS_H_
...@@ -56,10 +56,6 @@ constexpr int kIndexChildItems = 2; ...@@ -56,10 +56,6 @@ constexpr int kIndexChildItems = 2;
constexpr int kIndexFolderHeader = 3; constexpr int kIndexFolderHeader = 3;
constexpr int kIndexPageSwitcher = 4; constexpr int kIndexPageSwitcher = 4;
int GetCompositorActivatedFrameCount(ui::Compositor* compositor) {
return compositor ? compositor->activated_frame_count() : 0;
}
// Transit from the background of the folder item's icon to the opened // Transit from the background of the folder item's icon to the opened
// folder's background when opening the folder. Transit the other way when // folder's background when opening the folder. Transit the other way when
// closing the folder. // closing the folder.
...@@ -476,6 +472,12 @@ AppListFolderView::AppListFolderView(AppsContainerView* container_view, ...@@ -476,6 +472,12 @@ AppListFolderView::AppListFolderView(AppsContainerView* container_view,
contents_view_->app_list_view()->is_tablet_mode())); contents_view_->app_list_view()->is_tablet_mode()));
view_model_->Add(page_switcher_, kIndexPageSwitcher); view_model_->Add(page_switcher_, kIndexPageSwitcher);
show_hide_metrics_reporter_ =
std::make_unique<FolderShowHideAnimationReporter>();
show_hide_metrics_recorder_ =
std::make_unique<AppListAnimationMetricsRecorder>(
show_hide_metrics_reporter_.get());
model_->AddObserver(this); model_->AddObserver(this);
} }
...@@ -502,8 +504,9 @@ void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { ...@@ -502,8 +504,9 @@ void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) {
void AppListFolderView::ScheduleShowHideAnimation(bool show, void AppListFolderView::ScheduleShowHideAnimation(bool show,
bool hide_for_reparent) { bool hide_for_reparent) {
CreateOpenOrCloseFolderAccessibilityEvent(show); CreateOpenOrCloseFolderAccessibilityEvent(show);
animation_start_frame_number_ = show_hide_metrics_recorder_->OnAnimationStart(
GetCompositorActivatedFrameCount(GetCompositor()); GetAppListConfig().folder_transition_in_duration(),
GetWidget()->GetCompositor());
hide_for_reparent_ = hide_for_reparent; hide_for_reparent_ = hide_for_reparent;
...@@ -666,25 +669,7 @@ AppListItemView* AppListFolderView::GetActivatedFolderItemView() { ...@@ -666,25 +669,7 @@ AppListItemView* AppListFolderView::GetActivatedFolderItemView() {
} }
void AppListFolderView::RecordAnimationSmoothness() { void AppListFolderView::RecordAnimationSmoothness() {
ui::Compositor* compositor = GetCompositor(); show_hide_metrics_recorder_->OnAnimationEnd(GetWidget()->GetCompositor());
// Do not record animation smoothness if |compositor| is nullptr.
if (!compositor)
return;
// Do not record if the start frame number doesn't exist; either animation is
// not scheduled or the record happens.
if (!animation_start_frame_number_.has_value())
return;
const int end_frame_number = GetCompositorActivatedFrameCount(compositor);
if (end_frame_number > *animation_start_frame_number_) {
RecordFolderShowHideAnimationSmoothness(
end_frame_number - *animation_start_frame_number_,
GetAppListConfig().folder_transition_in_duration(),
compositor->refresh_rate());
}
// Resets the frame number so that further invocation won't record the
// metrics.
animation_start_frame_number_.reset();
} }
void AppListFolderView::OnTabletModeChanged(bool started) { void AppListFolderView::OnTabletModeChanged(bool started) {
......
...@@ -194,8 +194,9 @@ class APP_LIST_EXPORT AppListFolderView : public views::View, ...@@ -194,8 +194,9 @@ class APP_LIST_EXPORT AppListFolderView : public views::View,
std::unique_ptr<Animation> top_icon_animation_; std::unique_ptr<Animation> top_icon_animation_;
std::unique_ptr<Animation> contents_container_animation_; std::unique_ptr<Animation> contents_container_animation_;
// The compositor frame number when animation starts. // Records smoothness of the folder show/hide animation.
base::Optional<int> animation_start_frame_number_; std::unique_ptr<AppListAnimationMetricsRecorder> show_hide_metrics_recorder_;
std::unique_ptr<FolderShowHideAnimationReporter> show_hide_metrics_reporter_;
DISALLOW_COPY_AND_ASSIGN(AppListFolderView); DISALLOW_COPY_AND_ASSIGN(AppListFolderView);
}; };
......
...@@ -257,10 +257,6 @@ bool IsOEMFolderItem(AppListItem* item) { ...@@ -257,10 +257,6 @@ bool IsOEMFolderItem(AppListItem* item) {
AppListFolderItem::FOLDER_TYPE_OEM; AppListFolderItem::FOLDER_TYPE_OEM;
} }
int GetCompositorActivatedFrameCount(ui::Compositor* compositor) {
return compositor ? compositor->activated_frame_count() : 0;
}
} // namespace } // namespace
std::string GridIndex::ToString() const { std::string GridIndex::ToString() const {
...@@ -335,7 +331,6 @@ AppsGridView::AppsGridView(ContentsView* contents_view, ...@@ -335,7 +331,6 @@ AppsGridView::AppsGridView(ContentsView* contents_view,
: folder_delegate_(folder_delegate), : folder_delegate_(folder_delegate),
contents_view_(contents_view), contents_view_(contents_view),
page_flip_delay_in_ms_(kPageFlipDelayInMsFullscreen), page_flip_delay_in_ms_(kPageFlipDelayInMsFullscreen),
pagination_animation_start_frame_number_(0),
view_structure_(this) { view_structure_(this) {
DCHECK(contents_view_); DCHECK(contents_view_);
SetPaintToLayer(ui::LAYER_NOT_DRAWN); SetPaintToLayer(ui::LAYER_NOT_DRAWN);
...@@ -368,6 +363,12 @@ AppsGridView::AppsGridView(ContentsView* contents_view, ...@@ -368,6 +363,12 @@ AppsGridView::AppsGridView(ContentsView* contents_view,
: base::BindRepeating(&AppListRecordPageSwitcherSourceByEventType), : base::BindRepeating(&AppListRecordPageSwitcherSourceByEventType),
IsTabletMode()); IsTabletMode());
bounds_animator_->AddObserver(this); bounds_animator_->AddObserver(this);
pagination_metrics_reporter_ =
std::make_unique<PaginationTransitionAnimationReporter>();
pagination_metrics_recorder_ =
std::make_unique<AppListAnimationMetricsRecorder>(
pagination_metrics_reporter_.get());
} }
AppsGridView::~AppsGridView() { AppsGridView::~AppsGridView() {
...@@ -2793,8 +2794,6 @@ void AppsGridView::TransitionStarting() { ...@@ -2793,8 +2794,6 @@ void AppsGridView::TransitionStarting() {
MaybeCreateGradientMask(); MaybeCreateGradientMask();
CancelContextMenusOnCurrentPage(); CancelContextMenusOnCurrentPage();
pagination_animation_start_frame_number_ =
GetCompositorActivatedFrameCount(layer()->GetCompositor());
} }
void AppsGridView::TransitionStarted() { void AppsGridView::TransitionStarted() {
...@@ -2802,6 +2801,10 @@ void AppsGridView::TransitionStarted() { ...@@ -2802,6 +2801,10 @@ void AppsGridView::TransitionStarted() {
pagination_model_.selected_page()) > 1) { pagination_model_.selected_page()) > 1) {
Layout(); Layout();
} }
pagination_metrics_recorder_->OnAnimationStart(
pagination_model_.GetTransitionAnimationSlideDuration(),
GetWidget()->GetCompositor());
} }
void AppsGridView::TransitionChanged() { void AppsGridView::TransitionChanged() {
...@@ -2842,21 +2845,9 @@ void AppsGridView::TransitionChanged() { ...@@ -2842,21 +2845,9 @@ void AppsGridView::TransitionChanged() {
} }
void AppsGridView::TransitionEnded() { void AppsGridView::TransitionEnded() {
const base::TimeDelta duration = pagination_metrics_reporter_->set_is_tablet_mode(IsTabletMode());
pagination_model_.GetTransitionAnimationSlideDuration(); pagination_metrics_recorder_->OnAnimationEnd(GetWidget()->GetCompositor());
ui::Compositor* compositor = layer()->GetCompositor();
// Do not record animation smoothness if |compositor| is nullptr.
if (!compositor)
return;
const int end_frame_number = GetCompositorActivatedFrameCount(compositor);
if (end_frame_number > pagination_animation_start_frame_number_ &&
!duration.is_zero()) {
RecordPaginationAnimationSmoothness(
end_frame_number - pagination_animation_start_frame_number_, duration,
compositor->refresh_rate(), IsTabletMode());
}
// Gradient mask is no longer necessary once transition is finished. // Gradient mask is no longer necessary once transition is finished.
if (layer()->layer_mask_layer()) if (layer()->layer_mask_layer())
layer()->SetMaskLayer(nullptr); layer()->SetMaskLayer(nullptr);
......
...@@ -816,9 +816,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View, ...@@ -816,9 +816,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// True if it is the end gesture from shelf dragging. // True if it is the end gesture from shelf dragging.
bool is_end_gesture_ = false; bool is_end_gesture_ = false;
// The compositor frame number when animation starts.
int pagination_animation_start_frame_number_;
// view structure used only for non-folder. // view structure used only for non-folder.
PagedViewStructure view_structure_; PagedViewStructure view_structure_;
...@@ -846,6 +843,11 @@ class APP_LIST_EXPORT AppsGridView : public views::View, ...@@ -846,6 +843,11 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// If true, Layout() does nothing. See where set for details. // If true, Layout() does nothing. See where set for details.
bool ignore_layout_ = false; bool ignore_layout_ = false;
// Records smoothness of pagination animation.
std::unique_ptr<AppListAnimationMetricsRecorder> pagination_metrics_recorder_;
std::unique_ptr<PaginationTransitionAnimationReporter>
pagination_metrics_reporter_;
// Records the presentation time for apps grid dragging. // Records the presentation time for apps grid dragging.
std::unique_ptr<PresentationTimeRecorder> presentation_time_recorder_; std::unique_ptr<PresentationTimeRecorder> presentation_time_recorder_;
......
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