5#include "flutter/flow/frame_timings.h"
10#include "flutter/common/settings.h"
11#include "flutter/fml/logging.h"
12#include "flutter/fml/time/time_point.h"
22 return "kUninitialized";
30 return "kRasterStart";
41std::atomic<uint64_t> FrameTimingsRecorder::frame_number_gen_ = {1};
44 : frame_number_(frame_number_gen_++),
45 frame_number_trace_arg_val_(
std::
to_string(frame_number_)) {}
48 : frame_number_(frame_number),
49 frame_number_trace_arg_val_(
std::
to_string(frame_number_)) {}
54 std::scoped_lock state_lock(state_mutex_);
60 std::scoped_lock state_lock(state_mutex_);
66 std::scoped_lock state_lock(state_mutex_);
72 std::scoped_lock state_lock(state_mutex_);
78 std::scoped_lock state_lock(state_mutex_);
84 std::scoped_lock state_lock(state_mutex_);
90 std::scoped_lock state_lock(state_mutex_);
92 return raster_end_wall_time_;
96 std::scoped_lock state_lock(state_mutex_);
98 return build_end_ - build_start_;
103 std::scoped_lock state_lock(state_mutex_);
105 return layer_cache_count_;
110 std::scoped_lock state_lock(state_mutex_);
112 return layer_cache_bytes_;
117 std::scoped_lock state_lock(state_mutex_);
119 return picture_cache_count_;
124 std::scoped_lock state_lock(state_mutex_);
126 return picture_cache_bytes_;
131 fml::Status status = RecordVsyncImpl(vsync_start, vsync_target);
137 fml::Status status = RecordBuildStartImpl(build_start);
143 fml::Status status = RecordBuildEndImpl(build_end);
149 fml::Status status = RecordRasterStartImpl(raster_start);
156 std::scoped_lock state_lock(state_mutex_);
159 "Check failed: state_ == State::kUninitialized.");
162 vsync_start_ = vsync_start;
163 vsync_target_ = vsync_target;
167fml::Status FrameTimingsRecorder::RecordBuildStartImpl(
169 std::scoped_lock state_lock(state_mutex_);
172 "Check failed: state_ == State::kVsync.");
175 build_start_ = build_start;
180 std::scoped_lock state_lock(state_mutex_);
183 "Check failed: state_ == State::kBuildStart.");
186 build_end_ = build_end;
190fml::Status FrameTimingsRecorder::RecordRasterStartImpl(
192 std::scoped_lock state_lock(state_mutex_);
195 "Check failed: state_ == State::kBuildEnd.");
198 raster_start_ = raster_start;
203 std::scoped_lock state_lock(state_mutex_);
214 picture_cache_count_ = picture_metrics.
total_count();
215 picture_cache_bytes_ = picture_metrics.
total_bytes();
218 layer_cache_count_ = layer_cache_bytes_ = picture_cache_count_ =
219 picture_cache_bytes_ = 0;
229 picture_cache_count_, picture_cache_bytes_);
234 std::scoped_lock state_lock(state_mutex_);
241 std::scoped_lock state_lock(state_mutex_);
242 std::unique_ptr<FrameTimingsRecorder> recorder =
243 std::make_unique<FrameTimingsRecorder>(frame_number_);
245 recorder->state_ =
state;
248 recorder->vsync_start_ = vsync_start_;
249 recorder->vsync_target_ = vsync_target_;
253 recorder->build_start_ = build_start_;
257 recorder->build_end_ = build_end_;
261 recorder->raster_start_ = raster_start_;
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_;
277 return frame_number_;
281 return frame_number_trace_arg_val_.c_str();
286 <<
", actual state " << StateToString(state_);
void SetFrameNumber(uint64_t frame_number)
fml::TimePoint Set(Phase phase, fml::TimePoint value)
void SetRasterCacheStatistics(size_t layer_cache_count, size_t layer_cache_bytes, size_t picture_cache_count, size_t picture_cache_bytes)
void RecordBuildStart(fml::TimePoint build_start)
Records a build start event.
FrameTiming RecordRasterEnd(const RasterCache *cache=nullptr)
fml::TimePoint GetVsyncStartTime() const
Timestamp of the vsync signal.
fml::TimePoint GetBuildEndTime() const
Timestamp of when the frame was finished building.
fml::TimePoint GetRasterEndTime() const
Timestamp of when the frame rasterization finished.
void RecordRasterStart(fml::TimePoint raster_start)
Records a raster start event.
std::unique_ptr< FrameTimingsRecorder > CloneUntil(State state)
Clones the recorder until (and including) the specified state.
void AssertInState(State state) const
size_t GetPictureCacheCount() const
Count of the picture cache entries.
fml::TimePoint GetRasterEndWallTime() const
Timestamp of when the frame rasterization is complete in wall-time.
size_t GetLayerCacheBytes() const
Total Bytes in all layer cache entries.
void RecordVsync(fml::TimePoint vsync_start, fml::TimePoint vsync_target)
Records a vsync event.
fml::TimePoint GetVsyncTargetTime() const
size_t GetPictureCacheBytes() const
Total Bytes in all picture cache entries.
size_t GetLayerCacheCount() const
Count of the layer cache entries.
void RecordBuildEnd(fml::TimePoint build_end)
Records a build end event.
FrameTimingsRecorder()
Default constructor, initializes the recorder with State::kUninitialized.
fml::TimePoint GetBuildStartTime() const
Timestamp of when the frame building started.
const char * GetFrameNumberTraceArg() const
Returns the frame number in a fml tracing friendly format.
fml::TimePoint GetRasterStartTime() const
Timestamp of when the frame rasterization started.
uint64_t GetFrameNumber() const
FrameTiming GetRecordedTime() const
Returns the recorded time from when RecordRasterEnd is called.
fml::TimeDelta GetBuildDuration() const
Duration of the frame build time.
static TimePoint CurrentWallTime()
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
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
static SkString to_string(int n)
size_t total_count() const
size_t total_bytes() const