mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Avg ms/frame instead of FPS in performance overlay (#7443)
Computing FPS from max ms/frame is misleading and we're no longer just using 60 FPS displays.
This commit is contained in:
parent
b7e0527982
commit
5ce5ace6ea
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
class Stopwatch {
|
||||
@ -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;
|
||||
|
||||
@ -43,19 +43,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";
|
||||
DrawStatisticsText(canvas, stream.str(), x + label_x, y + height + label_y);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user