irqtop,lsirq: Miscellaneous enhancements
v2 cover irqtop,lsirq: Miscellaneous enhancements
This patchset add below new options for irqtop:
'-b|--batch' : Batch mode '-n|--iter' : Specifies the maximum number of iterations '-J|--json' : Json ouput format
Add below for lsirq:
'-i|--input' : Read data from file
v2:
- Removed macro irqtop_batch_mode.
- Replaced macro irqtop_printf() to inline function
- Changed option '--number' to '--iter'
- Replace strdup() to xstrdup()
- Added json output format for irqtop.
- Remove irqtop input file support.
Joe Jin (4):
irqtop: add batch mode support
irqtop: add max iteration support
irqtop: support json output format
lsirq: add support for reading data from given file
bash-completion/irqtop | 12 +++- bash-completion/lsirq | 4 ++ sys-utils/irq-common.c | 19 +++--- sys-utils/irq-common.h | 3 +- sys-utils/irqtop.1.adoc | 9 +++ sys-utils/irqtop.c | 124 +++++++++++++++++++++++++++++++--------- sys-utils/lsirq.1.adoc | 3 + sys-utils/lsirq.c | 24 ++++++-- 8 files changed, 155 insertions(+), 43 deletions(-)
Signature · 1 line
2.43.5
PATCH v2 1/4 irqtop: add batch mode support
Add batch mode support, which could be useful for sending output to other programs or to a file.
--- bash-completion/irqtop | 6 ++- sys-utils/irqtop.1.adoc | 3 ++ sys-utils/irqtop.c | 89 ++++++++++++++++++++++++++++++----------- 3 files changed, 73 insertions(+), 25 deletions(-)
bash-completion/irqtop +5 -1
@@ -5,6 +5,9 @@ _irqtop_module() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" case $prev in + '-b'|'--batch') + return 0 + ;; '-c'|'--cpu-stat') COMPREPLY=( $(compgen -W "auto enable disable" -- $cur) ) return 0
@@ -40,7 +43,8 @@ _irqtop_module() return 0 ;; esac - OPTS=" --cpu-stat + OPTS=" --batch + --cpu-stat --cpu-list --delay --sort
sys-utils/irqtop.1.adoc +3 -0
@@ -25,6 +25,9 @@ The default output is subject to change. So whenever possible, you should avoid *-o*, *--output* _list_:: Specify which output columns to print. Use *--help* to get a list of all supported columns. The default list of columns may be extended if list is specified in the format _+list_. +*-b*, *--batch*:: +Starts irqtop in batch mode, which could be useful for sending output to other programs or to a file. + *-c*, *--cpu-stat* _mode_:: Show per-cpu statistics by specified mode. Available modes are: *auto*, *enable*, *disable*. The default option *auto* detects the width of window, then shows the per-cpu statistics if the width of window is large enough to show a full line of statistics.
sys-utils/irqtop.c +65 -24
174 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 2/4 irqtop: add max iteration support
In reply to Joe JinAdd support for setting the number of iterations. This is useful in non-interactive mode.
--- bash-completion/irqtop | 5 +++++ sys-utils/irqtop.1.adoc | 3 +++ sys-utils/irqtop.c | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-)
bash-completion/irqtop +5 -0
@@ -22,6 +22,10 @@ _irqtop_module() COMPREPLY=( $(compgen -W "secs" -- $cur) ) return 0 ;; + '-n'|'--iter') + COMPREPLY=( $(compgen -W "the max iterations" -- $cur) ) + return 0 + ;; '-s'|'--sort') COMPREPLY=( $(compgen -W "irq total delta name" -- $cur) ) return 0
@@ -47,6 +51,7 @@ _irqtop_module() --cpu-stat --cpu-list --delay + --iter --sort --output --softirq
sys-utils/irqtop.1.adoc +3 -0
@@ -37,6 +37,9 @@ Specify cpus in list format to show. *-d*, *--delay* _seconds_:: Update interrupt output every _seconds_ intervals. +*-n*, *--iter* _number_:: +Specifies the maximum iterations before quitting. + *-s*, *--sort* _column_:: Specify sort criteria by column name. See *--help* output to get column names. The sort criteria may be changes in interactive mode.
sys-utils/irqtop.c +17 -2
@@ -83,6 +83,7 @@ struct irqtop_ctl {cpu_set_t *cpuset;enum irqtop_cpustat_mode cpustat_mode; +int64_t iter;bool batch;bool request_exit, softirq;
@@ -190,6 +191,12 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)if (ctl->prev_stat)free_irqstat (ctl->prev_stat); ctl->prev_stat = stat; + +if (ctl->iter >0 ) { + ctl->iter--; +if (ctl->iter ==0 ) + ctl->request_exit =1 ; + }return 0 ; }
@@ -295,6 +302,7 @@ static void __attribute__((__noreturn__)) usage(void)fputs (_ (" -c, --cpu-stat <mode> show per-cpu stat (auto, enable, disable)\n" ), stdout);fputs (_ (" -C, --cpu-list <list> specify cpus in list format\n" ), stdout);fputs (_ (" -d, --delay <secs> delay updates\n" ), stdout); +fputs (_ (" -n, --iter <number> the maximum number of iterations\n" ), stdout);fputs (_ (" -o, --output <list> define which output columns to use\n" ), stdout);fputs (_ (" -s, --sort <column> specify sort column\n" ), stdout);fputs (_ (" -S, --softirq show softirqs instead of interrupts\n" ), stdout);
@@ -327,6 +335,7 @@ static void parse_args( struct irqtop_ctl *ctl, {"cpu-stat", required_argument, NULL, 'c'}, {"cpu-list", required_argument, NULL, 'C'}, {"delay", required_argument, NULL, 'd'}, + {"iter", required_argument, NULL, 'n'}, {"sort", required_argument, NULL, 's'}, {"output", required_argument, NULL, 'o'}, {"softirq", no_argument, NULL, 'S'},
@@ -337,7 +346,7 @@ static void parse_args( struct irqtop_ctl *ctl, };int o; -while ((o =getopt_long (argc, argv,"bc:C:d:o:s:St:hV" , longopts,NULL )) !=-1 ) { +while ((o =getopt_long (argc, argv,"bc:C:d:n:o:s:St:hV" , longopts,NULL )) !=-1 ) {switch (o) {case 'b' : ctl->batch =1 ;
@@ -377,6 +386,11 @@ static void parse_args( struct irqtop_ctl *ctl, ctl->timer.it_value = ctl->timer.it_interval; }break ; +case 'n' : + ctl->iter =str2num_or_err (optarg,10 , +_ ("failed to parse iter argument" ), +0 ,INT_MAX ); +break ;case 's' :set_sort_func_by_name (out, optarg);break ;
@@ -423,7 +437,8 @@ int main(int argc, char **argv) };struct irqtop_ctl ctl = { .timer.it_interval = {3 ,0 }, - .timer.it_value = {3 ,0 } + .timer.it_value = {3 ,0 }, + .iter =-1 };setlocale (LC_ALL ,"" );
Signature · 1 line
2.43.5
Re: [PATCH V2 2/4] irqtop: add max iteration support
Quoted 64 lines · Joe Jin
Add support for setting the number of iterations. This is useful in non-interactive mode.
Signed-off-by Joe Jin <[email protected]>Cc Zhenwei Pi <[email protected]>Cc Sami Kerola <[email protected]>Cc Karel Zak <[email protected]>--- bash-completion/irqtop | 5 +++++ sys-utils/irqtop.1.adoc | 3 +++ sys-utils/irqtop.c | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-)bash-completion/irqtop +5
-0@@ -22,6 +22,10 @@ _irqtop_module() COMPREPLY=( $(compgen -W "secs" -- $cur) ) return 0 ;; + '-n'|'--iter') + COMPREPLY=( $(compgen -W "the max iterations" -- $cur) ) + return 0 + ;; '-s'|'--sort') COMPREPLY=( $(compgen -W "irq total delta name" -- $cur) ) return 0@@ -47,6 +51,7 @@ _irqtop_module() --cpu-stat --cpu-list --delay + --iter --sort --output --softirqsys-utils/irqtop.1.adoc +3
-0@@ -37,6 +37,9 @@ Specify cpus in list format to show. *-d*, *--delay* _seconds_:: Update interrupt output every _seconds_ intervals. +*-n*, *--iter* _number_:: +Specifies the maximum iterations before quitting. + *-s*, *--sort* _column_:: Specify sort criteria by column name. See *--help* output to get column names. The sort criteria may be changes in interactive mode.sys-utils/irqtop.c +1
-0@@ -83,6 +83,7 @@ struct irqtop_ctl {cpu_set_t *cpuset;enum irqtop_cpustat_mode cpustat_mode; +int64_t iter;bool batch;bool request_exit, softirq;@@ -190,6 +191,12 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)if (ctl->prev_stat)
sys-utils/irqtop.c static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out) · line 201
Quoted 10 lines
sys-utils/irqtop.c +6
-0free_irqstat (ctl->prev_stat); ctl->prev_stat = stat; + +if (ctl->iter >0 ) { + ctl->iter--; +if (ctl->iter ==0 ) + ctl->request_exit =1 ; + }return 0 ; }
If ctl->iter is initialized as int64_max, then we have codes like:
if (--ctl->iter == 0) {
ctl->request_exit = 1;
}Quoted 48 lines
sys-utils/irqtop.c +10
-2@@ -295,6 +302,7 @@ static void __attribute__((__noreturn__)) usage(void)fputs (_ (" -c, --cpu-stat <mode> show per-cpu stat (auto, enable, disable)\n" ), stdout);fputs (_ (" -C, --cpu-list <list> specify cpus in list format\n" ), stdout);fputs (_ (" -d, --delay <secs> delay updates\n" ), stdout); +fputs (_ (" -n, --iter <number> the maximum number of iterations\n" ), stdout);fputs (_ (" -o, --output <list> define which output columns to use\n" ), stdout);fputs (_ (" -s, --sort <column> specify sort column\n" ), stdout);fputs (_ (" -S, --softirq show softirqs instead of interrupts\n" ), stdout);@@ -327,6 +335,7 @@ static void parse_args( struct irqtop_ctl *ctl, {"cpu-stat", required_argument, NULL, 'c'}, {"cpu-list", required_argument, NULL, 'C'}, {"delay", required_argument, NULL, 'd'}, + {"iter", required_argument, NULL, 'n'}, {"sort", required_argument, NULL, 's'}, {"output", required_argument, NULL, 'o'}, {"softirq", no_argument, NULL, 'S'},@@ -337,7 +346,7 @@ static void parse_args( struct irqtop_ctl *ctl, };int o; -while ((o =getopt_long (argc, argv,"bc:C:d:o:s:St:hV" , longopts,NULL )) !=-1 ) { +while ((o =getopt_long (argc, argv,"bc:C:d:n:o:s:St:hV" , longopts,NULL )) !=-1 ) {switch (o) {case 'b' : ctl->batch =1 ;@@ -377,6 +386,11 @@ static void parse_args( struct irqtop_ctl *ctl, ctl->timer.it_value = ctl->timer.it_interval; }break ; +case 'n' : + ctl->iter =str2num_or_err (optarg,10 , +_ ("failed to parse iter argument" ), +0 ,INT_MAX ); +break ;case 's' :set_sort_func_by_name (out, optarg);break ;@@ -423,7 +437,8 @@ int main(int argc, char **argv) };struct irqtop_ctl ctl = { .timer.it_interval = {3 ,0 }, - .timer.it_value = {3 ,0 } + .timer.it_value = {3 ,0 }, + .iter =-1 };setlocale (LC_ALL ,"" );
Re: [PATCH V2 2/4] irqtop: add max iteration support
Quoted 77 lines · zhenwei pi
Quoted 61 lines · Joe Jin
Add support for setting the number of iterations. This is useful in non-interactive mode.
Signed-off-by Joe Jin <[email protected]>Cc Zhenwei Pi <[email protected]>Cc Sami Kerola <[email protected]>Cc Karel Zak <[email protected]>---
bash-completion/irqtop | 5 +++++ sys-utils/irqtop.1.adoc | 3 +++ sys-utils/irqtop.c | 19 +++++++++++++++++--3 files changed, 25 insertions(+), 2 deletions(-)bash-completion/irqtop +0
-0@@ -22,6 +22,10 @@ _irqtop_module() COMPREPLY=( $(compgen -W "secs" -- $cur) )return 0
;;
+ '-n'|'--iter')
+ COMPREPLY=( $(compgen -W "the max iterations" -- $cur) ) + return 0
+ ;;
'-s'|'--sort')
COMPREPLY=( $(compgen -W "irq total delta name" -- $cur) ) return 0bash-completion/irqtop +0
-0@@ -47,6 +51,7 @@ _irqtop_module()--cpu-stat
--cpu-list
--delay
+ --iter
--sort
--output
--softirqsys-utils/irqtop.1.adoc +0
-0@@ -37,6 +37,9 @@ Specify cpus in list format to show. *-d*, *--delay* _seconds_::Update interrupt output every _seconds_ intervals. +*-n*, *--iter* _number_::
sys-utils/irqtop.1.adoc +2
-0+Specifies the maximum iterations before quitting. +*-s*, *--sort* _column_::
Specify sort criteria by column name. See *--help* output to get column names. The sort criteria may be changes in interactive mode. diff --gita/sys-utils/irqtop.cb/sys-utils/irqtop.c
index81a137be0..17c7d72cb100644sys-utils/irqtop.c +1
-0@@ -83,6 +83,7 @@ struct irqtop_ctl { cpu_set_t *cpuset; enum irqtop_cpustat_mode cpustat_mode; + int64_t iter; bool batch; bool request_exit, softirq;@@ -190,6 +191,12 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out) if (ctl->prev_stat)sys-utils/irqtop.c static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out) · line 201
Quoted 10 lines
sys-utils/irqtop.c +6
-0free_irqstat(ctl->prev_stat); ctl->prev_stat = stat; + + if (ctl->iter > 0) { + ctl->iter--; + if (ctl->iter == 0) + ctl->request_exit = 1; + } return 0; }If
ctl->iteris initialized asint64_max, then we have codes like:
Quoted 3 lines
if (--ctl->iter == 0) {
ctl->request_exit= 1;
}
Yes they are exactly same.
As Karel has queued for CI test, maybe keep current code?
Thanks,
Joe
Quoted 47 lines
Quoted 46 lines
sys-utils/irqtop.c +0
-0@@ -295,6 +302,7 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_(" -c, --cpu-stat <mode> show per-cpu stat (auto, enable, disable)\n"), stdout);fputs(_(" -C, --cpu-list <list> specify cpus in list format\n"), stdout);fputs(_(" -d, --delay <secs> delay updates\n"), stdout);
+fputs(_(" -n, --iter <number> the maximum number of iterations\n"), stdout);fputs(_(" -o, --output <list> define which output columns to use\n"), stdout);fputs(_(" -s, --sort <column> specify sort column\n"), stdout);fputs(_(" -S, --softirq show softirqs instead of interrupts\n"), stdout);sys-utils/irqtop.c +2
-0@@ -327,6 +335,7 @@ static void parse_args( struct irqtop_ctl *ctl, {"cpu-stat", required_argument, NULL, 'c'}, {"cpu-list", required_argument, NULL, 'C'}, {"delay", required_argument, NULL, 'd'}, + {"iter", required_argument, NULL, 'n'}, {"sort", required_argument, NULL, 's'}, {"output", required_argument, NULL, 'o'}, {"softirq", no_argument, NULL, 'S'},@@ -337,7 +346,7 @@ static void parse_args( struct irqtop_ctl *ctl, }; int o; - while ((o = getopt_long(argc, argv, "bc:C:d:o:s:St:hV", longopts, NULL)) != -1) { + while ((o = getopt_long(argc, argv, "bc:C:d:n:o:s:St:hV", longopts, NULL)) != -1) { switch (o) {case 'b':
ctl->batch= 1;sys-utils/irqtop.c +5
-0@@ -377,6 +386,11 @@ static void parse_args( struct irqtop_ctl *ctl, ctl->timer.it_value = ctl->timer.it_interval; } break; + case 'n': + ctl->iter = str2num_or_err(optarg, 10, + _("failed to parse iter argument"), + 0, INT_MAX); + break;case 's':
set_sort_func_by_name(out, optarg); break;sys-utils/irqtop.c +2
-1@@ -423,7 +437,8 @@ int main(int argc, char **argv) }; struct irqtop_ctl ctl = { .timer.it_interval = {3, 0}, - .timer.it_value = {3, 0} + .timer.it_value = {3, 0}, + .iter = -1 }; setlocale(LC_ALL, "");
Re: Re: [PATCH V2 2/4] irqtop: add max iteration support
Quoted 7 lines
Quoted 6 lines
If
ctl->iteris initialized asint64_max, then we have codes like:if (--ctl->iter == 0) {
ctl->request_exit= 1;
}
Quoted 5 lines
Yes they are exactly same.
As Karel has queued for CI test, maybe keep current code?Thanks,
Joe
Fine.
PATCH v2 3/4 irqtop: support json output format
In reply to Joe Jin--- bash-completion/irqtop | 1 + sys-utils/irqtop.1.adoc | 3 +++ sys-utils/irqtop.c | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-)
bash-completion/irqtop +1 -0
@@ -48,6 +48,7 @@ _irqtop_module() ;; esac OPTS=" --batch + --json --cpu-stat --cpu-list --delay
sys-utils/irqtop.1.adoc +3 -0
@@ -37,6 +37,9 @@ Specify cpus in list format to show. *-d*, *--delay* _seconds_:: Update interrupt output every _seconds_ intervals. +*-J*, *--json*:: +Use JSON output format. irqtop will run in batch mode. + *-n*, *--iter* _number_:: Specifies the maximum iterations before quitting.
sys-utils/irqtop.c +7 -1
@@ -302,6 +302,7 @@ static void __attribute__((__noreturn__)) usage(void)fputs (_ (" -c, --cpu-stat <mode> show per-cpu stat (auto, enable, disable)\n" ), stdout);fputs (_ (" -C, --cpu-list <list> specify cpus in list format\n" ), stdout);fputs (_ (" -d, --delay <secs> delay updates\n" ), stdout); +fputs (_ (" -J, --json use JSON output format (will run in batch mode)\n" ), stdout);fputs (_ (" -n, --iter <number> the maximum number of iterations\n" ), stdout);fputs (_ (" -o, --output <list> define which output columns to use\n" ), stdout);fputs (_ (" -s, --sort <column> specify sort column\n" ), stdout);
@@ -336,6 +337,7 @@ static void parse_args( struct irqtop_ctl *ctl, {"cpu-list", required_argument, NULL, 'C'}, {"delay", required_argument, NULL, 'd'}, {"iter", required_argument, NULL, 'n'}, + {"json", no_argument, NULL, 'J'}, {"sort", required_argument, NULL, 's'}, {"output", required_argument, NULL, 'o'}, {"softirq", no_argument, NULL, 'S'},
@@ -346,7 +348,7 @@ static void parse_args( struct irqtop_ctl *ctl, };int o; -while ((o =getopt_long (argc, argv,"bc:C:d:n:o:s:St:hV" , longopts,NULL )) !=-1 ) { +while ((o =getopt_long (argc, argv,"bc:C:d:Jn:o:s:St:hV" , longopts,NULL )) !=-1 ) {switch (o) {case 'b' : ctl->batch =1 ;
@@ -386,6 +388,10 @@ static void parse_args( struct irqtop_ctl *ctl, ctl->timer.it_value = ctl->timer.it_interval; }break ; +case 'J' : + out->json =1 ; + ctl->batch =1 ; +break ;case 'n' : ctl->iter = str2num_or_err(optarg, 10, _("failed to parse iter argument"),
Signature · 1 line
2.43.5
PATCH v2 4/4 lsirq: add support for reading data from given file
In reply to Joe JinThis is helpful for analyzng data saved from other system.
--- bash-completion/lsirq | 4 ++++ sys-utils/irq-common.c | 19 +++++++++---------- sys-utils/irq-common.h | 3 ++- sys-utils/irqtop.c | 12 ++++++++++-- sys-utils/lsirq.1.adoc | 3 +++ sys-utils/lsirq.c | 24 ++++++++++++++++++++---- 6 files changed, 48 insertions(+), 17 deletions(-)
bash-completion/lsirq +4 -0
@@ -5,6 +5,9 @@ _lsirq_module() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" case $prev in + '-i'|'--input') + COMPREPLY=( $(compgen -W "input file" -- $cur) ) + ;; '-o'|'--output') local prefix realcur OUTPUT realcur="${cur##*,}"
@@ -35,6 +38,7 @@ _lsirq_module() OPTS=" --json --pairs --noheadings + --input --output --softirq --sort
sys-utils/irq-common.c +9 -10
@@ -233,7 +233,8 @@ static bool cpu_in_list(int cpu, size_t setsize, cpu_set_t *cpuset)/* * irqinfo - parse the system's interrupts */ -static struct irq_stat *get_irqinfo (int softirq,size_t setsize,cpu_set_t *cpuset) +static struct irq_stat *get_irqinfo (const char *input_file,int softirq, +size_t setsize,cpu_set_t *cpuset) {FILE *irqfile;char *line =NULL , *tmp;
@@ -247,18 +248,15 @@ static struct irq_stat *get_irqinfo(int softirq, size_t setsize, cpu_set_t *cpus stat->irq_info =xmalloc (sizeof (*stat->irq_info) *IRQ_INFO_LEN ); stat->nr_irq_info =IRQ_INFO_LEN ; -if (softirq) - irqfile =fopen (_PATH_PROC_SOFTIRQS,"r" ); -else - irqfile =fopen (_PATH_PROC_INTERRUPTS,"r" ); + irqfile =fopen (input_file,"r" );if (!irqfile) { -warn (_ ("cannot open %s" ), _PATH_PROC_INTERRUPTS); +warn (_ ("cannot open %s" ), input_file); goto free_stat; }/* read header firstly */ if (getline (&line, &len, irqfile) <0 ) { -warn (_ ("cannot read %s" ), _PATH_PROC_INTERRUPTS); +warn (_ ("cannot read %s" ), input_file); goto close_file; }
@@ -270,7 +268,7 @@ static struct irq_stat *get_irqinfo(int softirq, size_t setsize, cpu_set_t *cpus stat->cpus =xcalloc (stat->nr_active_cpu,sizeof (struct irq_cpu )); -/* parse each line of _PATH_PROC_INTERRUPTS */ +/* parse each line of input file */ while (getline (&line, &len, irqfile) >=0 ) {unsigned long count;size_t index;
@@ -527,7 +525,8 @@ struct libscols_table *get_scols_cpus_table(struct irq_output *out,return NULL ; } -struct libscols_table *get_scols_table(struct irq_output *out, +struct libscols_table *get_scols_table(const char *input_file, + struct irq_output *out, struct irq_stat *prev, struct irq_stat **xstat, int softirq,
@@ -542,7 +541,7 @@ struct libscols_table *get_scols_table(struct irq_output *out,size_t i;/* the stats */ - stat =get_irqinfo (softirq, setsize, cpuset); + stat =get_irqinfo (input_file, softirq, setsize, cpuset);if (!stat)return NULL ;
sys-utils/irq-common.h +2 -1
@@ -73,7 +73,8 @@ void irq_print_columns(FILE *f, int nodelta);void set_sort_func_by_name (struct irq_output *out,const char *name);void set_sort_func_by_key (struct irq_output *out,const char c); -struct libscols_table *get_scols_table(struct irq_output *out, +struct libscols_table *get_scols_table(const char *input_file, + struct irq_output *out, struct irq_stat *prev, struct irq_stat **xstat, int softirq,
sys-utils/irqtop.c +10 -2
@@ -130,10 +130,18 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)struct irq_stat *stat;time_t now =time (NULL );char timestr[64 ], *data, *data0, *p; +char *input_file;/* make irqs table */ - table =get_scols_table (out, ctl->prev_stat, &stat, ctl->softirq, - ctl->threshold, ctl->setsize, ctl->cpuset); +if (ctl->softirq) + input_file =xstrdup (_PATH_PROC_SOFTIRQS); +else + input_file =xstrdup (_PATH_PROC_INTERRUPTS); + + table =get_scols_table (input_file, out, ctl->prev_stat, &stat, + ctl->softirq, ctl->threshold, ctl->setsize, + ctl->cpuset); +free (input_file);if (!table) { ctl->request_exit =1 ;return 1 ;
sys-utils/lsirq.1.adoc +3 -0
@@ -25,6 +25,9 @@ The default output is subject to change. So whenever possible, you should avoid *-n*, *--noheadings*:: Don't print headings. +*-i*, *--input* _file_:: +Read data from _file_ (Which was created by other tools, e.g. sosreport). + *-o*, *--output* _list_:: Specify which output columns to print. Use *--help* to get a list of all supported columns. The default list of columns may be extended if list is specified in the format _+list_.
sys-utils/lsirq.c +20 -4
@@ -29,16 +29,17 @@#include "optutils.h" #include "strutils.h" #include "xalloc.h" +#include "pathnames.h" #include "irq-common.h" -static int print_irq_data (struct irq_output *out, +static int print_irq_data (const char *input_file,struct irq_output *out,int softirq,unsigned long threshold,size_t setsize,cpu_set_t *cpuset) {struct libscols_table *table; - table =get_scols_table (out,NULL ,NULL , softirq, threshold, setsize, cpuset); + table =get_scols_table (input_file, out,NULL ,NULL , softirq, threshold, setsize, cpuset);if (!table)return -1 ;
@@ -58,6 +59,7 @@ static void __attribute__((__noreturn__)) usage(void)fputs (USAGE_OPTIONS , stdout);fputs (_ (" -J, --json use JSON output format\n" ), stdout);fputs (_ (" -P, --pairs use key=\"value\" output format\n" ), stdout); +fputs (_ (" -i, --input read data from input file\n" ), stdout);fputs (_ (" -n, --noheadings don't print headings\n" ), stdout);fputs (_ (" -o, --output <list> define which output columns to use\n" ), stdout);fputs (_ (" -s, --sort <column> specify sort column\n" ), stdout);
@@ -82,6 +84,7 @@ int main(int argc, char **argv)static const struct option longopts[] = { {"sort" , required_argument,NULL ,'s' }, {"noheadings" , no_argument,NULL ,'n' }, + {"input" , required_argument,NULL ,'i' }, {"output" , required_argument,NULL ,'o' }, {"threshold" , required_argument,NULL ,'t' }, {"cpu-list" , required_argument,NULL ,'C' },
@@ -103,10 +106,11 @@ int main(int argc, char **argv)cpu_set_t *cpuset =NULL ;size_t setsize =0 ;int softirq =0 ; +char *input_file =NULL ;setlocale (LC_ALL ,"" ); -while ((c =getopt_long (argc, argv,"no:s:t:C:ShJPV" , longopts,NULL )) !=-1 ) { +while ((c =getopt_long (argc, argv,"i:no:s:t:C:ShJPV" , longopts,NULL )) !=-1 ) {err_exclusive_options (c, longopts, excl, excl_st);switch (c) {
@@ -116,6 +120,9 @@ int main(int argc, char **argv)case 'P' : out.pairs =1 ;break ; +case 'i' : + input_file =xstrdup (optarg); +break ;case 'n' : out.no_headings =1 ;break ;
@@ -157,6 +164,13 @@ int main(int argc, char **argv) } } +if (input_file ==NULL ) { +if (softirq ==1 ) + input_file =xstrdup (_PATH_PROC_SOFTIRQS); +else + input_file =xstrdup (_PATH_PROC_INTERRUPTS); + } +/* default */ if (!out.ncolumns) { out.columns[out.ncolumns++] =COL_IRQ ;
@@ -171,8 +185,10 @@ int main(int argc, char **argv) irq_column_name_to_id) < 0)exit (EXIT_FAILURE ); -if (print_irq_data (&out, softirq, threshold, setsize, cpuset) <0 ) +if (print_irq_data (input_file, &out, softirq, threshold, setsize, cpuset) <0 )return EXIT_FAILURE ; +free (input_file); +return EXIT_SUCCESS ; }
Signature · 1 line
2.43.5
Karel Zak
maintainerQuoted 22 lines · Joe Jin
This patchset add below new options for irqtop:
'-b|--batch' : Batch mode '-n|--iter' : Specifies the maximum number of iterations '-J|--json' : Json ouput formatAdd below for lsirq:
'-i|--input' : Read data from filev2:
- Removed macroirqtop_batch_mode.
- Replaced macroirqtop_printf()to inline function
- Changed option '--number' to '--iter'
- Replacestrdup()toxstrdup()
- Added json output format for irqtop.
- Remove irqtop input file support.Joe Jin (4):
irqtop: add batch mode support
irqtop: add max iteration support
irqtop: support json output format
lsirq: add support for reading data from given file
Quoted 9 lines
bash-completion/irqtop | 12 +++- bash-completion/lsirq | 4 ++ sys-utils/irq-common.c | 19 +++--- sys-utils/irq-common.h | 3 +- sys-utils/irqtop.1.adoc | 9 +++ sys-utils/irqtop.c | 124 +++++++++++++++++++++++++++++++--------- sys-utils/lsirq.1.adoc | 3 + sys-utils/lsirq.c | 24 ++++++-- 8 files changed, 155 insertions(+), 43 deletions(-)
Thanks for the update. I have created a PR
(https://github.com/util-linux/util-linux/pull/3435) to test it with CI tests.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 32 lines · Karel Zak
Quoted 22 lines · Joe Jin
This patchset add below new options for irqtop:
'-b|--batch' : Batch mode '-n|--iter' : Specifies the maximum number of iterations '-J|--json' : Json ouput formatAdd below for lsirq:
'-i|--input' : Read data from filev2:
- Removed macroirqtop_batch_mode.
- Replaced macroirqtop_printf()to inline function
- Changed option '--number' to '--iter'
- Replacestrdup()toxstrdup()
- Added json output format for irqtop.
- Remove irqtop input file support.Joe Jin (4):
irqtop: add batch mode support
irqtop: add max iteration support
irqtop: support json output format
lsirq: add support for reading data from given fileQuoted 9 lines
bash-completion/irqtop | 12 +++- bash-completion/lsirq | 4 ++ sys-utils/irq-common.c | 19 +++--- sys-utils/irq-common.h | 3 +- sys-utils/irqtop.1.adoc | 9 +++ sys-utils/irqtop.c | 124 +++++++++++++++++++++++++++++++--------- sys-utils/lsirq.1.adoc | 3 + sys-utils/lsirq.c | 24 ++++++-- 8 files changed, 155 insertions(+), 43 deletions(-)
Quoted 3 lines
Thanks for the update. I have created a PR
(https://github.com/util-linux/util-linux/pull/3435) to test it with CI tests.
Thanks so much!
Quoted 2 lines
Karel
zhenwei pi
Reviewed-byThis series looks good to me!
Quoted 43 lines · Joe Jin
Quoted 32 lines · Karel Zak
Quoted 22 lines · Joe Jin
This patchset add below new options for irqtop:
'-b|--batch' : Batch mode '-n|--iter' : Specifies the maximum number of iterations '-J|--json' : Json ouput formatAdd below for lsirq:
'-i|--input' : Read data from filev2:
- Removed macroirqtop_batch_mode.
- Replaced macroirqtop_printf()to inline function
- Changed option '--number' to '--iter'
- Replacestrdup()toxstrdup()
- Added json output format for irqtop.
- Remove irqtop input file support.Joe Jin (4):
irqtop: add batch mode support
irqtop: add max iteration support
irqtop: support json output format
lsirq: add support for reading data from given fileQuoted 9 lines
bash-completion/irqtop | 12 +++- bash-completion/lsirq | 4 ++ sys-utils/irq-common.c | 19 +++--- sys-utils/irq-common.h | 3 +- sys-utils/irqtop.1.adoc | 9 +++ sys-utils/irqtop.c | 124 +++++++++++++++++++++++++++++++--------- sys-utils/lsirq.1.adoc | 3 + sys-utils/lsirq.c | 24 ++++++-- 8 files changed, 155 insertions(+), 43 deletions(-)Quoted 3 lines
Thanks for the update. I have created a PR
(https://github.com/util-linux/util-linux/pull/3435) to test it with CI tests.Thanks so much!
Quoted 2 lines
Karel
Quoted 14 lines · Joe Jin
v2:
- Removed macroirqtop_batch_mode.
- Replaced macroirqtop_printf()to inline function
- Changed option '--number' to '--iter'
- Replacestrdup()toxstrdup()
- Added json output format for irqtop.
- Remove irqtop input file support.Joe Jin (4):
irqtop: add batch mode support
irqtop: add max iteration support
irqtop: support json output format
lsirq: add support for reading data from given file
Quoted 9 lines
bash-completion/irqtop | 12 +++- bash-completion/lsirq | 4 ++ sys-utils/irq-common.c | 19 +++--- sys-utils/irq-common.h | 3 +- sys-utils/irqtop.1.adoc | 9 +++ sys-utils/irqtop.c | 124 +++++++++++++++++++++++++++++++--------- sys-utils/lsirq.1.adoc | 3 + sys-utils/lsirq.c | 24 ++++++-- 8 files changed, 155 insertions(+), 43 deletions(-)
Applied, thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 24 lines · Karel Zak
Quoted 14 lines · Joe Jin
v2:
- Removed macroirqtop_batch_mode.
- Replaced macroirqtop_printf()to inline function
- Changed option '--number' to '--iter'
- Replacestrdup()toxstrdup()
- Added json output format for irqtop.
- Remove irqtop input file support.Joe Jin (4):
irqtop: add batch mode support
irqtop: add max iteration support
irqtop: support json output format
lsirq: add support for reading data from given fileQuoted 9 lines
bash-completion/irqtop | 12 +++- bash-completion/lsirq | 4 ++ sys-utils/irq-common.c | 19 +++--- sys-utils/irq-common.h | 3 +- sys-utils/irqtop.1.adoc | 9 +++ sys-utils/irqtop.c | 124 +++++++++++++++++++++++++++++++--------- sys-utils/lsirq.1.adoc | 3 + sys-utils/lsirq.c | 24 ++++++-- 8 files changed, 155 insertions(+), 43 deletions(-)
Quoted 1 line
Applied, thanks.
Thanks so much!
Quoted 3 lines
Karel