From: Willy Tarreau Date: Mon, 20 May 2019 18:28:34 +0000 (+0200) Subject: MINOR: time: add a function to retrieve another thread's cputime X-Git-Tag: v2.0-dev4~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=219b829b623f66636efb7ddcc07a7e24b0aa9f63;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/common/time.h b/include/common/time.h index 0790873272..9920a77ae1 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().