Commit 269f7161 authored by Weiliang Chen's avatar Weiliang Chen Committed by Commit Bot

cc: Set up a Flag for Displaying Performance Metrics

Set up a feature flag and corresponding state inside cc to enable
using HUD for displaying performance metrics. Currently when we enable
the show performance metrics flag we only add WebVitals metrics, which
comes from Blink. We might want to add other metrics in the future.

R=sadrul

Bug: 1149385
Change-Id: I437e113a5fc4f44c6fbaa542c92d1f2da6cbb393
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2540570
Commit-Queue: weiliangc <weiliangc@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828221}
parent 8e9881c3
......@@ -60,4 +60,7 @@ const base::Feature kSchedulerSmoothnessForAnimatedScrolls{
const base::Feature kWheelEventRegions{"WheelEventRegions",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kHudDisplayForPerformanceMetrics{
"HudDisplayForPerformanceMetrics", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
......@@ -42,6 +42,10 @@ CC_BASE_EXPORT extern const base::Feature
// https://docs.google.com/document/d/1ar4WhVnLA-fmw6atgP-23iq-ys_NfFoGb3LA5AgaylA/edit?usp=sharing
CC_BASE_EXPORT extern const base::Feature kWheelEventRegions;
// When enabled, cc will show blink's Web-Vital metrics inside its heads up
// display.
CC_BASE_EXPORT extern const base::Feature kHudDisplayForPerformanceMetrics;
} // namespace features
#endif // CC_BASE_FEATURES_H_
......@@ -4,29 +4,10 @@
#include "cc/debug/layer_tree_debug_state.h"
namespace cc {
// IMPORTANT: new fields must be added to Equal() and Unite()
LayerTreeDebugState::LayerTreeDebugState()
: show_fps_counter(false),
show_debug_borders(false),
show_layout_shift_regions(false),
show_paint_rects(false),
show_property_changed_rects(false),
show_surface_damage_rects(false),
show_screen_space_rects(false),
show_touch_event_handler_rects(false),
show_wheel_event_handler_rects(false),
show_scroll_event_handler_rects(false),
show_non_fast_scrollable_rects(false),
show_main_thread_scrolling_reason_rects(false),
show_layer_animation_bounds_rects(false),
slow_down_raster_scale_factor(0),
rasterize_only_visible_content(false),
highlight_non_lcd_text_layers(false),
show_hit_test_borders(false),
record_rendering_stats_(false) {}
LayerTreeDebugState::LayerTreeDebugState() = default;
LayerTreeDebugState::LayerTreeDebugState(const LayerTreeDebugState& other) =
default;
......@@ -41,11 +22,11 @@ bool LayerTreeDebugState::RecordRenderingStats() const {
return record_rendering_stats_;
}
bool LayerTreeDebugState::ShowHudInfo() const {
return show_fps_counter || ShowHudRects();
bool LayerTreeDebugState::ShouldCreateHudLayer() const {
return show_fps_counter || ShowDebugRects() || show_web_vital_metrics;
}
bool LayerTreeDebugState::ShowHudRects() const {
bool LayerTreeDebugState::ShowDebugRects() const {
return show_paint_rects || show_property_changed_rects ||
show_surface_damage_rects || show_screen_space_rects ||
show_touch_event_handler_rects || show_wheel_event_handler_rects ||
......@@ -58,6 +39,10 @@ bool LayerTreeDebugState::ShowMemoryStats() const {
return show_fps_counter;
}
bool LayerTreeDebugState::ShouldDrawHudInfo() const {
return show_fps_counter || show_web_vital_metrics;
}
bool LayerTreeDebugState::Equal(const LayerTreeDebugState& a,
const LayerTreeDebugState& b) {
return (
......@@ -80,6 +65,7 @@ bool LayerTreeDebugState::Equal(const LayerTreeDebugState& a,
a.rasterize_only_visible_content == b.rasterize_only_visible_content &&
a.highlight_non_lcd_text_layers == b.highlight_non_lcd_text_layers &&
a.show_hit_test_borders == b.show_hit_test_borders &&
a.show_web_vital_metrics == b.show_web_vital_metrics &&
a.record_rendering_stats_ == b.record_rendering_stats_);
}
......@@ -110,6 +96,8 @@ LayerTreeDebugState LayerTreeDebugState::Unite(const LayerTreeDebugState& a,
r.show_hit_test_borders |= b.show_hit_test_borders;
r.show_web_vital_metrics |= b.show_web_vital_metrics;
r.record_rendering_stats_ |= b.record_rendering_stats_;
return r;
......
......@@ -29,40 +29,48 @@ class CC_DEBUG_EXPORT LayerTreeDebugState {
LayerTreeDebugState(const LayerTreeDebugState& other);
~LayerTreeDebugState();
bool show_fps_counter;
DebugBorderTypes show_debug_borders;
bool show_layout_shift_regions;
bool show_paint_rects;
bool show_property_changed_rects;
bool show_surface_damage_rects;
bool show_screen_space_rects;
bool show_touch_event_handler_rects;
bool show_wheel_event_handler_rects;
bool show_scroll_event_handler_rects;
bool show_non_fast_scrollable_rects;
bool show_main_thread_scrolling_reason_rects;
bool show_layer_animation_bounds_rects;
int slow_down_raster_scale_factor;
bool rasterize_only_visible_content;
bool highlight_non_lcd_text_layers;
bool show_hit_test_borders;
bool show_fps_counter = false;
DebugBorderTypes show_debug_borders = false;
bool show_layout_shift_regions = false;
bool show_paint_rects = false;
bool show_property_changed_rects = false;
bool show_surface_damage_rects = false;
bool show_screen_space_rects = false;
bool show_touch_event_handler_rects = false;
bool show_wheel_event_handler_rects = false;
bool show_scroll_event_handler_rects = false;
bool show_non_fast_scrollable_rects = false;
bool show_main_thread_scrolling_reason_rects = false;
bool show_layer_animation_bounds_rects = false;
int slow_down_raster_scale_factor = 0;
bool rasterize_only_visible_content = false;
bool highlight_non_lcd_text_layers = false;
bool show_hit_test_borders = false;
// This is part of the feature to show performance metrics on HUD. This
// particular flag is set only in Blink.
bool show_web_vital_metrics = false;
void SetRecordRenderingStats(bool enabled);
bool RecordRenderingStats() const;
bool ShowHudInfo() const;
bool ShowHudRects() const;
// HUD layer is responsible for drawing debug rects as well as displaying HUD
// overlay. This function checks if a HUD layer should be created for any of
// these situations.
bool ShouldCreateHudLayer() const;
bool ShowDebugRects() const;
bool ShowMemoryStats() const;
bool ShouldDrawHudInfo() const;
static bool Equal(const LayerTreeDebugState& a, const LayerTreeDebugState& b);
static LayerTreeDebugState Unite(const LayerTreeDebugState& a,
const LayerTreeDebugState& b);
private:
bool record_rendering_stats_;
bool record_rendering_stats_ = false;
};
} // namespace cc
......
......@@ -5,6 +5,7 @@
#include "cc/layers/heads_up_display_layer.h"
#include <algorithm>
#include <vector>
#include "base/trace_event/trace_event.h"
#include "cc/layers/heads_up_display_layer_impl.h"
......@@ -37,7 +38,7 @@ void HeadsUpDisplayLayer::UpdateLocationAndSize(
gfx::Size bounds;
if (layer_tree_host()->GetDebugState().ShowHudRects()) {
if (layer_tree_host()->GetDebugState().ShowDebugRects()) {
bounds = device_viewport_in_layout_pixels;
} else {
// If the HUD is not displaying full-viewport rects (e.g., it is showing the
......
......@@ -564,26 +564,35 @@ void HeadsUpDisplayLayerImpl::DrawHudContents(PaintCanvas* canvas) {
canvas->save();
canvas->scale(internal_contents_scale_, internal_contents_scale_);
if (debug_state.ShowHudRects()) {
if (debug_state.ShowDebugRects()) {
DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history());
if (IsAnimatingHUDContents()) {
layer_tree_impl()->SetNeedsRedraw();
}
}
if (!debug_state.show_fps_counter) {
if (!debug_state.ShouldDrawHudInfo()) {
canvas->restore();
return;
}
SkRect area = DrawFrameThroughputDisplay(
canvas, layer_tree_impl()->dropped_frame_counter(), 0, 0);
area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(),
std::max<SkScalar>(area.width(), 150));
SkRect area;
if (debug_state.show_fps_counter) {
area = DrawFrameThroughputDisplay(
canvas, layer_tree_impl()->dropped_frame_counter(), 0, 0);
area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(),
std::max<SkScalar>(area.width(), 150));
}
if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used) {
area = DrawMemoryDisplay(canvas, 0, area.bottom(),
std::max<SkScalar>(area.width(), 150));
}
if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used)
DrawMemoryDisplay(canvas, 0, area.bottom(),
std::max<SkScalar>(area.width(), 150));
if (debug_state.show_web_vital_metrics) {
area = DrawWebVitalMetrics(canvas, 0, area.bottom(),
std::max<SkScalar>(area.width(), 150));
}
canvas->restore();
}
......@@ -1022,6 +1031,35 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects(
}
}
SkRect HeadsUpDisplayLayerImpl::DrawWebVitalMetrics(PaintCanvas* canvas,
int right,
int top,
int width) const {
std::string loading_status = "-";
// TODO(weiliangc): Update loading status with actual number.
const int kPadding = 4;
const int kTitleFontHeight = 13;
const int kFontHeight = 12;
const int height = kTitleFontHeight + kFontHeight + 3 * kPadding;
const int left = 0;
const SkRect area = SkRect::MakeXYWH(left, top, width, height);
PaintFlags flags;
DrawGraphBackground(canvas, &flags, area);
SkPoint metrics_pos = SkPoint::Make(left + width - kPadding,
top + 2 * kFontHeight + 2 * kPadding);
flags.setColor(DebugColors::HUDTitleColor());
DrawText(canvas, flags, "Load time", TextAlign::kLeft, kTitleFontHeight,
left + kPadding, top + kFontHeight + kPadding);
DrawText(canvas, flags, loading_status, TextAlign::kRight, kFontHeight,
metrics_pos);
return area;
}
const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
return "cc::HeadsUpDisplayLayerImpl";
}
......
......@@ -127,6 +127,11 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
void DrawDebugRects(PaintCanvas* canvas,
DebugRectHistory* debug_rect_history);
SkRect DrawWebVitalMetrics(PaintCanvas* canvas,
int right,
int top,
int width) const;
ResourcePool::InUsePoolResource in_flight_resource_;
std::unique_ptr<ResourcePool> pool_;
viz::DrawQuad* current_quad_ = nullptr;
......
......@@ -97,5 +97,22 @@ class HeadsUpDisplaySizeWithFPS : public LayerTreeTest {
SINGLE_AND_MULTI_THREAD_TEST_F(HeadsUpDisplaySizeWithFPS);
class HeadsUpDisplaySizeWithMetrics : public LayerTreeTest {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->initial_debug_state.show_web_vital_metrics = true;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
ASSERT_TRUE(layer_tree_host()->hud_layer());
EXPECT_EQ(gfx::Size(256, 256), layer_tree_host()->hud_layer()->bounds());
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(HeadsUpDisplaySizeWithMetrics);
} // namespace
} // namespace cc
......@@ -804,7 +804,7 @@ bool LayerTreeHost::DoUpdateLayers() {
TRACE_EVENT1("cc,benchmark", "LayerTreeHost::DoUpdateLayers",
"source_frame_number", SourceFrameNumber());
UpdateHudLayer(debug_state_.ShowHudInfo());
UpdateHudLayer(debug_state_.ShouldCreateHudLayer());
// In layer lists mode, the cc property trees are built directly and do not
// need to be built here.
......
......@@ -2429,7 +2429,7 @@ viz::CompositorFrame LayerTreeHostImpl::GenerateCompositorFrame(
memory_history_->SaveEntry(tile_manager_.memory_stats_from_last_assign());
if (debug_state_.ShowHudRects()) {
if (debug_state_.ShowDebugRects()) {
debug_rect_history_->SaveDebugRectsForCurrentFrame(
active_tree(), active_tree_->hud_layer(), *frame->render_surface_list,
debug_state_);
......
......@@ -358,6 +358,9 @@ cc::LayerTreeSettings GenerateLayerTreeSettings(
cmd.HasSwitch(cc::switches::kShowScreenSpaceRects);
settings.initial_debug_state.highlight_non_lcd_text_layers =
cmd.HasSwitch(cc::switches::kHighlightNonLCDTextLayers);
settings.initial_debug_state.show_web_vital_metrics =
base::FeatureList::IsEnabled(
::features::kHudDisplayForPerformanceMetrics);
settings.initial_debug_state.SetRecordRenderingStats(
cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
......
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