4
4
5
5
#include " default_session_connection.h"
6
6
7
+ #include < lib/async/cpp/task.h>
8
+ #include < lib/async/default.h>
9
+ #include < lib/fit/function.h>
10
+
7
11
#include " flutter/fml/make_copyable.h"
8
12
#include " flutter/fml/trace_event.h"
9
13
14
+ #include " fml/time/time_point.h"
15
+ #include " runtime/dart/utils/root_inspect_node.h"
10
16
#include " vsync_waiter.h"
11
17
12
18
namespace flutter_runner {
@@ -175,6 +181,27 @@ DefaultSessionConnection::DefaultSessionConnection(
175
181
uint64_t max_frames_in_flight,
176
182
fml::TimeDelta vsync_offset)
177
183
: session_wrapper_(session.Bind(), nullptr ),
184
+ inspect_node_ (
185
+ dart_utils::RootInspectNode::CreateRootChild (" vsync_stats" )),
186
+ secondary_vsyncs_completed_(
187
+ inspect_node_.CreateUint(" SecondaryVsyncsCompleted" , 0u )),
188
+ vsyncs_requested_(inspect_node_.CreateUint(" VsyncsRequested" , 0u )),
189
+ vsyncs_completed_(inspect_node_.CreateUint(" VsyncsCompleted" , 0u )),
190
+ presents_requested_(inspect_node_.CreateUint(" PresentsRequested" , 0u )),
191
+ presents_submitted_(inspect_node_.CreateUint(" PresentsSubmitted" , 0u )),
192
+ presents_completed_(inspect_node_.CreateUint(" PresentsCompleted" , 0u )),
193
+ last_secondary_vsync_completed_(
194
+ inspect_node_.CreateInt(" LastSecondaryVsyncCompleteTime" , 0 )),
195
+ last_vsync_requested_(inspect_node_.CreateInt(" LastVsyncRequestTime" , 0 )),
196
+ last_vsync_completed_(
197
+ inspect_node_.CreateInt(" LastVsyncCompleteTime" , 0 )),
198
+ last_frame_requested_(
199
+ inspect_node_.CreateInt(" LastPresentRequestTime" , 0 )),
200
+ last_frame_presented_(
201
+ inspect_node_.CreateInt(" LastPresentSubmitTime" , 0 )),
202
+ last_frame_completed_(
203
+ inspect_node_.CreateInt(" LastSubmitCompleteTime" , 0 )),
204
+ inspect_dispatcher_(async_get_default_dispatcher()),
178
205
on_frame_presented_callback_(std::move(on_frame_presented_callback)),
179
206
kMaxFramesInFlight(max_frames_in_flight),
180
207
vsync_offset_(vsync_offset) {
@@ -207,6 +234,16 @@ DefaultSessionConnection::DefaultSessionConnection(
207
234
last_presentation_time_ = fml::TimePoint::FromEpochDelta (
208
235
fml::TimeDelta::FromNanoseconds (info.actual_presentation_time ));
209
236
237
+ // Scenic retired a given number of frames, so mark them as completed.
238
+ // Inspect updates must run on the inspect dispatcher.
239
+ async::PostTask (
240
+ inspect_dispatcher_,
241
+ [this , num_presents_handled,
242
+ now = fml::TimePoint::Now ().ToEpochDelta ().ToNanoseconds ()]() {
243
+ presents_completed_.Add (num_presents_handled);
244
+ last_frame_completed_.Set (now);
245
+ });
246
+
210
247
if (fire_callback_request_pending_) {
211
248
FireCallbackMaybe ();
212
249
}
@@ -251,7 +288,17 @@ void DefaultSessionConnection::Present() {
251
288
next_present_session_trace_id_);
252
289
++next_present_session_trace_id_;
253
290
254
- present_requested_time_ = fml::TimePoint::Now ();
291
+ auto now = fml::TimePoint::Now ();
292
+ present_requested_time_ = now;
293
+
294
+ // Flutter is requesting a frame here, so mark it as such.
295
+ // Inspect updates must run on the inspect dispatcher.
296
+ async::PostTask (
297
+ inspect_dispatcher_,
298
+ [this , now = fml::TimePoint::Now ().ToEpochDelta ().ToNanoseconds ()]() {
299
+ presents_requested_.Add (1 );
300
+ last_frame_requested_.Set (now);
301
+ });
255
302
256
303
// Throttle frame submission to Scenic if we already have the maximum amount
257
304
// of frames in flight. This allows the paint tasks for this frame to execute
@@ -272,6 +319,15 @@ void DefaultSessionConnection::AwaitVsync(FireCallbackCallback callback) {
272
319
TRACE_DURATION (" flutter" , " DefaultSessionConnection::AwaitVsync" );
273
320
fire_callback_ = callback;
274
321
322
+ // Flutter is requesting a vsync here, so mark it as such.
323
+ // Inspect updates must run on the inspect dispatcher.
324
+ async::PostTask (
325
+ inspect_dispatcher_,
326
+ [this , now = fml::TimePoint::Now ().ToEpochDelta ().ToNanoseconds ()]() {
327
+ vsyncs_requested_.Add (1 );
328
+ last_vsync_requested_.Set (now);
329
+ });
330
+
275
331
FireCallbackMaybe ();
276
332
}
277
333
@@ -282,6 +338,15 @@ void DefaultSessionConnection::AwaitVsyncForSecondaryCallback(
282
338
" DefaultSessionConnection::AwaitVsyncForSecondaryCallback" );
283
339
fire_callback_ = callback;
284
340
341
+ // Flutter is requesting a secondary vsync here, so mark it as such.
342
+ // Inspect updates must run on the inspect dispatcher.
343
+ async::PostTask (
344
+ inspect_dispatcher_,
345
+ [this , now = fml::TimePoint::Now ().ToEpochDelta ().ToNanoseconds ()]() {
346
+ secondary_vsyncs_completed_.Add (1 );
347
+ last_secondary_vsync_completed_.Set (now);
348
+ });
349
+
285
350
FlutterFrameTimes times = GetTargetTimesHelper (/* secondary_callback=*/ true );
286
351
fire_callback_ (times.frame_start , times.frame_target );
287
352
}
@@ -316,6 +381,15 @@ void DefaultSessionConnection::PresentSession() {
316
381
317
382
last_latch_point_targeted_ = next_latch_point;
318
383
384
+ // Flutter is presenting a frame here, so mark it as such.
385
+ // Inspect updates must run on the inspect dispatcher.
386
+ async::PostTask (
387
+ inspect_dispatcher_,
388
+ [this , now = fml::TimePoint::Now ().ToEpochDelta ().ToNanoseconds ()]() {
389
+ presents_submitted_.Add (1 );
390
+ last_frame_presented_.Set (now);
391
+ });
392
+
319
393
session_wrapper_.Present2 (
320
394
/* requested_presentation_time=*/ next_latch_point.ToEpochDelta ()
321
395
.ToNanoseconds (),
@@ -357,6 +431,15 @@ void DefaultSessionConnection::FireCallbackMaybe() {
357
431
last_targeted_vsync_ = times.frame_target ;
358
432
fire_callback_request_pending_ = false ;
359
433
434
+ // Scenic completed a vsync here, so mark it as such.
435
+ // Inspect updates must run on the inspect dispatcher.
436
+ async::PostTask (
437
+ inspect_dispatcher_,
438
+ [this , now = fml::TimePoint::Now ().ToEpochDelta ().ToNanoseconds ()]() {
439
+ vsyncs_completed_.Add (1 );
440
+ last_vsync_completed_.Set (now);
441
+ });
442
+
360
443
fire_callback_ (times.frame_start , times.frame_target );
361
444
} else {
362
445
fire_callback_request_pending_ = true ;
0 commit comments