• Pl chevron_right

      Christian Hergert: Testing Keyboard Input Latency

      news.movim.eu / PlanetGnome • 14 hours ago • 1 minute

    I occasionally see people go through great effort to do end-to-end testing of keyboard input latency. That is fantastic but it requires hardware and patience I don’t, nor will ever, have.

    Here is a much simpler way to get about 90% of the value. For example, everything but driver/interrupt handler latency and display link scanout/monitor visibility latency and of course your app side (but you could theoretically rig this up to do that too, inside your app). Not that those aren’t important, but they definitely fall into the category of things I personally cannot control for you.

    Keyspeed is a very simple GTK application which uses /dev/uinput to synthesize keypresses. Since it knows the time of provenance, it can compare that to when it gets the event back from compositor delivery.

    Wrap all that data up in Sysprof capture marks, pull in some from the compositor (GNOME Shell/Mutter support this), tie in some callgraphs/flamegraphs, and you have a very good overview of what is going on during your keypress.

    Run it like this (but remember to chmod back when you’re done less you have attack surface available).

    $ sudo chmod 660 /dev/uinput
    $ git clone https://gitlab.gnome.org/chergert/keypress
    $ sudo dnf install sysprof-devel libinput-devel gtk4-devel
    $ make
    $ sysprof-cli --gtk --gnome-shell capture.syscap -- ./keyspeed
    $ sysprof capture.syscap

    a screenshot of keypress. key being press/release on left, time it took on the right.

    Currently, this only shows you keypress send to receive in GTK, but if someone cared enough, you could make it take the next GtkFrameTimings and use that to get the presentation time. I don’t need that for what I’m doing, so it doesn’t.

    If you go to the marks section, you can dive in to a specific keypress/release cycle. Zoom in on just that section, switch back to callgraph/flamegraph profiler and see what was going on.

    Pretty simple, no special hardware needed.

    You can see how long it took, where time was spent, and more importantly, how much time was empty between things that matter.

    A screenshot of sysprof showing the marks section with timing information for minutia happening across GTK/Mutter for full event delivery timing.

    A screenshot of sysprof showing the marks section with timing information for minutia happening across GTK/Mutter for full event delivery timing.