Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 283a42f

Browse files
authored
fuchsia: Log vsync stats in inspect (#27433)
1 parent 590902b commit 283a42f

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ template("runner_sources") {
110110
]
111111

112112
public_deps = [
113+
"$fuchsia_sdk_root/pkg:inspect",
113114
"$fuchsia_sdk_root/pkg:scenic_cpp",
114115
"$fuchsia_sdk_root/pkg:sys_cpp",
115116
"$fuchsia_sdk_root/pkg:sys_inspect_cpp",

shell/platform/fuchsia/flutter/default_session_connection.cc

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44

55
#include "default_session_connection.h"
66

7+
#include <lib/async/cpp/task.h>
8+
#include <lib/async/default.h>
9+
#include <lib/fit/function.h>
10+
711
#include "flutter/fml/make_copyable.h"
812
#include "flutter/fml/trace_event.h"
913

14+
#include "fml/time/time_point.h"
15+
#include "runtime/dart/utils/root_inspect_node.h"
1016
#include "vsync_waiter.h"
1117

1218
namespace flutter_runner {
@@ -175,6 +181,27 @@ DefaultSessionConnection::DefaultSessionConnection(
175181
uint64_t max_frames_in_flight,
176182
fml::TimeDelta vsync_offset)
177183
: 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()),
178205
on_frame_presented_callback_(std::move(on_frame_presented_callback)),
179206
kMaxFramesInFlight(max_frames_in_flight),
180207
vsync_offset_(vsync_offset) {
@@ -207,6 +234,16 @@ DefaultSessionConnection::DefaultSessionConnection(
207234
last_presentation_time_ = fml::TimePoint::FromEpochDelta(
208235
fml::TimeDelta::FromNanoseconds(info.actual_presentation_time));
209236

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+
210247
if (fire_callback_request_pending_) {
211248
FireCallbackMaybe();
212249
}
@@ -251,7 +288,17 @@ void DefaultSessionConnection::Present() {
251288
next_present_session_trace_id_);
252289
++next_present_session_trace_id_;
253290

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+
});
255302

256303
// Throttle frame submission to Scenic if we already have the maximum amount
257304
// of frames in flight. This allows the paint tasks for this frame to execute
@@ -272,6 +319,15 @@ void DefaultSessionConnection::AwaitVsync(FireCallbackCallback callback) {
272319
TRACE_DURATION("flutter", "DefaultSessionConnection::AwaitVsync");
273320
fire_callback_ = callback;
274321

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+
275331
FireCallbackMaybe();
276332
}
277333

@@ -282,6 +338,15 @@ void DefaultSessionConnection::AwaitVsyncForSecondaryCallback(
282338
"DefaultSessionConnection::AwaitVsyncForSecondaryCallback");
283339
fire_callback_ = callback;
284340

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+
285350
FlutterFrameTimes times = GetTargetTimesHelper(/*secondary_callback=*/true);
286351
fire_callback_(times.frame_start, times.frame_target);
287352
}
@@ -316,6 +381,15 @@ void DefaultSessionConnection::PresentSession() {
316381

317382
last_latch_point_targeted_ = next_latch_point;
318383

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+
319393
session_wrapper_.Present2(
320394
/*requested_presentation_time=*/next_latch_point.ToEpochDelta()
321395
.ToNanoseconds(),
@@ -357,6 +431,15 @@ void DefaultSessionConnection::FireCallbackMaybe() {
357431
last_targeted_vsync_ = times.frame_target;
358432
fire_callback_request_pending_ = false;
359433

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+
360443
fire_callback_(times.frame_start, times.frame_target);
361444
} else {
362445
fire_callback_request_pending_ = true;

shell/platform/fuchsia/flutter/default_session_connection.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include <fuchsia/scenic/scheduling/cpp/fidl.h>
99
#include <fuchsia/ui/scenic/cpp/fidl.h>
10+
#include <lib/async/dispatcher.h>
1011
#include <lib/fidl/cpp/interface_handle.h>
12+
#include <lib/inspect/cpp/inspect.h>
1113
#include <lib/ui/scenic/cpp/session.h>
1214

1315
#include "flutter/fml/closure.h"
@@ -102,6 +104,21 @@ class DefaultSessionConnection final {
102104

103105
scenic::Session session_wrapper_;
104106

107+
inspect::Node inspect_node_;
108+
inspect::UintProperty secondary_vsyncs_completed_;
109+
inspect::UintProperty vsyncs_requested_;
110+
inspect::UintProperty vsyncs_completed_;
111+
inspect::UintProperty presents_requested_;
112+
inspect::UintProperty presents_submitted_;
113+
inspect::UintProperty presents_completed_;
114+
inspect::IntProperty last_secondary_vsync_completed_;
115+
inspect::IntProperty last_vsync_requested_;
116+
inspect::IntProperty last_vsync_completed_;
117+
inspect::IntProperty last_frame_requested_;
118+
inspect::IntProperty last_frame_presented_;
119+
inspect::IntProperty last_frame_completed_;
120+
async_dispatcher_t* inspect_dispatcher_;
121+
105122
on_frame_presented_event on_frame_presented_callback_;
106123

107124
fml::TimePoint last_latch_point_targeted_ =

0 commit comments

Comments
 (0)