forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_timings.h
146 lines (107 loc) · 4.52 KB
/
frame_timings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FLOW_FRAME_TIMINGS_H_
#define FLUTTER_FLOW_FRAME_TIMINGS_H_
#include <mutex>
#include "flutter/common/settings.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/time/time_point.h"
#define TRACE_EVENT_WITH_FRAME_NUMBER(recorder, category_group, name) \
TRACE_EVENT1(category_group, name, "frame_number", \
recorder->GetFrameNumberTraceArg())
namespace flutter {
/// 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.
class FrameTimingsRecorder {
public:
/// 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.
enum class State : uint32_t {
kUninitialized,
kVsync,
kBuildStart,
kBuildEnd,
kRasterStart,
kRasterEnd,
};
/// Default constructor, initializes the recorder with State::kUninitialized.
FrameTimingsRecorder();
/// Constructor with a pre-populated frame number.
explicit FrameTimingsRecorder(uint64_t frame_number);
~FrameTimingsRecorder();
/// Timestamp of the vsync signal.
fml::TimePoint GetVsyncStartTime() const;
/// Timestamp of when the frame was targeted to be presented.
///
/// This is typically the next vsync signal timestamp.
fml::TimePoint GetVsyncTargetTime() const;
/// Timestamp of when the frame building started.
fml::TimePoint GetBuildStartTime() const;
/// Timestamp of when the frame was finished building.
fml::TimePoint GetBuildEndTime() const;
/// Timestamp of when the frame rasterization started.
fml::TimePoint GetRasterStartTime() const;
/// Timestamp of when the frame rasterization finished.
fml::TimePoint GetRasterEndTime() const;
/// Timestamp of when the frame rasterization is complete in wall-time.
fml::TimePoint GetRasterEndWallTime() const;
/// Duration of the frame build time.
fml::TimeDelta GetBuildDuration() const;
/// Count of the layer cache entries
size_t GetLayerCacheCount() const;
/// Total Bytes in all layer cache entries
size_t GetLayerCacheBytes() const;
/// Count of the picture cache entries
size_t GetPictureCacheCount() const;
/// Total Bytes in all picture cache entries
size_t GetPictureCacheBytes() const;
/// Records a vsync event.
void RecordVsync(fml::TimePoint vsync_start, fml::TimePoint vsync_target);
/// Records a build start event.
void RecordBuildStart(fml::TimePoint build_start);
/// Records a build end event.
void RecordBuildEnd(fml::TimePoint build_end);
/// Records a raster start event.
void RecordRasterStart(fml::TimePoint raster_start);
/// Clones the recorder until (and including) the specified state.
std::unique_ptr<FrameTimingsRecorder> CloneUntil(State state);
/// Records a raster end event, and builds a `FrameTiming` that summarizes all
/// the events. This summary is sent to the framework.
FrameTiming RecordRasterEnd(const RasterCache* cache = nullptr);
/// 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.
uint64_t GetFrameNumber() const;
/// Returns the frame number in a fml tracing friendly format.
const char* GetFrameNumberTraceArg() const;
/// Returns the recorded time from when `RecordRasterEnd` is called.
FrameTiming GetRecordedTime() const;
private:
static std::atomic<uint64_t> frame_number_gen_;
mutable std::mutex state_mutex_;
State state_ = State::kUninitialized;
const uint64_t frame_number_;
const std::string frame_number_trace_arg_val_;
fml::TimePoint vsync_start_;
fml::TimePoint vsync_target_;
fml::TimePoint build_start_;
fml::TimePoint build_end_;
fml::TimePoint raster_start_;
fml::TimePoint raster_end_;
fml::TimePoint raster_end_wall_time_;
size_t layer_cache_count_;
size_t layer_cache_bytes_;
size_t picture_cache_count_;
size_t picture_cache_bytes_;
// Set when `RecordRasterEnd` is called. Cannot be reset once set.
FrameTiming timing_;
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(FrameTimingsRecorder);
};
} // namespace flutter
#endif // FLUTTER_FLOW_FRAME_TIMINGS_H_