forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_timings.cc
159 lines (128 loc) · 4.59 KB
/
frame_timings.cc
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
147
148
149
150
151
152
153
154
155
156
157
158
159
// 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.
#include "flutter/flow/frame_timings.h"
#include <memory>
#include <sstream>
#include "flutter/common/settings.h"
#include "flutter/fml/logging.h"
namespace flutter {
std::atomic<uint64_t> FrameTimingsRecorder::frame_number_gen_ = {1};
static std::string ToString(uint64_t val) {
std::stringstream stream;
stream << val;
return stream.str();
}
FrameTimingsRecorder::FrameTimingsRecorder()
: frame_number_(frame_number_gen_++),
frame_number_trace_arg_val_(ToString(frame_number_)) {}
FrameTimingsRecorder::FrameTimingsRecorder(uint64_t frame_number)
: frame_number_(frame_number),
frame_number_trace_arg_val_(ToString(frame_number_)) {}
FrameTimingsRecorder::~FrameTimingsRecorder() = default;
fml::TimePoint FrameTimingsRecorder::GetVsyncStartTime() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kVsync);
return vsync_start_;
}
fml::TimePoint FrameTimingsRecorder::GetVsyncTargetTime() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kVsync);
return vsync_target_;
}
fml::TimePoint FrameTimingsRecorder::GetBuildStartTime() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kBuildStart);
return build_start_;
}
fml::TimePoint FrameTimingsRecorder::GetBuildEndTime() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kBuildEnd);
return build_end_;
}
fml::TimePoint FrameTimingsRecorder::GetRasterStartTime() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kRasterStart);
return raster_start_;
}
fml::TimePoint FrameTimingsRecorder::GetRasterEndTime() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kRasterEnd);
return raster_end_;
}
fml::TimeDelta FrameTimingsRecorder::GetBuildDuration() const {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ >= State::kBuildEnd);
return build_end_ - build_start_;
}
void FrameTimingsRecorder::RecordVsync(fml::TimePoint vsync_start,
fml::TimePoint vsync_target) {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ == State::kUninitialized);
state_ = State::kVsync;
vsync_start_ = vsync_start;
vsync_target_ = vsync_target;
}
void FrameTimingsRecorder::RecordBuildStart(fml::TimePoint build_start) {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ == State::kVsync);
state_ = State::kBuildStart;
build_start_ = build_start;
}
void FrameTimingsRecorder::RecordBuildEnd(fml::TimePoint build_end) {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ == State::kBuildStart);
state_ = State::kBuildEnd;
build_end_ = build_end;
}
void FrameTimingsRecorder::RecordRasterStart(fml::TimePoint raster_start) {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ == State::kBuildEnd);
state_ = State::kRasterStart;
raster_start_ = raster_start;
}
FrameTiming FrameTimingsRecorder::RecordRasterEnd(fml::TimePoint raster_end) {
std::scoped_lock state_lock(state_mutex_);
FML_DCHECK(state_ == State::kRasterStart);
state_ = State::kRasterEnd;
raster_end_ = raster_end;
FrameTiming timing;
timing.Set(FrameTiming::kVsyncStart, vsync_start_);
timing.Set(FrameTiming::kBuildStart, build_start_);
timing.Set(FrameTiming::kBuildFinish, build_end_);
timing.Set(FrameTiming::kRasterStart, raster_start_);
timing.Set(FrameTiming::kRasterFinish, raster_end_);
timing.SetFrameNumber(GetFrameNumber());
return timing;
}
std::unique_ptr<FrameTimingsRecorder> FrameTimingsRecorder::CloneUntil(
State state) {
std::scoped_lock state_lock(state_mutex_);
std::unique_ptr<FrameTimingsRecorder> recorder =
std::make_unique<FrameTimingsRecorder>(frame_number_);
recorder->state_ = state;
if (state >= State::kVsync) {
recorder->vsync_start_ = vsync_start_;
recorder->vsync_target_ = vsync_target_;
}
if (state >= State::kBuildStart) {
recorder->build_start_ = build_start_;
}
if (state >= State::kRasterEnd) {
recorder->build_end_ = build_end_;
}
if (state >= State::kRasterStart) {
recorder->raster_start_ = raster_start_;
}
if (state >= State::kRasterEnd) {
recorder->raster_end_ = raster_end_;
}
return recorder;
}
uint64_t FrameTimingsRecorder::GetFrameNumber() const {
return frame_number_;
}
const char* FrameTimingsRecorder::GetFrameNumberTraceArg() const {
return frame_number_trace_arg_val_.c_str();
}
} // namespace flutter