Skip to content

Commit c07d227

Browse files
OMWAI-3261: vsync timing debugs added (chinmaygarde#9)
1 parent ea05169 commit c07d227

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/wayland_display.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
#include "egl_utils.h"
3636
#include "wayland_display.h"
3737

38+
#include <unistd.h>
39+
#include <sys/syscall.h>
40+
41+
#define DBG_TIMING(x)
42+
43+
DBG_TIMING(
44+
#define gettid() syscall(SYS_gettid)
45+
static uint64_t t00;
46+
)
47+
3848
namespace flutter {
3949

4050
static double get_pixel_ratio(int32_t physical_width, int32_t physical_height, int32_t pixels_width, int32_t pixels_height) {
@@ -344,6 +354,14 @@ const struct wp_presentation_feedback_listener WaylandDisplay::kPresentationFeed
344354
}
345355
}
346356

357+
DBG_TIMING({
358+
static auto t0 = FlutterEngineGetCurrentTime();
359+
const auto t1 = FlutterEngineGetCurrentTime();
360+
// dbgI("[%09.4f][%ld] presented: %09lldns flags:%08x p2p-diff:%5lldus rerfresh:%u\n", (t1-t00)/1e9, gettid(), (new_last_frame_ns-t00), flags, (new_last_frame_ns - wd->vsync.last_frame_)/1000, refresh);
361+
dbgI("[%09.4f][%ld] presented %09.4f f:%08x dc:%.5f df:%.5f r:%u\n", (t1-t00)/1e9, gettid(), (new_last_frame_ns-t00)/1e9, flags, (t1 - t0)/1e9, (new_last_frame_ns - wd->vsync.last_frame_)/1e9, refresh);
362+
t0 = t1;
363+
})
364+
347365
wd->vsync.last_frame_ = new_last_frame_ns;
348366
},
349367
.discarded =
@@ -499,6 +517,7 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height, const std::string &b
499517
return;
500518
}
501519

520+
DBG_TIMING({t00 = FlutterEngineGetCurrentTime();});
502521
valid_ = true;
503522
}
504523

@@ -531,12 +550,24 @@ bool WaylandDisplay::SetupEngine(const std::string &bundle_path, const std::vect
531550
config.open_gl.present = [](void *data) -> bool {
532551
WaylandDisplay *const wd = get_wayland_display(data);
533552

553+
DBG_TIMING(
554+
static auto tprev = FlutterEngineGetCurrentTime();
555+
auto tb = FlutterEngineGetCurrentTime();
556+
dbgI("[%09.4f][%ld] >>> swap buffer [%09.4f]\n", (tb-t00)/1e9, gettid(), (tb-tprev)/1e9);
557+
);
558+
534559
if (eglSwapBuffers(wd->egl_display_, wd->egl_surface_) != EGL_TRUE) {
535560
LogLastEGLError();
536561
dbgE("Could not swap the EGL buffer\n");
537562
return false;
538563
}
539564

565+
DBG_TIMING(
566+
auto ta = FlutterEngineGetCurrentTime();
567+
dbgI("[%09.4f][%ld] <<< swap buffer [dur:%09.4f]\n", (ta-t00)/1e9, gettid(), (ta-tb)/1e9);
568+
tprev = tb;
569+
);
570+
540571
return true;
541572
};
542573
config.open_gl.fbo_callback = [](void *data) -> uint32_t { return 0; };
@@ -591,6 +622,11 @@ bool WaylandDisplay::SetupEngine(const std::string &bundle_path, const std::vect
591622
.vsync_callback = [](void *data, intptr_t baton) -> void {
592623
WaylandDisplay *const wd = get_wayland_display(data);
593624

625+
DBG_TIMING({
626+
auto tx = FlutterEngineGetCurrentTime();
627+
dbgI("[%09.4f][%ld] vsync callback [%jx]\n", (tx-t00)/1e9, gettid(), static_cast<uintmax_t>(baton));
628+
});
629+
594630
if (wd->vsync.baton_ != 0) {
595631
dbgE("vsync.wait: New baton arrived, but old was not sent\n");
596632
exit(1);
@@ -773,6 +809,13 @@ ssize_t WaylandDisplay::vSyncHandler() {
773809
const uint64_t finish_time_ns = current_ns + vsync.vblank_time_ns_;
774810
intptr_t baton = std::atomic_exchange(&vsync.baton_, 0);
775811

812+
DBG_TIMING({
813+
auto tx = FlutterEngineGetCurrentTime();
814+
dbgI("[%09.4f][%ld] flutterEngineOnVsync [%jx] (t:%09.4f d:%09.4f vb:%09.4f c:%09.4f f:%09.4f)\n",
815+
(tx-t00)/1e9, gettid(), static_cast<uintmax_t>(baton), (t_now_ns-t00)/1e9, (t_now_ns-vsync.last_frame_)/1e9,
816+
vsync.vblank_time_ns_/1e9, (current_ns-t00)/1e9, (finish_time_ns-t00)/1e9);
817+
});
818+
776819
const auto status = FlutterEngineOnVsync(engine_, baton, current_ns, finish_time_ns);
777820

778821
if (status != kSuccess) {
@@ -901,6 +944,10 @@ bool WaylandDisplay::Run() {
901944
}
902945

903946
if (vsync.presentation_clk_id_ != UINT32_MAX && presentation_ != nullptr) {
947+
DBG_TIMING({
948+
auto tx = FlutterEngineGetCurrentTime();
949+
dbgI("[%09.4f][%ld] add listener\n", (tx-t00)/1e9, gettid());
950+
});
904951
wp_presentation_feedback_add_listener(::wp_presentation_feedback(presentation_, surface_), &kPresentationFeedbackListener, this);
905952
wl_display_dispatch_pending(display_);
906953
}

0 commit comments

Comments
 (0)