From 11b20fb29d96b2a93ccbda77d470634d10352e93 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 21 Feb 2020 22:28:43 +0000 Subject: [PATCH] irqtop: display number of new interupts in-between updates The rirst output is total count followed by number of interupts since previous screen update. This is how the irqtop worked before libsmartcols was added to the command. Signed-off-by: Sami Kerola --- sys-utils/irqtop.1 | 4 ++++ sys-utils/irqtop.c | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/sys-utils/irqtop.1 b/sys-utils/irqtop.1 index 4353c23f40..97e24f6bde 100644 --- a/sys-utils/irqtop.1 +++ b/sys-utils/irqtop.1 @@ -27,6 +27,7 @@ interactive mode will make the ncurses output to be ordered accordingly. .PP .RS .PD 0 +.\" Key commands are in alphabetical order .TP .B c sort by increase count of each interrupt (the default) @@ -39,6 +40,9 @@ sort by name .TP .B q Q stop updates and exit program +.TP +.B t +alterate displaying delta and totals count .PD .RE .TP diff --git a/sys-utils/irqtop.c b/sys-utils/irqtop.c index ef3b275db7..bdb8c3b877 100644 --- a/sys-utils/irqtop.c +++ b/sys-utils/irqtop.c @@ -119,7 +119,7 @@ struct irqtop_ctl { struct timeval uptime_tv; int (*sort_func)(const struct irq_info *, const struct irq_info *); long smp_num_cpus; - struct irq_stat *last_stat; + struct irq_stat *prev_stat; char *hostname; struct libscols_table *table; struct libscols_line *outline; @@ -129,6 +129,7 @@ struct irqtop_ctl { json:1, no_headings:1, request_exit:1, + display_total:1, run_once:1; }; @@ -396,6 +397,8 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" c: sort by increase count of each interrupt\n"), stdout); fputs(_(" i: sort by default interrupts from proc interrupt\n"), stdout); fputs(_(" n: sort by name\n"), stdout); + fputs(_(" q Q: stop updates and exit program\n"), stdout); + fputs(_(" t: alterate displaying delta and totals count\n"), stdout); fputs(USAGE_COLUMNS, stdout); for (i = 0; i < ARRAY_SIZE(infos); i++) @@ -431,6 +434,9 @@ static void parse_input(struct irqtop_ctl *ctl, char c) case 'n': ctl->sort_func = sort_name; break; + case 't': + ctl->display_total = !ctl->display_total; + break; case 'q': case 'Q': ctl->request_exit = 1; @@ -496,8 +502,13 @@ static int update_screen(struct irqtop_ctl *ctl) size = sizeof(*stat->irq_info) * stat->nr_irq; result = xmalloc(size); memcpy(result, stat->irq_info, size); + if (!ctl->display_total) { + for (index = 0; ctl->prev_stat && index < stat->nr_irq; index++) + result[index].count -= ctl->prev_stat->irq_info[index].count; + } sort_result(ctl, result, stat->nr_irq); - for (index = 0; index < choose_smaller(ctl->rows - RESERVE_ROWS, stat->nr_irq); index++) { + size = choose_smaller(ctl->rows - RESERVE_ROWS, stat->nr_irq); + for (index = 0; index < size; index++) { curr = result + index; add_scols_line(ctl, curr); } @@ -514,6 +525,11 @@ static int update_screen(struct irqtop_ctl *ctl) } scols_unref_table(ctl->table); + if (!ctl->display_total) { + if (ctl->prev_stat) + free_irqinfo(ctl->prev_stat); + ctl->prev_stat = stat; + } return 0; } @@ -695,7 +711,7 @@ int main(int argc, char **argv) else event_loop(&ctl); - free_irqinfo(ctl.last_stat); + free_irqinfo(ctl.prev_stat); free(ctl.hostname); if (is_tty) -- 2.47.2