Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
flutter::Stopwatch Class Reference

#include <stopwatch.h>

Inheritance diagram for flutter::Stopwatch:
flutter::FixedRefreshRateStopwatch

Classes

class  RefreshRateUpdater
 The refresh rate interface for Stopwatch. More...
 

Public Member Functions

 Stopwatch (const RefreshRateUpdater &updater)
 
 ~Stopwatch ()
 
const fml::TimeDeltaGetLap (size_t index) const
 
size_t GetLapsCount () const
 Return a reference to all the laps.
 
size_t GetCurrentSample () const
 
const fml::TimeDeltaLastLap () const
 
fml::TimeDelta MaxDelta () const
 
fml::TimeDelta AverageDelta () const
 
void Start ()
 
void Stop ()
 
void SetLapTime (const fml::TimeDelta &delta)
 
fml::Milliseconds GetFrameBudget () const
 All places which want to get frame_budget should call this function.
 

Detailed Description

Definition at line 17 of file stopwatch.h.

Constructor & Destructor Documentation

◆ Stopwatch()

flutter::Stopwatch::Stopwatch ( const RefreshRateUpdater updater)
explicit

The constructor with a updater parameter, it will update frame_budget everytime when GetFrameBudget() is called.

Definition at line 11 of file stopwatch.cc.

12 : refresh_rate_updater_(updater), start_(fml::TimePoint::Now()) {
14 laps_.resize(kMaxSamples, delta);
15}
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

◆ ~Stopwatch()

flutter::Stopwatch::~Stopwatch ( )
default

Member Function Documentation

◆ AverageDelta()

fml::TimeDelta flutter::Stopwatch::AverageDelta ( ) const

Definition at line 80 of file stopwatch.cc.

80 {
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}

◆ GetCurrentSample()

size_t flutter::Stopwatch::GetCurrentSample ( ) const

Definition at line 53 of file stopwatch.cc.

53 {
54 return current_sample_;
55}

◆ GetFrameBudget()

fml::Milliseconds flutter::Stopwatch::GetFrameBudget ( ) const

All places which want to get frame_budget should call this function.

Definition at line 88 of file stopwatch.cc.

88 {
89 return refresh_rate_updater_.GetFrameBudget();
90}
virtual fml::Milliseconds GetFrameBudget() const =0

◆ GetLap()

const fml::TimeDelta & flutter::Stopwatch::GetLap ( size_t  index) const

Definition at line 45 of file stopwatch.cc.

45 {
46 return laps_[index];
47}

◆ GetLapsCount()

size_t flutter::Stopwatch::GetLapsCount ( ) const

Return a reference to all the laps.

Definition at line 49 of file stopwatch.cc.

49 {
50 return laps_.size();
51}

◆ LastLap()

const fml::TimeDelta & flutter::Stopwatch::LastLap ( ) const

Definition at line 41 of file stopwatch.cc.

41 {
42 return laps_[(current_sample_ - 1) % kMaxSamples];
43}

◆ MaxDelta()

fml::TimeDelta flutter::Stopwatch::MaxDelta ( ) const

Definition at line 70 of file stopwatch.cc.

70 {
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}

◆ SetLapTime()

void flutter::Stopwatch::SetLapTime ( const fml::TimeDelta delta)

Definition at line 36 of file stopwatch.cc.

36 {
37 current_sample_ = (current_sample_ + 1) % kMaxSamples;
38 laps_[current_sample_] = delta;
39}

◆ Start()

void flutter::Stopwatch::Start ( )

Definition at line 27 of file stopwatch.cc.

27 {
28 start_ = fml::TimePoint::Now();
29 current_sample_ = (current_sample_ + 1) % kMaxSamples;
30}

◆ Stop()

void flutter::Stopwatch::Stop ( )

Definition at line 32 of file stopwatch.cc.

32 {
33 laps_[current_sample_] = fml::TimePoint::Now() - start_;
34}

The documentation for this class was generated from the following files: