Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros
frame_timings.h File Reference
#include <mutex>
#include "flutter/common/settings.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/status.h"
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/time/time_point.h"

Go to the source code of this file.

Classes

class  flutter::FrameTimingsRecorder
 

Namespaces

namespace  flutter
 

Macros

#define TRACE_EVENT_WITH_FRAME_NUMBER(recorder, category_group, name, flow_id_count, flow_ids)
 

Macro Definition Documentation

◆ TRACE_EVENT_WITH_FRAME_NUMBER

#define TRACE_EVENT_WITH_FRAME_NUMBER (   recorder,
  category_group,
  name,
  flow_id_count,
  flow_ids 
)
Value:
TRACE_EVENT1_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids, \
"frame_number", \
recorder->GetFrameNumberTraceArg())
const char * name
Definition fuchsia.cc:50
#define TRACE_EVENT1_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids, arg1_name, arg1_val)

Definition at line 17 of file frame_timings.h.

22 {
23
24/// Records timestamps for various phases of a frame rendering process.
25///
26/// Recorder is created on vsync and destroyed after the rasterization of the
27/// frame. This class is thread safe and doesn't require additional
28/// synchronization.
29class FrameTimingsRecorder {
30 public:
31 /// Various states that the recorder can be in. When created the recorder is
32 /// in an unitialized state and transtions in sequential order of the states.
33 // After adding an item to this enum, modify StateToString accordingly.
34 enum class State : uint32_t {
36 kVsync,
37 kBuildStart,
38 kBuildEnd,
39 kRasterStart,
40 kRasterEnd,
41 };
42
43 /// Default constructor, initializes the recorder with State::kUninitialized.
44 FrameTimingsRecorder();
45
46 /// Constructor with a pre-populated frame number.
47 explicit FrameTimingsRecorder(uint64_t frame_number);
48
49 ~FrameTimingsRecorder();
50
51 /// Timestamp of the vsync signal.
52 fml::TimePoint GetVsyncStartTime() const;
53
54 /// Timestamp of when the frame was targeted to be presented.
55 ///
56 /// This is typically the next vsync signal timestamp.
57 fml::TimePoint GetVsyncTargetTime() const;
58
59 /// Timestamp of when the frame building started.
60 fml::TimePoint GetBuildStartTime() const;
61
62 /// Timestamp of when the frame was finished building.
63 fml::TimePoint GetBuildEndTime() const;
64
65 /// Timestamp of when the frame rasterization started.
66 fml::TimePoint GetRasterStartTime() const;
67
68 /// Timestamp of when the frame rasterization finished.
69 fml::TimePoint GetRasterEndTime() const;
70
71 /// Timestamp of when the frame rasterization is complete in wall-time.
72 fml::TimePoint GetRasterEndWallTime() const;
73
74 /// Duration of the frame build time.
75 fml::TimeDelta GetBuildDuration() const;
76
77 /// Count of the layer cache entries
78 size_t GetLayerCacheCount() const;
79
80 /// Total Bytes in all layer cache entries
81 size_t GetLayerCacheBytes() const;
82
83 /// Count of the picture cache entries
84 size_t GetPictureCacheCount() const;
85
86 /// Total Bytes in all picture cache entries
87 size_t GetPictureCacheBytes() const;
88
89 /// Records a vsync event.
90 void RecordVsync(fml::TimePoint vsync_start, fml::TimePoint vsync_target);
91
92 /// Records a build start event.
93 void RecordBuildStart(fml::TimePoint build_start);
94
95 /// Records a build end event.
96 void RecordBuildEnd(fml::TimePoint build_end);
97
98 /// Records a raster start event.
99 void RecordRasterStart(fml::TimePoint raster_start);
100
101 /// Clones the recorder until (and including) the specified state.
102 std::unique_ptr<FrameTimingsRecorder> CloneUntil(State state);
103
104 /// Records a raster end event, and builds a `FrameTiming` that summarizes all
105 /// the events. This summary is sent to the framework.
106 FrameTiming RecordRasterEnd(const RasterCache* cache = nullptr);
107
108 /// Returns the frame number. Frame number is unique per frame and a frame
109 /// built earlier will have a frame number less than a frame that has been
110 /// built at a later point of time.
111 uint64_t GetFrameNumber() const;
112
113 /// Returns the frame number in a fml tracing friendly format.
114 const char* GetFrameNumberTraceArg() const;
115
116 /// Returns the recorded time from when `RecordRasterEnd` is called.
117 FrameTiming GetRecordedTime() const;
118
119 /// Asserts in unopt builds that the recorder is current at the specified
120 /// state.
121 ///
122 /// Instead of adding a `GetState` method and asserting on the result, this
123 /// method prevents other logic from relying on the state.
124 ///
125 /// In release builds, this call is a no-op.
126 void AssertInState(State state) const;
127
128 private:
129 FML_FRIEND_TEST(FrameTimingsRecorderTest, ThrowWhenRecordBuildBeforeVsync);
130 FML_FRIEND_TEST(FrameTimingsRecorderTest,
131 ThrowWhenRecordRasterBeforeBuildEnd);
132
133 [[nodiscard]] fml::Status RecordVsyncImpl(fml::TimePoint vsync_start,
134 fml::TimePoint vsync_target);
135 [[nodiscard]] fml::Status RecordBuildStartImpl(fml::TimePoint build_start);
136 [[nodiscard]] fml::Status RecordBuildEndImpl(fml::TimePoint build_end);
137 [[nodiscard]] fml::Status RecordRasterStartImpl(fml::TimePoint raster_start);
138
139 static std::atomic<uint64_t> frame_number_gen_;
140
141 mutable std::mutex state_mutex_;
142 State state_ = State::kUninitialized;
143
144 const uint64_t frame_number_;
145 const std::string frame_number_trace_arg_val_;
146
147 fml::TimePoint vsync_start_;
148 fml::TimePoint vsync_target_;
149 fml::TimePoint build_start_;
150 fml::TimePoint build_end_;
151 fml::TimePoint raster_start_;
152 fml::TimePoint raster_end_;
153 fml::TimePoint raster_end_wall_time_;
154
155 size_t layer_cache_count_;
156 size_t layer_cache_bytes_;
157 size_t picture_cache_count_;
158 size_t picture_cache_bytes_;
159
160 // Set when `RecordRasterEnd` is called. Cannot be reset once set.
161 FrameTiming timing_;
162
163 FML_DISALLOW_COPY_ASSIGN_AND_MOVE(FrameTimingsRecorder);
164};
165
166} // namespace flutter
167
168#endif // FLUTTER_FLOW_FRAME_TIMINGS_H_
AtkStateType state
#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName)
Definition macros.h:31
#define FML_FRIEND_TEST(test_case_name, test_name)
Definition macros.h:41