Commit d55cd8aa authored by wutao's avatar wutao Committed by Commit Bot

Assistant: Add UMA for container view animation

This patch adds UMA to measure assistant container view's animation
smoothness.

Bug: b/113942916, 887583
Test: see UMA in histograms.
Change-Id: I83da71c4c0003061f5ca852a6128534a681646d3
Reviewed-on: https://chromium-review.googlesource.com/1234956Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593411}
parent 9ecf8ac1
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/assistant/ui/assistant_web_view.h" #include "ash/assistant/ui/assistant_web_view.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_targeter.h" #include "ui/aura/window_targeter.h"
...@@ -144,13 +145,24 @@ class AssistantContainerLayout : public views::LayoutManager { ...@@ -144,13 +145,24 @@ class AssistantContainerLayout : public views::LayoutManager {
DISALLOW_COPY_AND_ASSIGN(AssistantContainerLayout); DISALLOW_COPY_AND_ASSIGN(AssistantContainerLayout);
}; };
int GetCompositorFrameNumber(ui::Layer* layer) {
ui::Compositor* compositor = layer->GetCompositor();
return compositor ? compositor->activated_frame_count() : 0;
}
float GetCompositorRefreshRate(ui::Layer* layer) {
ui::Compositor* compositor = layer->GetCompositor();
return compositor ? compositor->refresh_rate() : 60.0f;
}
} // namespace } // namespace
// AssistantContainerView ------------------------------------------------------ // AssistantContainerView ------------------------------------------------------
AssistantContainerView::AssistantContainerView( AssistantContainerView::AssistantContainerView(
AssistantController* assistant_controller) AssistantController* assistant_controller)
: assistant_controller_(assistant_controller) { : assistant_controller_(assistant_controller),
animation_start_frame_number_(0) {
set_accept_events(true); set_accept_events(true);
SetAnchor(nullptr); SetAnchor(nullptr);
set_close_on_deactivate(false); set_close_on_deactivate(false);
...@@ -234,6 +246,8 @@ void AssistantContainerView::PreferredSizeChanged() { ...@@ -234,6 +246,8 @@ void AssistantContainerView::PreferredSizeChanged() {
radius_start_ = radius_start_ =
GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius();
animation_start_frame_number_ = GetCompositorFrameNumber(layer());
// Start animation. // Start animation.
resize_animation_->Show(); resize_animation_->Show();
return; return;
...@@ -392,6 +406,27 @@ void AssistantContainerView::AnimationProgressed( ...@@ -392,6 +406,27 @@ void AssistantContainerView::AnimationProgressed(
GetWidget()->SetBounds(bounds); GetWidget()->SetBounds(bounds);
} }
void AssistantContainerView::AnimationEnded(const gfx::Animation* animation) {
const int ideal_frames = GetCompositorRefreshRate(layer()) *
kResizeAnimationDurationMs /
base::Time::kMillisecondsPerSecond;
const int actual_frames =
GetCompositorFrameNumber(layer()) - animation_start_frame_number_;
if (actual_frames <= 0)
return;
int smoothness = 100;
// The |actual_frames| could be |ideal_frames| + 1. The reason could be that
// the animation timer is running with interval of 0.016666 s, which could
// animate one more frame than expected due to rounding error.
if (ideal_frames > actual_frames)
smoothness = 100 * actual_frames / ideal_frames;
UMA_HISTOGRAM_PERCENTAGE("Assistant.ContainerView.Resize.AnimationSmoothness",
smoothness);
}
void AssistantContainerView::OnDisplayMetricsChanged( void AssistantContainerView::OnDisplayMetricsChanged(
const display::Display& display, const display::Display& display,
uint32_t changed_metrics) { uint32_t changed_metrics) {
......
...@@ -62,6 +62,7 @@ class AssistantContainerView : public views::BubbleDialogDelegateView, ...@@ -62,6 +62,7 @@ class AssistantContainerView : public views::BubbleDialogDelegateView,
// gfx::AnimationDelegate: // gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override; void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationEnded(const gfx::Animation* animation) override;
// display::DisplayObserver: // display::DisplayObserver:
void OnDisplayMetricsChanged(const display::Display& display, void OnDisplayMetricsChanged(const display::Display& display,
...@@ -101,6 +102,8 @@ class AssistantContainerView : public views::BubbleDialogDelegateView, ...@@ -101,6 +102,8 @@ class AssistantContainerView : public views::BubbleDialogDelegateView,
// This layer shows a rounded rectangle with drop shadow. // This layer shows a rounded rectangle with drop shadow.
ui::Layer shadow_layer_; ui::Layer shadow_layer_;
int animation_start_frame_number_ = 0;
DISALLOW_COPY_AND_ASSIGN(AssistantContainerView); DISALLOW_COPY_AND_ASSIGN(AssistantContainerView);
}; };
......
...@@ -5205,6 +5205,16 @@ uploading your change for review. ...@@ -5205,6 +5205,16 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Assistant.ContainerView.Resize.AnimationSmoothness" units="%">
<owner>wutao@chromium.org</owner>
<summary>
Relative animation smoothness of resizing assistant container window. 100%
represents ideally smooth 60 frames per second. 50% represents when only 30
frames per second is achieved during the animations. 0% should not happen.
This metric is recorded when the container window resizing is finished.
</summary>
</histogram>
<histogram name="Assistant.HotwordEnableNotification" enum="BooleanHit"> <histogram name="Assistant.HotwordEnableNotification" enum="BooleanHit">
<owner>updowndota@chromium.org</owner> <owner>updowndota@chromium.org</owner>
<summary> <summary>
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