Commit 7b2e4297 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Chromium LUCI CQ

Ash HUD: Cleanup code of the "FPS" graph tab.

This CL refactors the animations frame rate graph
simplifying data acquisition.

Bug: 1075612
Change-Id: Icc0ed230f08cc561423e0b49881cebe67f7b7a11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2538702Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835711}
parent b2b7d0bf
...@@ -510,8 +510,6 @@ component("ash") { ...@@ -510,8 +510,6 @@ component("ash") {
"host/root_window_transformer.h", "host/root_window_transformer.h",
"host/transformer_helper.cc", "host/transformer_helper.cc",
"host/transformer_helper.h", "host/transformer_helper.h",
"hud_display/compositor_stats.cc",
"hud_display/compositor_stats.h",
"hud_display/cpu_graph_page_view.cc", "hud_display/cpu_graph_page_view.cc",
"hud_display/cpu_graph_page_view.h", "hud_display/cpu_graph_page_view.h",
"hud_display/cpu_status.cc", "hud_display/cpu_status.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/hud_display/compositor_stats.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/presentation_feedback.h"
namespace ash {
namespace hud_display {
CompositorStats::CompositorStats() = default;
CompositorStats::~CompositorStats() = default;
void CompositorStats::OnDidPresentCompositorFrame(
const gfx::PresentationFeedback& feedback) {
constexpr base::TimeDelta kOneSec = base::TimeDelta::FromSeconds(1);
constexpr base::TimeDelta k500ms = base::TimeDelta::FromMilliseconds(500);
if (!feedback.failed())
presented_times_.push_back(feedback.timestamp);
const base::TimeTicks deadline_1s = feedback.timestamp - kOneSec;
while (!presented_times_.empty() && presented_times_.front() <= deadline_1s)
presented_times_.pop_front();
const base::TimeTicks deadline_500ms = feedback.timestamp - k500ms;
frame_rate_for_last_half_second_ = 0;
for (auto i = presented_times_.crbegin();
(i != presented_times_.crend()) && (*i > deadline_500ms); ++i) {
++frame_rate_for_last_half_second_;
}
frame_rate_for_last_half_second_ *= 2;
}
} // namespace hud_display
} // namespace ash
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_HUD_DISPLAY_COMPOSITOR_STATS_H_
#define ASH_HUD_DISPLAY_COMPOSITOR_STATS_H_
#include "base/containers/circular_deque.h"
#include "base/time/time.h"
namespace gfx {
struct PresentationFeedback;
}
namespace ash {
namespace hud_display {
class CompositorStats {
public:
CompositorStats();
CompositorStats(const CompositorStats&) = delete;
CompositorStats& operator=(const CompositorStats&) = delete;
~CompositorStats();
float frame_rate_for_last_second() const { return presented_times_.size(); }
float frame_rate_for_last_half_second() const {
return frame_rate_for_last_half_second_;
}
// Updates the stats with |feedback|.
void OnDidPresentCompositorFrame(const gfx::PresentationFeedback& feedback);
private:
float frame_rate_for_last_half_second_;
// |timestamp| from PresentationFeedback for one second.
base::circular_deque<base::TimeTicks> presented_times_;
};
} // namespace hud_display
} // namespace ash
#endif // ASH_HUD_DISPLAY_COMPOSITOR_STATS_H_
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/views/metadata/metadata_impl_macros.h" #include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -111,9 +112,10 @@ void FPSGraphPageView::OnPaint(gfx::Canvas* canvas) { ...@@ -111,9 +112,10 @@ void FPSGraphPageView::OnPaint(gfx::Canvas* canvas) {
void FPSGraphPageView::OnDidPresentCompositorFrame( void FPSGraphPageView::OnDidPresentCompositorFrame(
uint32_t frame_token, uint32_t frame_token,
const gfx::PresentationFeedback& feedback) { const gfx::PresentationFeedback& feedback) {
compositor_stats_.OnDidPresentCompositorFrame(feedback); UpdateStats(feedback);
float frame_rate_1s = compositor_stats_.frame_rate_for_last_second();
float frame_rate_500ms = compositor_stats_.frame_rate_for_last_half_second(); float frame_rate_1s = frame_rate_for_last_second();
float frame_rate_500ms = frame_rate_for_last_half_second();
float refresh_rate = GetWidget()->GetCompositor()->refresh_rate(); float refresh_rate = GetWidget()->GetCompositor()->refresh_rate();
...@@ -160,6 +162,25 @@ void FPSGraphPageView::OnWindowRemovingFromRootWindow(aura::Window* window, ...@@ -160,6 +162,25 @@ void FPSGraphPageView::OnWindowRemovingFromRootWindow(aura::Window* window,
} }
} }
void FPSGraphPageView::UpdateStats(const gfx::PresentationFeedback& feedback) {
constexpr base::TimeDelta kOneSec = base::TimeDelta::FromSeconds(1);
constexpr base::TimeDelta k500ms = base::TimeDelta::FromMilliseconds(500);
if (!feedback.failed())
presented_times_.push_back(feedback.timestamp);
const base::TimeTicks deadline_1s = feedback.timestamp - kOneSec;
while (!presented_times_.empty() && presented_times_.front() <= deadline_1s)
presented_times_.pop_front();
const base::TimeTicks deadline_500ms = feedback.timestamp - k500ms;
frame_rate_for_last_half_second_ = 0;
for (auto i = presented_times_.crbegin();
(i != presented_times_.crend()) && (*i > deadline_500ms); ++i) {
++frame_rate_for_last_half_second_;
}
frame_rate_for_last_half_second_ *= 2;
}
void FPSGraphPageView::UpdateTopLabel(float refresh_rate) { void FPSGraphPageView::UpdateTopLabel(float refresh_rate) {
const float refresh_rate_rounded_10 = const float refresh_rate_rounded_10 =
ceilf(unsigned(refresh_rate) / 10.0F) * 10; ceilf(unsigned(refresh_rate) / 10.0F) * 10;
......
...@@ -7,22 +7,25 @@ ...@@ -7,22 +7,25 @@
#include "time.h" #include "time.h"
#include "ash/hud_display/compositor_stats.h"
#include "ash/hud_display/graph.h" #include "ash/hud_display/graph.h"
#include "ash/hud_display/graph_page_view_base.h" #include "ash/hud_display/graph_page_view_base.h"
#include "base/containers/circular_deque.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/compositor/compositor_observer.h" #include "ui/compositor/compositor_observer.h"
#include "ui/views/view_observer.h" #include "ui/views/view_observer.h"
namespace gfx {
struct PresentationFeedback;
}
namespace ash { namespace ash {
namespace hud_display { namespace hud_display {
class Grid; class Grid;
// Draws FPS graphs. // Draws several graphs per UI compositor frame. Every time
// Graph is updated in two ways: // OnDidPresentCompositorFrame() is called a new value is appended to the end
// 1. Regular update with UpdateData() sifts graph and adds new point. // of the graph. Every time UpdateData() is called, legend values are updated.
// 2. Every time OnFramePresented() is called, the last graph value is updated.
class FPSGraphPageView : public GraphPageViewBase, class FPSGraphPageView : public GraphPageViewBase,
public ui::CompositorObserver, public ui::CompositorObserver,
public views::ViewObserver, public views::ViewObserver,
...@@ -53,9 +56,18 @@ class FPSGraphPageView : public GraphPageViewBase, ...@@ -53,9 +56,18 @@ class FPSGraphPageView : public GraphPageViewBase,
aura::Window* new_root) override; aura::Window* new_root) override;
private: private:
float frame_rate_for_last_second() const { return presented_times_.size(); }
float frame_rate_for_last_half_second() const {
return frame_rate_for_last_half_second_;
}
// Sets grid top label to the maximum of the observed refresh rate. // Sets grid top label to the maximum of the observed refresh rate.
void UpdateTopLabel(float f_refresh_rate); void UpdateTopLabel(float f_refresh_rate);
// Updates the stats with |feedback|.
void UpdateStats(const gfx::PresentationFeedback& feedback);
// Number of frames per second presented. // Number of frames per second presented.
Graph frame_rate_1s_; Graph frame_rate_1s_;
Graph frame_rate_500ms_; Graph frame_rate_500ms_;
...@@ -65,7 +77,10 @@ class FPSGraphPageView : public GraphPageViewBase, ...@@ -65,7 +77,10 @@ class FPSGraphPageView : public GraphPageViewBase,
Grid* grid_; // not owned Grid* grid_; // not owned
CompositorStats compositor_stats_; float frame_rate_for_last_half_second_;
// |timestamp| from PresentationFeedback for one second.
base::circular_deque<base::TimeTicks> presented_times_;
}; };
} // namespace hud_display } // namespace hud_display
......
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