Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flow/instrumentation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ fml::TimeDelta Stopwatch::MaxDelta() const {
return max_delta;
}

fml::TimeDelta Stopwatch::AverageDelta() const {
fml::TimeDelta sum; // default to 0
for (size_t i = 0; i < kMaxSamples; i++) {
sum = sum + laps_[i];
}
return sum / kMaxSamples;
}

// Initialize the SkSurface for drawing into. Draws the base background and any
// timing data from before the initial Visualize() call.
void Stopwatch::InitVisualizeSurface(const SkRect& rect) const {
Expand Down
4 changes: 4 additions & 0 deletions flow/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace flow {

// DEPRECATED
// The frame per second FPS could be different than 60 (e.g., 120).
static const double kOneFrameMS = 1e3 / 60.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there consumers that still exist that use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used for drawing 3 horizontal lines: 16ms, 32ms, 48ms (https://github.com/flutter/engine/blob/master/flow/instrumentation.cc#L92)

Eventually, we should remove this altogether and get the refresh rate from #7002

I feel that it's better to do it in another PR to keep each one small and focused.


class Stopwatch {
Expand All @@ -28,6 +30,8 @@ class Stopwatch {

fml::TimeDelta MaxDelta() const;

fml::TimeDelta AverageDelta() const;

void InitVisualizeSurface(const SkRect& rect) const;

void Visualize(SkCanvas& canvas, const SkRect& rect) const;
Expand Down
15 changes: 5 additions & 10 deletions flow/layers/performance_overlay_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,14 @@ void VisualizeStopWatch(SkCanvas& canvas,
}

if (show_labels) {
double ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF();
double fps;
if (ms_per_frame < kOneFrameMS) {
fps = 1e3 / kOneFrameMS;
} else {
fps = 1e3 / ms_per_frame;
}

double max_ms_per_frame = stopwatch.MaxDelta().ToMillisecondsF();
double average_ms_per_frame = stopwatch.AverageDelta().ToMillisecondsF();
std::stringstream stream;
stream.setf(std::ios::fixed | std::ios::showpoint);
stream << std::setprecision(1);
stream << label_prefix << " " << fps << " fps " << ms_per_frame
<< "ms/frame";
stream << label_prefix << " "
<< "max " << max_ms_per_frame << " ms/frame, "
<< "avg " << average_ms_per_frame << " ms/frame";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a little conflicted about showing the average...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are often a few big spikes to make the max very different from the average (e.g., max is 300ms while the average is 11ms). One way of thinking is that average is more about the power consumption while max is more about janks.

DrawStatisticsText(canvas, stream.str(), x + label_x, y + height + label_y);
}
}
Expand Down