From: Donald Sharp Date: Thu, 10 Nov 2016 19:25:39 +0000 (-0500) Subject: lib: Fix 'show thread cpu' to display active threads X-Git-Tag: frr-3.0-branchpoint~64^2~10^2~107 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e4fe5b196e6228fdbd221db1f9ffe09cf9930c09;p=mirror%2Ffrr.git lib: Fix 'show thread cpu' to display active threads Fix the display of 'show thread cpu' to keep track of the number of active threads and to display that information. Signed-off-by: Donald Sharp --- diff --git a/lib/thread.c b/lib/thread.c index 59c0b77b90..ba1386af21 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -221,8 +221,8 @@ static void vty_out_cpu_thread_history(struct vty* vty, struct cpu_thread_history *a) { - vty_out(vty, "%10ld.%03ld %9d %8ld %9ld %8ld %9ld", - a->cpu.total/1000, a->cpu.total%1000, a->total_calls, + vty_out(vty, "%5d %10ld.%03ld %9d %8ld %9ld %8ld %9ld", + a->total_active, a->cpu.total/1000, a->cpu.total%1000, a->total_calls, a->cpu.total/a->total_calls, a->cpu.max, a->real.total/a->total_calls, a->real.max); vty_out(vty, " %c%c%c%c%c%c %s%s", @@ -247,6 +247,7 @@ cpu_record_hash_print(struct hash_backet *bucket, if ( !(a->types & *filter) ) return; vty_out_cpu_thread_history(vty,a); + totals->total_active += a->total_active; totals->total_calls += a->total_calls; totals->real.total += a->real.total; if (totals->real.max < a->real.max) @@ -268,7 +269,7 @@ cpu_record_print(struct vty *vty, thread_type filter) vty_out(vty, "%21s %18s %18s%s", "", "CPU (user+system):", "Real (wall-clock):", VTY_NEWLINE); - vty_out(vty, " Runtime(ms) Invoked Avg uSec Max uSecs"); + vty_out(vty, "Active Runtime(ms) Invoked Avg uSec Max uSecs"); vty_out(vty, " Avg uSec Max uSecs"); vty_out(vty, " Type Thread%s", VTY_NEWLINE); hash_iterate(cpu_record, @@ -572,6 +573,7 @@ thread_add_unuse (struct thread_master *m, struct thread *thread) assert (thread->prev == NULL); thread->type = THREAD_UNUSED; + thread->hist->total_active--; thread_list_add (&m->unuse, thread); } @@ -726,6 +728,7 @@ thread_get (struct thread_master *m, u_char type, thread->hist = hash_get (cpu_record, &tmp, (void * (*) (void *))cpu_record_hash_alloc); } + thread->hist->total_active++; thread->func = func; thread->funcname = funcname; thread->schedfrom = schedfrom; diff --git a/lib/thread.h b/lib/thread.h index 5c6b96a32d..c22bb4828d 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -115,6 +115,7 @@ struct cpu_thread_history { int (*func)(struct thread *); unsigned int total_calls; + unsigned int total_active; struct time_stats { unsigned long total, max;