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();
285 FML_DCHECK(state_ == state) <<
"Expected state " << StateToString(state)
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.
const RasterCacheMetrics & picture_metrics() const
const RasterCacheMetrics & layer_metrics() const
static TimePoint CurrentWallTime()
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
size_t total_count() const
size_t total_bytes() const