[cmaster-next] [PATCH 6/9] lib: Fix 'show thread cpu' to display active threads
Donald Sharp
sharpd at cumulusnetworks.com
Wed Dec 14 15:49:50 EST 2016
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 <sharpd at cumulusnetworks.com>
(cherry picked from commit db4300f0568d061889ab5ac4ad54c2a5bfa67445)
---
lib/thread.c | 9 ++++++---
lib/thread.h | 1 +
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/thread.c b/lib/thread.c
index 59c0b77..ba1386a 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 5c6b96a..c22bb48 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;
--
2.5.5
More information about the dev
mailing list