]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: time: add a function to retrieve another thread's cputime
authorWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 18:28:34 +0000 (20:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 19:14:14 +0000 (21:14 +0200)
now_cpu_time_thread() does the same as now_cpu_time() but for another
thread based on its clockid.

include/common/time.h

index 0790873272c965a1b504de63a6b5b5fb3f586340..9920a77ae1afb1be3c8660387dfcaf883b58ea23 100644 (file)
@@ -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 <before_poll> to be
  * updated to the system time before calling poll().