Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | List of all members
flutter::FrameTimingsRecorder Class Reference

#include <frame_timings.h>

Public Types

enum class  State : uint32_t {
  kUninitialized , kVsync , kBuildStart , kBuildEnd ,
  kRasterStart , kRasterEnd
}
 

Public Member Functions

 FrameTimingsRecorder ()
 Default constructor, initializes the recorder with State::kUninitialized. More...
 
 FrameTimingsRecorder (uint64_t frame_number)
 Constructor with a pre-populated frame number. More...
 
 ~FrameTimingsRecorder ()
 
fml::TimePoint GetVsyncStartTime () const
 Timestamp of the vsync signal. More...
 
fml::TimePoint GetVsyncTargetTime () const
 
fml::TimePoint GetBuildStartTime () const
 Timestamp of when the frame building started. More...
 
fml::TimePoint GetBuildEndTime () const
 Timestamp of when the frame was finished building. More...
 
fml::TimePoint GetRasterStartTime () const
 Timestamp of when the frame rasterization started. More...
 
fml::TimePoint GetRasterEndTime () const
 Timestamp of when the frame rasterization finished. More...
 
fml::TimePoint GetRasterEndWallTime () const
 Timestamp of when the frame rasterization is complete in wall-time. More...
 
fml::TimeDelta GetBuildDuration () const
 Duration of the frame build time. More...
 
size_t GetLayerCacheCount () const
 Count of the layer cache entries. More...
 
size_t GetLayerCacheBytes () const
 Total Bytes in all layer cache entries. More...
 
size_t GetPictureCacheCount () const
 Count of the picture cache entries. More...
 
size_t GetPictureCacheBytes () const
 Total Bytes in all picture cache entries. More...
 
void RecordVsync (fml::TimePoint vsync_start, fml::TimePoint vsync_target)
 Records a vsync event. More...
 
void RecordBuildStart (fml::TimePoint build_start)
 Records a build start event. More...
 
void RecordBuildEnd (fml::TimePoint build_end)
 Records a build end event. More...
 
void RecordRasterStart (fml::TimePoint raster_start)
 Records a raster start event. More...
 
std::unique_ptr< FrameTimingsRecorderCloneUntil (State state)
 Clones the recorder until (and including) the specified state. More...
 
FrameTiming RecordRasterEnd (const RasterCache *cache=nullptr)
 
uint64_t GetFrameNumber () const
 
const char * GetFrameNumberTraceArg () const
 Returns the frame number in a fml tracing friendly format. More...
 
FrameTiming GetRecordedTime () const
 Returns the recorded time from when RecordRasterEnd is called. More...
 
void AssertInState (State state) const
 

Detailed Description

Records timestamps for various phases of a frame rendering process.

Recorder is created on vsync and destroyed after the rasterization of the frame. This class is thread safe and doesn't require additional synchronization.

Definition at line 30 of file frame_timings.h.

Member Enumeration Documentation

◆ State

enum class flutter::FrameTimingsRecorder::State : uint32_t
strong

Various states that the recorder can be in. When created the recorder is in an unitialized state and transtions in sequential order of the states.

Enumerator
kUninitialized 
kVsync 
kBuildStart 
kBuildEnd 
kRasterStart 
kRasterEnd 

Definition at line 35 of file frame_timings.h.

35 : uint32_t {
37 kVsync,
38 kBuildStart,
39 kBuildEnd,
40 kRasterStart,
41 kRasterEnd,
42 };

Constructor & Destructor Documentation

◆ FrameTimingsRecorder() [1/2]

flutter::FrameTimingsRecorder::FrameTimingsRecorder ( )

Default constructor, initializes the recorder with State::kUninitialized.

Definition at line 43 of file frame_timings.cc.

44 : frame_number_(frame_number_gen_++),
45 frame_number_trace_arg_val_(std::to_string(frame_number_)) {}
static SkString to_string(int n)
Definition: nanobench.cpp:119

◆ FrameTimingsRecorder() [2/2]

flutter::FrameTimingsRecorder::FrameTimingsRecorder ( uint64_t  frame_number)
explicit

Constructor with a pre-populated frame number.

Definition at line 47 of file frame_timings.cc.

48 : frame_number_(frame_number),
49 frame_number_trace_arg_val_(std::to_string(frame_number_)) {}

◆ ~FrameTimingsRecorder()

flutter::FrameTimingsRecorder::~FrameTimingsRecorder ( )
default

Member Function Documentation

◆ AssertInState()

void flutter::FrameTimingsRecorder::AssertInState ( State  state) const

Asserts in unopt builds that the recorder is current at the specified state.

Instead of adding a GetState method and asserting on the result, this method prevents other logic from relying on the state.

In release builds, this call is a no-op.

Definition at line 284 of file frame_timings.cc.

284 {
285 FML_DCHECK(state_ == state) << "Expected state " << StateToString(state)
286 << ", actual state " << StateToString(state_);
287}
AtkStateType state
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ CloneUntil()

std::unique_ptr< FrameTimingsRecorder > flutter::FrameTimingsRecorder::CloneUntil ( State  state)

Clones the recorder until (and including) the specified state.

Definition at line 239 of file frame_timings.cc.

240 {
241 std::scoped_lock state_lock(state_mutex_);
242 std::unique_ptr<FrameTimingsRecorder> recorder =
243 std::make_unique<FrameTimingsRecorder>(frame_number_);
244 FML_DCHECK(state_ >= state);
245 recorder->state_ = state;
246
247 if (state >= State::kVsync) {
248 recorder->vsync_start_ = vsync_start_;
249 recorder->vsync_target_ = vsync_target_;
250 }
251
252 if (state >= State::kBuildStart) {
253 recorder->build_start_ = build_start_;
254 }
255
256 if (state >= State::kBuildEnd) {
257 recorder->build_end_ = build_end_;
258 }
259
260 if (state >= State::kRasterStart) {
261 recorder->raster_start_ = raster_start_;
262 }
263
264 if (state >= State::kRasterEnd) {
265 recorder->raster_end_ = raster_end_;
266 recorder->raster_end_wall_time_ = raster_end_wall_time_;
267 recorder->layer_cache_count_ = layer_cache_count_;
268 recorder->layer_cache_bytes_ = layer_cache_bytes_;
269 recorder->picture_cache_count_ = picture_cache_count_;
270 recorder->picture_cache_bytes_ = picture_cache_bytes_;
271 }
272
273 return recorder;
274}

◆ GetBuildDuration()

fml::TimeDelta flutter::FrameTimingsRecorder::GetBuildDuration ( ) const

Duration of the frame build time.

Definition at line 95 of file frame_timings.cc.

95 {
96 std::scoped_lock state_lock(state_mutex_);
98 return build_end_ - build_start_;
99}

◆ GetBuildEndTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetBuildEndTime ( ) const

Timestamp of when the frame was finished building.

Definition at line 71 of file frame_timings.cc.

71 {
72 std::scoped_lock state_lock(state_mutex_);
74 return build_end_;
75}

◆ GetBuildStartTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetBuildStartTime ( ) const

Timestamp of when the frame building started.

Definition at line 65 of file frame_timings.cc.

65 {
66 std::scoped_lock state_lock(state_mutex_);
68 return build_start_;
69}

◆ GetFrameNumber()

uint64_t flutter::FrameTimingsRecorder::GetFrameNumber ( ) const

Returns the frame number. Frame number is unique per frame and a frame built earlier will have a frame number less than a frame that has been built at a later point of time.

Definition at line 276 of file frame_timings.cc.

276 {
277 return frame_number_;
278}

◆ GetFrameNumberTraceArg()

const char * flutter::FrameTimingsRecorder::GetFrameNumberTraceArg ( ) const

Returns the frame number in a fml tracing friendly format.

Definition at line 280 of file frame_timings.cc.

280 {
281 return frame_number_trace_arg_val_.c_str();
282}

◆ GetLayerCacheBytes()

size_t flutter::FrameTimingsRecorder::GetLayerCacheBytes ( ) const

Total Bytes in all layer cache entries.

Total bytes in all layer cache entries.

Definition at line 109 of file frame_timings.cc.

109 {
110 std::scoped_lock state_lock(state_mutex_);
111 FML_DCHECK(state_ >= State::kRasterEnd);
112 return layer_cache_bytes_;
113}

◆ GetLayerCacheCount()

size_t flutter::FrameTimingsRecorder::GetLayerCacheCount ( ) const

Count of the layer cache entries.

Definition at line 102 of file frame_timings.cc.

102 {
103 std::scoped_lock state_lock(state_mutex_);
104 FML_DCHECK(state_ >= State::kRasterEnd);
105 return layer_cache_count_;
106}

◆ GetPictureCacheBytes()

size_t flutter::FrameTimingsRecorder::GetPictureCacheBytes ( ) const

Total Bytes in all picture cache entries.

Total bytes in all picture cache entries.

Definition at line 123 of file frame_timings.cc.

123 {
124 std::scoped_lock state_lock(state_mutex_);
125 FML_DCHECK(state_ >= State::kRasterEnd);
126 return picture_cache_bytes_;
127}

◆ GetPictureCacheCount()

size_t flutter::FrameTimingsRecorder::GetPictureCacheCount ( ) const

Count of the picture cache entries.

Definition at line 116 of file frame_timings.cc.

116 {
117 std::scoped_lock state_lock(state_mutex_);
118 FML_DCHECK(state_ >= State::kRasterEnd);
119 return picture_cache_count_;
120}

◆ GetRasterEndTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetRasterEndTime ( ) const

Timestamp of when the frame rasterization finished.

Definition at line 83 of file frame_timings.cc.

83 {
84 std::scoped_lock state_lock(state_mutex_);
86 return raster_end_;
87}

◆ GetRasterEndWallTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetRasterEndWallTime ( ) const

Timestamp of when the frame rasterization is complete in wall-time.

Definition at line 89 of file frame_timings.cc.

89 {
90 std::scoped_lock state_lock(state_mutex_);
92 return raster_end_wall_time_;
93}

◆ GetRasterStartTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetRasterStartTime ( ) const

Timestamp of when the frame rasterization started.

Definition at line 77 of file frame_timings.cc.

77 {
78 std::scoped_lock state_lock(state_mutex_);
80 return raster_start_;
81}

◆ GetRecordedTime()

FrameTiming flutter::FrameTimingsRecorder::GetRecordedTime ( ) const

Returns the recorded time from when RecordRasterEnd is called.

Definition at line 233 of file frame_timings.cc.

233 {
234 std::scoped_lock state_lock(state_mutex_);
235 FML_DCHECK(state_ == State::kRasterEnd);
236 return timing_;
237}

◆ GetVsyncStartTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetVsyncStartTime ( ) const

Timestamp of the vsync signal.

Definition at line 53 of file frame_timings.cc.

53 {
54 std::scoped_lock state_lock(state_mutex_);
55 FML_DCHECK(state_ >= State::kVsync);
56 return vsync_start_;
57}

◆ GetVsyncTargetTime()

fml::TimePoint flutter::FrameTimingsRecorder::GetVsyncTargetTime ( ) const

Timestamp of when the frame was targeted to be presented.

This is typically the next vsync signal timestamp.

Definition at line 59 of file frame_timings.cc.

59 {
60 std::scoped_lock state_lock(state_mutex_);
61 FML_DCHECK(state_ >= State::kVsync);
62 return vsync_target_;
63}

◆ RecordBuildEnd()

void flutter::FrameTimingsRecorder::RecordBuildEnd ( fml::TimePoint  build_end)

Records a build end event.

Definition at line 142 of file frame_timings.cc.

142 {
143 fml::Status status = RecordBuildEndImpl(build_end);
144 FML_DCHECK(status.ok());
145 (void)status;
146}
bool ok() const
Definition: status.h:71

◆ RecordBuildStart()

void flutter::FrameTimingsRecorder::RecordBuildStart ( fml::TimePoint  build_start)

Records a build start event.

Definition at line 136 of file frame_timings.cc.

136 {
137 fml::Status status = RecordBuildStartImpl(build_start);
138 FML_DCHECK(status.ok());
139 (void)status;
140}

◆ RecordRasterEnd()

FrameTiming flutter::FrameTimingsRecorder::RecordRasterEnd ( const RasterCache cache = nullptr)

Records a raster end event, and builds a FrameTiming that summarizes all the events. This summary is sent to the framework.

Definition at line 202 of file frame_timings.cc.

202 {
203 std::scoped_lock state_lock(state_mutex_);
205 state_ = State::kRasterEnd;
206 raster_end_ = fml::TimePoint::Now();
207 raster_end_wall_time_ = fml::TimePoint::CurrentWallTime();
208 if (cache) {
209#if !SLIMPELLER
210 const RasterCacheMetrics& layer_metrics = cache->layer_metrics();
211 const RasterCacheMetrics& picture_metrics = cache->picture_metrics();
212 layer_cache_count_ = layer_metrics.total_count();
213 layer_cache_bytes_ = layer_metrics.total_bytes();
214 picture_cache_count_ = picture_metrics.total_count();
215 picture_cache_bytes_ = picture_metrics.total_bytes();
216#endif // !SLIMPELLER
217 } else {
218 layer_cache_count_ = layer_cache_bytes_ = picture_cache_count_ =
219 picture_cache_bytes_ = 0;
220 }
221 timing_.Set(FrameTiming::kVsyncStart, vsync_start_);
222 timing_.Set(FrameTiming::kBuildStart, build_start_);
223 timing_.Set(FrameTiming::kBuildFinish, build_end_);
224 timing_.Set(FrameTiming::kRasterStart, raster_start_);
225 timing_.Set(FrameTiming::kRasterFinish, raster_end_);
226 timing_.Set(FrameTiming::kRasterFinishWallTime, raster_end_wall_time_);
228 timing_.SetRasterCacheStatistics(layer_cache_count_, layer_cache_bytes_,
229 picture_cache_count_, picture_cache_bytes_);
230 return timing_;
231}
void SetFrameNumber(uint64_t frame_number)
Definition: settings.h:57
fml::TimePoint Set(Phase phase, fml::TimePoint value)
Definition: settings.h:52
void SetRasterCacheStatistics(size_t layer_cache_count, size_t layer_cache_bytes, size_t picture_cache_count, size_t picture_cache_bytes)
Definition: settings.h:62
static TimePoint CurrentWallTime()
Definition: time_point.cc:57
static TimePoint Now()
Definition: time_point.cc:49
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191

◆ RecordRasterStart()

void flutter::FrameTimingsRecorder::RecordRasterStart ( fml::TimePoint  raster_start)

Records a raster start event.

Definition at line 148 of file frame_timings.cc.

148 {
149 fml::Status status = RecordRasterStartImpl(raster_start);
150 FML_DCHECK(status.ok());
151 (void)status;
152}

◆ RecordVsync()

void flutter::FrameTimingsRecorder::RecordVsync ( fml::TimePoint  vsync_start,
fml::TimePoint  vsync_target 
)

Records a vsync event.

Definition at line 129 of file frame_timings.cc.

130 {
131 fml::Status status = RecordVsyncImpl(vsync_start, vsync_target);
132 FML_DCHECK(status.ok());
133 (void)status;
134}

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