]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: report each thread's cpu usage in "show thread"
authorWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 18:52:20 +0000 (20:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 19:14:14 +0000 (21:14 +0200)
Now we can report each thread's CPU time, both at wake up (poll) and
retrieved while dumping (now), then the difference, which directly
indicates how long the thread has been running uninterrupted. A very
high value for the diff could indicate a deadlock, especially if it
happens between two threads. Note that it may occasionally happen
that a wrong value is displayed since nothing guarantees that the
date is read atomically.

src/debug.c

index ecb55f59077632ee4a40bf345239bd3785396104..ba668781e9b5bfa9c4d57040756577e7aa233b24 100644 (file)
@@ -38,6 +38,8 @@
 void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
 {
        unsigned long thr_bit = 1UL << thr;
+       unsigned long long p = thread_info[thr].prev_cpu_time;
+       unsigned long long n = now_cpu_time_thread(&thread_info[thr]);
 
        chunk_appendf(buf,
                      "%c Thread %-2u: act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n"
@@ -61,6 +63,7 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
 #endif
 
        chunk_appendf(buf, "\n");
+       chunk_appendf(buf, "             cpu_ns: poll=%llu now=%llu diff=%llu\n", p, n, n-p);
 
        /* this is the end of what we can dump from outside the thread */