Skip to content

Commit

Permalink
metrics: Add Smoothness Metrics for HUD Performance Metrics Display
Browse files Browse the repository at this point in the history
For the HUD display of performance metrics, add smoothness as part of
it.

Web Vital metrics is only enabled on Blink. Smoothness metrics could
be enabled on ui/compositor as well.

R=sadrul

Bug: 1149385
Change-Id: I9ac4c5fd36c4c828a2839bbc1ced1049950dc40f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2541577
Commit-Queue: weiliangc <weiliangc@chromium.org>
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830391}
  • Loading branch information
weiliangc authored and Commit Bot committed Nov 24, 2020
1 parent 9143523 commit a2ef183
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cc/debug/layer_tree_debug_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ bool LayerTreeDebugState::RecordRenderingStats() const {
}

bool LayerTreeDebugState::ShouldCreateHudLayer() const {
return show_fps_counter || ShowDebugRects() || show_web_vital_metrics;
return show_fps_counter || ShowDebugRects() || show_web_vital_metrics ||
show_smoothness_metrics;
}

bool LayerTreeDebugState::ShowDebugRects() const {
Expand All @@ -40,7 +41,7 @@ bool LayerTreeDebugState::ShowMemoryStats() const {
}

bool LayerTreeDebugState::ShouldDrawHudInfo() const {
return show_fps_counter || show_web_vital_metrics;
return show_fps_counter || show_web_vital_metrics || show_smoothness_metrics;
}

bool LayerTreeDebugState::Equal(const LayerTreeDebugState& a,
Expand Down
1 change: 1 addition & 0 deletions cc/debug/layer_tree_debug_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CC_DEBUG_EXPORT LayerTreeDebugState {
// 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;
bool show_smoothness_metrics = false;

void SetRecordRenderingStats(bool enabled);
bool RecordRenderingStats() const;
Expand Down
37 changes: 37 additions & 0 deletions cc/layers/heads_up_display_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ void HeadsUpDisplayLayerImpl::DrawHudContents(PaintCanvas* canvas) {
std::max<SkScalar>(area.width(), 150));
}

if (debug_state.show_smoothness_metrics) {
area = DrawSmoothnessMetrics(canvas, 0, area.bottom(),
std::max<SkScalar>(area.width(), 150));
}

canvas->restore();
}

Expand Down Expand Up @@ -1118,6 +1123,38 @@ SkRect HeadsUpDisplayLayerImpl::DrawWebVitalMetrics(PaintCanvas* canvas,
return area;
}

SkRect HeadsUpDisplayLayerImpl::DrawSmoothnessMetrics(PaintCanvas* canvas,
int right,
int top,
int width) const {
std::string avg_smoothness = "-";
double smoothness_data = layer_tree_impl()
->dropped_frame_counter()
->GetMostRecentAverageSmoothness();
if (smoothness_data >= 0.f)
avg_smoothness = ToStringTwoDecimalPrecision(smoothness_data) + " %";

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, "Average Dropped Frame:", TextAlign::kLeft,
kTitleFontHeight, left + kPadding, top + kFontHeight + kPadding);
DrawText(canvas, flags, avg_smoothness, TextAlign::kRight, kFontHeight,
metrics_pos);
return area;
}

const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
return "cc::HeadsUpDisplayLayerImpl";
}
Expand Down
5 changes: 5 additions & 0 deletions cc/layers/heads_up_display_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
int top,
int width) const;

SkRect DrawSmoothnessMetrics(PaintCanvas* canvas,
int right,
int top,
int width) const;

ResourcePool::InUsePoolResource in_flight_resource_;
std::unique_ptr<ResourcePool> pool_;
viz::DrawQuad* current_quad_ = nullptr;
Expand Down
7 changes: 7 additions & 0 deletions cc/metrics/dropped_frame_counter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ void DroppedFrameCounter::ReportFrames() {
}
}

double DroppedFrameCounter::GetMostRecentAverageSmoothness() const {
if (ukm_smoothness_data_)
return ukm_smoothness_data_->data.avg_smoothness;

return -1.f;
}

void DroppedFrameCounter::SetUkmSmoothnessDestination(
UkmSmoothnessDataShared* smoothness_data) {
ukm_smoothness_data_ = smoothness_data;
Expand Down
2 changes: 2 additions & 0 deletions cc/metrics/dropped_frame_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class CC_EXPORT DroppedFrameCounter {

uint32_t GetAverageThroughput() const;

double GetMostRecentAverageSmoothness() const;

typedef base::RingBuffer<FrameState, 180> RingBufferType;
RingBufferType::Iterator begin() const { return ring_buffer_.Begin(); }
RingBufferType::Iterator end() const { return ring_buffer_.End(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ cc::LayerTreeSettings GenerateLayerTreeSettings(
settings.initial_debug_state.show_web_vital_metrics =
base::FeatureList::IsEnabled(
::features::kHudDisplayForPerformanceMetrics);
settings.initial_debug_state.show_smoothness_metrics =
base::FeatureList::IsEnabled(
::features::kHudDisplayForPerformanceMetrics);

settings.initial_debug_state.SetRecordRenderingStats(
cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
Expand Down

0 comments on commit a2ef183

Please sign in to comment.