Flutter Engine
 
Loading...
Searching...
No Matches
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.
 

Static Public Attributes

static const size_t kMaxSamples = 120
 

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 9 of file stopwatch.cc.

10 : refresh_rate_updater_(updater), start_(fml::TimePoint::Now()) {
12 laps_.resize(kMaxSamples, delta);
13}
static const size_t kMaxSamples
Definition stopwatch.h:20
static constexpr TimeDelta Zero()
Definition time_delta.h:33
static TimePoint Now()
Definition time_point.cc:49

References kMaxSamples, and fml::TimeDelta::Zero().

◆ ~Stopwatch()

flutter::Stopwatch::~Stopwatch ( )
default

Member Function Documentation

◆ AverageDelta()

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

Definition at line 77 of file stopwatch.cc.

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

References i, and kMaxSamples.

Referenced by flutter::PerformanceOverlayLayer::MakeStatisticsText().

◆ GetCurrentSample()

size_t flutter::Stopwatch::GetCurrentSample ( ) const

Definition at line 50 of file stopwatch.cc.

50 {
51 return current_sample_;
52}

Referenced by flutter::testing::TEST(), flutter::testing::TEST(), and flutter::DlStopwatchVisualizer::Visualize().

◆ GetFrameBudget()

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

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

Definition at line 85 of file stopwatch.cc.

85 {
86 return refresh_rate_updater_.GetFrameBudget();
87}
virtual fml::Milliseconds GetFrameBudget() const =0

References flutter::Stopwatch::RefreshRateUpdater::GetFrameBudget().

Referenced by flutter::StopwatchVisualizer::StopwatchVisualizer(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ GetLap()

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

Definition at line 42 of file stopwatch.cc.

42 {
43 return laps_[index];
44}

Referenced by flutter::testing::TEST(), and flutter::DlStopwatchVisualizer::Visualize().

◆ GetLapsCount()

size_t flutter::Stopwatch::GetLapsCount ( ) const

Return a reference to all the laps.

Definition at line 46 of file stopwatch.cc.

46 {
47 return laps_.size();
48}

Referenced by flutter::testing::TEST(), and flutter::DlStopwatchVisualizer::Visualize().

◆ LastLap()

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

Definition at line 38 of file stopwatch.cc.

38 {
39 return laps_[current_sample_];
40}

Referenced by flutter::DlStopwatchVisualizer::Visualize().

◆ MaxDelta()

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

Definition at line 67 of file stopwatch.cc.

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

References i, and kMaxSamples.

Referenced by flutter::PerformanceOverlayLayer::MakeStatisticsText().

◆ SetLapTime()

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

Definition at line 33 of file stopwatch.cc.

33 {
34 current_sample_ = (current_sample_ + 1) % kMaxSamples;
35 laps_[current_sample_] = delta;
36}

References kMaxSamples.

Referenced by Stop(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ Start()

void flutter::Stopwatch::Start ( )

Definition at line 25 of file stopwatch.cc.

25 {
26 start_ = fml::TimePoint::Now();
27}

References fml::TimePoint::Now().

Referenced by flutter::testing::TEST().

◆ Stop()

void flutter::Stopwatch::Stop ( )

Definition at line 29 of file stopwatch.cc.

29 {
31}
void SetLapTime(const fml::TimeDelta &delta)
Definition stopwatch.cc:33

References fml::TimePoint::Now(), and SetLapTime().

Referenced by flutter::testing::TEST().

Member Data Documentation

◆ kMaxSamples

const size_t flutter::Stopwatch::kMaxSamples = 120
static

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