Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
stopwatch.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/flow/stopwatch.h"
6
7namespace flutter {
8
9static const size_t kMaxSamples = 120;
10
12 : refresh_rate_updater_(updater), start_(fml::TimePoint::Now()) {
14 laps_.resize(kMaxSamples, delta);
15}
16
17Stopwatch::~Stopwatch() = default;
18
20 fml::Milliseconds frame_budget)
21 : Stopwatch(fixed_delegate_), fixed_delegate_(frame_budget) {}
22
24 fml::Milliseconds fixed_frame_budget)
25 : fixed_frame_budget_(fixed_frame_budget) {}
26
28 start_ = fml::TimePoint::Now();
29 current_sample_ = (current_sample_ + 1) % kMaxSamples;
30}
31
33 laps_[current_sample_] = fml::TimePoint::Now() - start_;
34}
35
37 current_sample_ = (current_sample_ + 1) % kMaxSamples;
38 laps_[current_sample_] = delta;
39}
40
42 return laps_[(current_sample_ - 1) % kMaxSamples];
43}
44
45const fml::TimeDelta& Stopwatch::GetLap(size_t index) const {
46 return laps_[index];
47}
48
50 return laps_.size();
51}
52
54 return current_sample_;
55}
56
57double StopwatchVisualizer::UnitFrameInterval(double raster_time_ms) const {
58 return raster_time_ms / frame_budget_.count();
59}
60
61double StopwatchVisualizer::UnitHeight(double raster_time_ms,
62 double max_unit_interval) const {
63 double unit_height = UnitFrameInterval(raster_time_ms) / max_unit_interval;
64 if (unit_height > 1.0) {
65 unit_height = 1.0;
66 }
67 return unit_height;
68}
69
71 fml::TimeDelta max_delta;
72 for (size_t i = 0; i < kMaxSamples; i++) {
73 if (laps_[i] > max_delta) {
74 max_delta = laps_[i];
75 }
76 }
77 return max_delta;
78}
79
81 fml::TimeDelta sum; // default to 0
82 for (size_t i = 0; i < kMaxSamples; i++) {
83 sum = sum + laps_[i];
84 }
85 return sum / kMaxSamples;
86}
87
89 return refresh_rate_updater_.GetFrameBudget();
90}
91
93 return fixed_frame_budget_;
94}
95
96} // namespace flutter
FixedRefreshRateStopwatch(fml::Milliseconds fixed_frame_budget=fml::kDefaultFrameBudget)
Definition stopwatch.cc:19
fml::Milliseconds GetFrameBudget() const override
Definition stopwatch.cc:92
FixedRefreshRateUpdater(fml::Milliseconds fixed_frame_budget=fml::kDefaultFrameBudget)
Definition stopwatch.cc:23
double UnitHeight(double time_ms, double max_height) const
Converts a raster time to a unit height.
Definition stopwatch.cc:61
fml::Milliseconds frame_budget_
Definition stopwatch.h:123
double UnitFrameInterval(double time_ms) const
Converts a raster time to a unit interval.
Definition stopwatch.cc:57
The refresh rate interface for Stopwatch.
Definition stopwatch.h:20
virtual fml::Milliseconds GetFrameBudget() const =0
const fml::TimeDelta & GetLap(size_t index) const
Definition stopwatch.cc:45
const fml::TimeDelta & LastLap() const
Definition stopwatch.cc:41
fml::Milliseconds GetFrameBudget() const
All places which want to get frame_budget should call this function.
Definition stopwatch.cc:88
fml::TimeDelta MaxDelta() const
Definition stopwatch.cc:70
size_t GetLapsCount() const
Return a reference to all the laps.
Definition stopwatch.cc:49
size_t GetCurrentSample() const
Definition stopwatch.cc:53
void SetLapTime(const fml::TimeDelta &delta)
Definition stopwatch.cc:36
Stopwatch(const RefreshRateUpdater &updater)
Definition stopwatch.cc:11
fml::TimeDelta AverageDelta() const
Definition stopwatch.cc:80
static constexpr TimeDelta Zero()
Definition time_delta.h:33
static TimePoint Now()
Definition time_point.cc:49
static const size_t kMaxSamples
Definition stopwatch.cc:9
std::chrono::duration< double, std::milli > Milliseconds
Definition time_delta.h:18