From: zhenwei pi <pizhenwei@bytedance.com>
To: Joe Jin <joe.jin@oracle.com>, Karel Zak <kzak@redhat.com>,
Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH V2 2/4] irqtop: add max iteration support
Date: Mon, 3 Mar 2025 17:39:52 +0800 [thread overview]
Message-ID: <db814aa0-e91b-4a37-81fb-4c849c4a6c0d@bytedance.com> (raw)
In-Reply-To: <20250228161334.82987-3-joe.jin@oracle.com>
On 3/1/25 00:13, Joe Jin wrote:
> Add support for setting the number of iterations. This is useful in
> non-interactive mode.
>
> Signed-off-by: Joe Jin <joe.jin@oracle.com>
> Cc: Zhenwei Pi <pizhenwei@bytedance.com>
> Cc: Sami Kerola <kerolasa@iki.fi>
> Cc: Karel Zak <kzak@redhat.com>
> ---
> bash-completion/irqtop | 5 +++++
> sys-utils/irqtop.1.adoc | 3 +++
> sys-utils/irqtop.c | 19 +++++++++++++++++--
> 3 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/bash-completion/irqtop b/bash-completion/irqtop
> index 215281ee8..d18ef99bb 100644
> --- a/bash-completion/irqtop
> +++ b/bash-completion/irqtop
> @@ -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
> diff --git a/sys-utils/irqtop.1.adoc b/sys-utils/irqtop.1.adoc
> index e81f4fbb6..75930f5cf 100644
> --- a/sys-utils/irqtop.1.adoc
> +++ b/sys-utils/irqtop.1.adoc
> @@ -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.
>
> diff --git a/sys-utils/irqtop.c b/sys-utils/irqtop.c
> index 81a137be0..17c7d72cb 100644
> --- a/sys-utils/irqtop.c
> +++ b/sys-utils/irqtop.c
> @@ -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;
> }
If ctl->iter is initialized as int64_max, then we have codes like:
if (--ctl->iter == 0) {
ctl->request_exit = 1;
}
>
> @@ -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, "");
next prev parent reply other threads:[~2025-03-03 9:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 16:13 [PATCH V2 0/4] irqtop,lsirq: Miscellaneous enhancements Joe Jin
2025-02-28 16:13 ` [PATCH V2 1/4] irqtop: add batch mode support Joe Jin
2025-02-28 16:13 ` [PATCH V2 2/4] irqtop: add max iteration support Joe Jin
2025-03-03 9:39 ` zhenwei pi [this message]
2025-03-04 1:39 ` Joe Jin
2025-03-04 3:49 ` zhenwei pi
2025-02-28 16:13 ` [PATCH V2 3/4] irqtop: support json output format Joe Jin
2025-02-28 16:13 ` [PATCH V2 4/4] lsirq: add support for reading data from given file Joe Jin
2025-03-03 10:16 ` [PATCH V2 0/4] irqtop,lsirq: Miscellaneous enhancements Karel Zak
2025-03-04 1:38 ` Joe Jin
2025-03-04 3:50 ` zhenwei pi
2025-03-04 10:58 ` Karel Zak
2025-03-05 2:23 ` Joe Jin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=db814aa0-e91b-4a37-81fb-4c849c4a6c0d@bytedance.com \
--to=pizhenwei@bytedance.com \
--cc=joe.jin@oracle.com \
--cc=kerolasa@iki.fi \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox