From b7aa51de0d613dd94111728413716f25556714c8 Mon Sep 17 00:00:00 2001 From: Emil Mikulic Date: Mon, 11 Mar 2013 04:23:14 +1100 Subject: [PATCH] Show TID instead of PID in warn_time(). --- buftee.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/buftee.c b/buftee.c index 4b03eca..0ab9bd4 100644 --- a/buftee.c +++ b/buftee.c @@ -175,6 +175,10 @@ static void time_diff(const struct timespec* restrict start, assert(out->tv_nsec < 1000000000); } +static int gettid(void) { + return (int)syscall(SYS_gettid); +} + static void warn_time(const char* desc, const struct timespec* restrict start, const struct timespec* restrict end) { @@ -183,9 +187,8 @@ static void warn_time(const char* desc, if (diff.tv_sec > 0 || diff.tv_nsec > SLOW_NSEC) { char buf[128]; extern char *__progname; // This is where glibc stashes argv[0]. - snprintf(buf, sizeof(buf), "%d: %s: %s took %d.%09d secs\n", - (int)getpid(), __progname, desc, - (int)diff.tv_sec, (int)diff.tv_nsec); + snprintf(buf, sizeof(buf), "%s:tid %d: %s took %d.%09d secs\n", + __progname, gettid(), desc, (int)diff.tv_sec, (int)diff.tv_nsec); // Best effort write to a non-blocking stderr. (void)write(STDERR_FILENO, buf, strlen(buf)); } -- 2.17.1