From 219b829b623f66636efb7ddcc07a7e24b0aa9f63 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 20 May 2019 20:28:34 +0200 Subject: [PATCH] MINOR: time: add a function to retrieve another thread's cputime now_cpu_time_thread() does the same as now_cpu_time() but for another thread based on its clockid. --- include/common/time.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/common/time.h b/include/common/time.h index 079087327..9920a77ae 100644 --- a/include/common/time.h +++ b/include/common/time.h @@ -540,6 +540,18 @@ static inline uint64_t now_cpu_time() #endif } +/* returns another thread's cumulated CPU time in nanoseconds if supported, otherwise zero */ +static inline uint64_t now_cpu_time_thread(const struct thread_info *thr) +{ +#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME) + struct timespec ts; + clock_gettime(thr->clock_id, &ts); + return ts.tv_sec * 1000000000ULL + ts.tv_nsec; +#else + return 0; +#endif +} + /* Update the idle time value twice a second, to be called after * tv_update_date() when called after poll(). It relies on to be * updated to the system time before calling poll().