tools: debug-events: offset timestamps by the first normal event
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 11 Nov 2019 05:47:10 +0000 (15:47 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 18 Nov 2019 22:43:48 +0000 (22:43 +0000)
Start counting the timestamps from the first time we get something off the
actual fd. This makes it easier to match up timestamps with the output from
libinput record.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/libinput-debug-events.c

index dd0c7ed0f65589ac0f8a7d6148569229ab4dc371..d4f5914f959294e892c5dbdc080cc6a31460c1c6 100644 (file)
@@ -155,7 +155,7 @@ print_event_header(struct libinput_event *ev)
 static void
 print_event_time(uint32_t time)
 {
-       printq("%+6.2fs ", (time - start_time) / 1000.0);
+       printq("%+6.2fs ", start_time ? (time - start_time) / 1000.0 : 0);
 }
 
 static inline void
@@ -908,8 +908,16 @@ mainloop(struct libinput *li)
                fprintf(stderr, "Expected device added events on startup but got none. "
                                "Maybe you don't have the right permissions?\n");
 
-       while (!stop && poll(&fds, 1, -1) > -1)
-               handle_and_print_events(li);
+       /* time offset starts with our first received event */
+       if (poll(&fds, 1, -1) > -1) {
+               struct timespec tp;
+
+               clock_gettime(CLOCK_MONOTONIC, &tp);
+               start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
+               do {
+                       handle_and_print_events(li);
+               } while (!stop && poll(&fds, 1, -1) > -1);
+       }
 
        printf("\n");
 }
@@ -923,16 +931,12 @@ int
 main(int argc, char **argv)
 {
        struct libinput *li;
-       struct timespec tp;
        enum tools_backend backend = BACKEND_NONE;
        const char *seat_or_device = "seat0";
        bool grab = false;
        bool verbose = false;
        struct sigaction act;
 
-       clock_gettime(CLOCK_MONOTONIC, &tp);
-       start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
-
        tools_init_options(&options);
 
        while (1) {