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
6
7namespace flutter {
8
10 : refresh_rate_updater_(updater), start_(fml::TimePoint::Now()) {
12 laps_.resize(kMaxSamples, delta);
13}
14
15Stopwatch::~Stopwatch() = default;
16
18 fml::Milliseconds frame_budget)
19 : Stopwatch(fixed_delegate_), fixed_delegate_(frame_budget) {}
20
22 fml::Milliseconds fixed_frame_budget)
23 : fixed_frame_budget_(fixed_frame_budget) {}
24
26 start_ = fml::TimePoint::Now();
27}
28
31}
32
34 current_sample_ = (current_sample_ + 1) % kMaxSamples;
35 laps_[current_sample_] = delta;
36}
37
39 return laps_[current_sample_];
40}
41
42const fml::TimeDelta& Stopwatch::GetLap(size_t index) const {
43 return laps_[index];
44}
45
47 return laps_.size();
48}
49
51 return current_sample_;
52}
53
54double StopwatchVisualizer::UnitFrameInterval(double raster_time_ms) const {
55 return raster_time_ms / frame_budget_.count();
56}
57
58double StopwatchVisualizer::UnitHeight(double raster_time_ms,
59 double max_unit_interval) const {
60 double unit_height = UnitFrameInterval(raster_time_ms) / max_unit_interval;
61 if (unit_height > 1.0) {
62 unit_height = 1.0;
63 }
64 return unit_height;
65}
66
68 fml::TimeDelta max_delta;
69 for (size_t i = 0; i < kMaxSamples; i++) {
70 if (laps_[i] > max_delta) {
71 max_delta = laps_[i];
72 }
73 }
74 return max_delta;
75}
76
78 fml::TimeDelta sum; // default to 0
79 for (size_t i = 0; i < kMaxSamples; i++) {
80 sum = sum + laps_[i];
81 }
82 return sum / kMaxSamples;
83}
84
86 return refresh_rate_updater_.GetFrameBudget();
87}
88
89fml::Milliseconds FixedRefreshRateUpdater::GetFrameBudget() const {
90 return fixed_frame_budget_;
91}
92
93} // namespace flutter
FixedRefreshRateStopwatch(fml::Milliseconds fixed_frame_budget=fml::kDefaultFrameBudget)
Definition stopwatch.cc:17
FixedRefreshRateUpdater(fml::Milliseconds fixed_frame_budget=fml::kDefaultFrameBudget)
Definition stopwatch.cc:21
The refresh rate interface for Stopwatch.
Definition stopwatch.h:23
virtual fml::Milliseconds GetFrameBudget() const =0
const fml::TimeDelta & GetLap(size_t index) const
Definition stopwatch.cc:42
const fml::TimeDelta & LastLap() const
Definition stopwatch.cc:38
fml::Milliseconds GetFrameBudget() const
All places which want to get frame_budget should call this function.
Definition stopwatch.cc:85
fml::TimeDelta MaxDelta() const
Definition stopwatch.cc:67
size_t GetLapsCount() const
Return a reference to all the laps.
Definition stopwatch.cc:46
size_t GetCurrentSample() const
Definition stopwatch.cc:50
void SetLapTime(const fml::TimeDelta &delta)
Definition stopwatch.cc:33
static const size_t kMaxSamples
Definition stopwatch.h:20
Stopwatch(const RefreshRateUpdater &updater)
Definition stopwatch.cc:9
fml::TimeDelta AverageDelta() const
Definition stopwatch.cc:77
double UnitHeight(double time_ms, double max_height) const
Converts a raster time to a unit height.
Definition stopwatch.cc:58
fml::Milliseconds frame_budget_
Definition stopwatch.h:126
double UnitFrameInterval(double time_ms) const
Converts a raster time to a unit interval.
Definition stopwatch.cc:54
static constexpr TimeDelta Zero()
Definition time_delta.h:33
static TimePoint Now()
Definition time_point.cc:49
std::chrono::duration< double, std::milli > Milliseconds
Definition time_delta.h:18
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition timing.h:15