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

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_)) {}

◆ 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 282 of file frame_timings.cc.

282 {
283 FML_DCHECK(state_ == state) << "Expected state " << StateToString(state)
284 << ", actual state " << StateToString(state_);
285}
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 237 of file frame_timings.cc.

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

◆ 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 274 of file frame_timings.cc.

274 {
275 return frame_number_;
276}

◆ GetFrameNumberTraceArg()

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

Returns the frame number in a fml tracing friendly format.

Definition at line 278 of file frame_timings.cc.

278 {
279 return frame_number_trace_arg_val_.c_str();
280}

◆ 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 231 of file frame_timings.cc.

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

◆ 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 const RasterCacheMetrics& layer_metrics = cache->layer_metrics();
210 const RasterCacheMetrics& picture_metrics = cache->picture_metrics();
211 layer_cache_count_ = layer_metrics.total_count();
212 layer_cache_bytes_ = layer_metrics.total_bytes();
213 picture_cache_count_ = picture_metrics.total_count();
214 picture_cache_bytes_ = picture_metrics.total_bytes();
215 } else {
216 layer_cache_count_ = layer_cache_bytes_ = picture_cache_count_ =
217 picture_cache_bytes_ = 0;
218 }
219 timing_.Set(FrameTiming::kVsyncStart, vsync_start_);
220 timing_.Set(FrameTiming::kBuildStart, build_start_);
221 timing_.Set(FrameTiming::kBuildFinish, build_end_);
222 timing_.Set(FrameTiming::kRasterStart, raster_start_);
223 timing_.Set(FrameTiming::kRasterFinish, raster_end_);
224 timing_.Set(FrameTiming::kRasterFinishWallTime, raster_end_wall_time_);
226 timing_.SetRasterCacheStatistics(layer_cache_count_, layer_cache_bytes_,
227 picture_cache_count_, picture_cache_bytes_);
228 return timing_;
229}
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: