This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] support: Print timestamps in timeout handler
- From: "Gabriel F. T. Gomes" <gabriel at inconstante dot eti dot br>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Fri, 16 Nov 2018 11:12:39 -0200
- Subject: Re: [PATCH] support: Print timestamps in timeout handler
- References: <875zx0hgio.fsf@oldenburg.str.redhat.com>
On Tue, 13 Nov 2018, Florian Weimer wrote:
>This is sometimes useful to determine if a test truly hang, or if it
>was making progress (logging information to standard output) and was
>just slow to complete.
>
>2018-11-13 Florian Weimer <fweimer@redhat.com>
>
> support: Print timestamps in timeout handler.
> * support/support_test_main.c (print_timestamp): New function.
> (signal_handler): Use it to print the termination time and the
> time of the last write to standard output.
Looks good to me.
>+static void
>+print_timestamp (const char *what, struct timeval tv)
>+{
>+ struct tm tm;
>+ if (gmtime_r (&tv.tv_sec, &tm) == NULL)
>+ printf ("%s: %lld.%06d\n",
>+ what, (long long int) tv.tv_sec, (int) tv.tv_usec);
~~~~~~~~~~~~~~~ ~~~~~
OK.
>+ /* Do this first to avoid further interference from the
>+ subprocess. */
>+ struct timeval now;
>+ bool now_available = gettimeofday (&now, NULL) == 0;
>+ struct stat64 st;
>+ bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0;
OK.
>+ if (now_available)
>+ print_timestamp ("Termination time", now);
>+ if (st_available)
>+ print_timestamp ("Last write to standard output",
>+ (struct timeval) { st.st_mtim.tv_sec,
>+ st.st_mtim.tv_nsec / 1000 });
OK.
The st_mtim member of stat64 is only available in XOPEN2K8 mode, which is
fine for the test cases.
PS: I was reading about these types in the manual, but there's no mention
to st_mtim, only to st_mtime, which is provided when *not* in XOPEN2K8.
Does this deserve mention in the manual? (not a problem for this patch).