Commit ad2f62d6 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Log basic tab strip paint performance metrics

This add a metric for tracking time spent painting the TabStrip at a
high level and another for time spent painting TabIcons. The former is
logged for each frame the TabStrip paints. The latter is logged every
time a TabIcon paints, which can be more often since they sometimes
paint to their own layers.

These metrics are high-level and not super actionable on their own;
they are mainly intended to catch regressions.

Change-Id: Ie90f5db94ffab163aaf475c19ea678276db3b308
Bug: 966237
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626169
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Auto-Submit: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665003}
parent d82dec1a
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
#include "chrome/browser/ui/views/tabs/tab_icon.h" #include "chrome/browser/ui/views/tabs/tab_icon.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "cc/paint/paint_flags.h" #include "cc/paint/paint_flags.h"
#include "chrome/browser/favicon/favicon_utils.h" #include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
...@@ -167,6 +170,9 @@ void TabIcon::SetBackgroundColor(SkColor bg_color) { ...@@ -167,6 +170,9 @@ void TabIcon::SetBackgroundColor(SkColor bg_color) {
} }
void TabIcon::OnPaint(gfx::Canvas* canvas) { void TabIcon::OnPaint(gfx::Canvas* canvas) {
// This is used to log to UMA. NO EARLY RETURNS!
base::ElapsedTimer paint_timer;
// Compute the bounds adjusted for the hiding fraction. // Compute the bounds adjusted for the hiding fraction.
gfx::Rect contents_bounds = GetContentsBounds(); gfx::Rect contents_bounds = GetContentsBounds();
...@@ -183,19 +189,23 @@ void TabIcon::OnPaint(gfx::Canvas* canvas) { ...@@ -183,19 +189,23 @@ void TabIcon::OnPaint(gfx::Canvas* canvas) {
// The old animation replaces the favicon and should early-abort. // The old animation replaces the favicon and should early-abort.
if (!use_new_loading_animation_ && ShowingLoadingAnimation()) { if (!use_new_loading_animation_ && ShowingLoadingAnimation()) {
PaintLoadingAnimation(canvas, icon_bounds); PaintLoadingAnimation(canvas, icon_bounds);
return;
}
// Don't paint the attention indicator during the loading animation.
if (!ShowingLoadingAnimation() && ShowingAttentionIndicator() &&
!should_display_crashed_favicon_) {
PaintAttentionIndicatorAndIcon(canvas, GetIconToPaint(), icon_bounds);
} else { } else {
MaybePaintFavicon(canvas, GetIconToPaint(), icon_bounds); // Don't paint the attention indicator during the loading animation.
if (!ShowingLoadingAnimation() && ShowingAttentionIndicator() &&
!should_display_crashed_favicon_) {
PaintAttentionIndicatorAndIcon(canvas, GetIconToPaint(), icon_bounds);
} else {
MaybePaintFavicon(canvas, GetIconToPaint(), icon_bounds);
}
if (ShowingLoadingAnimation())
PaintLoadingAnimation(canvas, icon_bounds);
} }
if (ShowingLoadingAnimation()) UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
PaintLoadingAnimation(canvas, icon_bounds); "TabStrip.Tab.Icon.PaintDuration", paint_timer.Elapsed(),
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMicroseconds(10000), 50);
} }
void TabIcon::OnThemeChanged() { void TabIcon::OnThemeChanged() {
...@@ -216,6 +226,8 @@ void TabIcon::AnimationEnded(const gfx::Animation* animation) { ...@@ -216,6 +226,8 @@ void TabIcon::AnimationEnded(const gfx::Animation* animation) {
void TabIcon::PaintAttentionIndicatorAndIcon(gfx::Canvas* canvas, void TabIcon::PaintAttentionIndicatorAndIcon(gfx::Canvas* canvas,
const gfx::ImageSkia& icon, const gfx::ImageSkia& icon,
const gfx::Rect& bounds) { const gfx::Rect& bounds) {
TRACE_EVENT0("views", "TabIcon::PaintAttentionIndicatorAndIcon");
gfx::Point circle_center( gfx::Point circle_center(
bounds.x() + (base::i18n::IsRTL() ? 0 : gfx::kFaviconSize), bounds.x() + (base::i18n::IsRTL() ? 0 : gfx::kFaviconSize),
bounds.y() + gfx::kFaviconSize); bounds.y() + gfx::kFaviconSize);
...@@ -247,6 +259,8 @@ void TabIcon::PaintAttentionIndicatorAndIcon(gfx::Canvas* canvas, ...@@ -247,6 +259,8 @@ void TabIcon::PaintAttentionIndicatorAndIcon(gfx::Canvas* canvas,
} }
void TabIcon::PaintLoadingAnimation(gfx::Canvas* canvas, gfx::Rect bounds) { void TabIcon::PaintLoadingAnimation(gfx::Canvas* canvas, gfx::Rect bounds) {
TRACE_EVENT0("views", "TabIcon::PaintLoadingAnimation");
const ui::ThemeProvider* tp = GetThemeProvider(); const ui::ThemeProvider* tp = GetThemeProvider();
base::Optional<SkScalar> stroke_width; base::Optional<SkScalar> stroke_width;
if (use_new_loading_animation_) if (use_new_loading_animation_)
...@@ -287,6 +301,8 @@ const gfx::ImageSkia& TabIcon::GetIconToPaint() { ...@@ -287,6 +301,8 @@ const gfx::ImageSkia& TabIcon::GetIconToPaint() {
void TabIcon::MaybePaintFavicon(gfx::Canvas* canvas, void TabIcon::MaybePaintFavicon(gfx::Canvas* canvas,
const gfx::ImageSkia& icon, const gfx::ImageSkia& icon,
const gfx::Rect& bounds) { const gfx::Rect& bounds) {
TRACE_EVENT0("views", "TabIcon::MaybePaintFavicon");
if (icon.isNull()) if (icon.isNull())
return; return;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/timer/elapsed_timer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
...@@ -1829,6 +1830,9 @@ bool TabStrip::OnMouseWheel(const ui::MouseWheelEvent& event) { ...@@ -1829,6 +1830,9 @@ bool TabStrip::OnMouseWheel(const ui::MouseWheelEvent& event) {
} }
void TabStrip::PaintChildren(const views::PaintInfo& paint_info) { void TabStrip::PaintChildren(const views::PaintInfo& paint_info) {
// This is used to log to UMA. NO EARLY RETURNS!
base::ElapsedTimer paint_timer;
// The view order doesn't match the paint order (tabs_ contains the tab // The view order doesn't match the paint order (tabs_ contains the tab
// ordering). Additionally we need to paint the tabs that are closing in // ordering). Additionally we need to paint the tabs that are closing in
// |tabs_closing_map_|. // |tabs_closing_map_|.
...@@ -1918,6 +1922,11 @@ void TabStrip::PaintChildren(const views::PaintInfo& paint_info) { ...@@ -1918,6 +1922,11 @@ void TabStrip::PaintChildren(const views::PaintInfo& paint_info) {
// If the active tab is being dragged, it goes last. // If the active tab is being dragged, it goes last.
if (active_tab && is_dragging) if (active_tab && is_dragging)
active_tab->Paint(paint_info); active_tab->Paint(paint_info);
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"TabStrip.PaintChildrenDuration", paint_timer.Elapsed(),
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMicroseconds(10000), 50);
} }
const char* TabStrip::GetClassName() const { const char* TabStrip::GetClassName() const {
......
...@@ -131859,6 +131859,33 @@ should be kept until we use this API. --> ...@@ -131859,6 +131859,33 @@ should be kept until we use this API. -->
</summary> </summary>
</histogram> </histogram>
<histogram name="TabStrip.PaintChildrenDuration" units="microseconds"
expires_after="M80">
<owner>collinbaker@chromium.org</owner>
<owner>chrome-desktop-ui-sea@google.com</owner>
<summary>
Total time spent in each call of TabStrip::PaintChildren(). This comprises
the paint time for all parts of the TabStrip that do not paint to their own
layers. This is recorded at the end of TabStrip::PaintChildren(), when all
child views are finished painting.
As of writing (May 17, 2019), this always includes the tab backgrounds,
strokes, labels, close buttons. The tab icons and new tab button sometimes
paint to their own layer; in frames where this is so, their times won't be
included here.
</summary>
</histogram>
<histogram name="TabStrip.Tab.Icon.PaintDuration" units="microseconds"
expires_after="M80">
<owner>collinbaker@chromium.org</owner>
<owner>chrome-desktop-ui-sea@google.com</owner>
<summary>
Time spent painting a tab icon. This includes a page's favicon and loading
animation (when loading). This is recorded at the end of TabIcon::OnPaint().
</summary>
</histogram>
<histogram name="TabStrip.TabCountOnPageLoad" units="tabs" <histogram name="TabStrip.TabCountOnPageLoad" units="tabs"
expires_after="2020-01-01"> expires_after="2020-01-01">
<owner>yusufo@chromium.org</owner> <owner>yusufo@chromium.org</owner>
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