]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsirq,irqtop: add threshold option
authorRobin Jarry <robin@jarry.cc>
Tue, 5 Nov 2024 10:22:06 +0000 (11:22 +0100)
committerRobin Jarry <robin@jarry.cc>
Wed, 6 Nov 2024 10:06:11 +0000 (11:06 +0100)
Add a new option to filter out IRQs whose counters are below the
specified value. The argument supports plain integers and human readable
values (e.g. 1.2K).

Signed-off-by: Robin Jarry <robin@jarry.cc>
bash-completion/irqtop
bash-completion/lsirq
sys-utils/irq-common.c
sys-utils/irq-common.h
sys-utils/irqtop.1.adoc
sys-utils/irqtop.c
sys-utils/lsirq.1.adoc
sys-utils/lsirq.c

index 7688f673c4ba1bd7e2a33d23c043fa759e2bda19..b9e454d4cb270389e6a61dcdfd094408dbc43af0 100644 (file)
@@ -12,6 +12,9 @@ _irqtop_module()
                '-C'|'--cpu-list')
                        return 0
                        ;;
+               '-t'|'--threshold')
+                       return 0
+                       ;;
                '-d'|'--delay')
                        COMPREPLY=( $(compgen -W "secs" -- $cur) )
                        return 0
@@ -43,6 +46,7 @@ _irqtop_module()
                --sort
                --output
                --softirq
+               --threshold
                --help
                --version"
        COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
index 09893d8141392ef861823a8a51d7cd99ba7b0a89..d4dd19efa3c383fe2a2b7eb6e744011e8f8a163c 100644 (file)
@@ -22,6 +22,9 @@ _lsirq_module()
                        COMPREPLY=( $(compgen -W "irq total name" -- $cur) )
                        return 0
                        ;;
+               '-t'|'--threshold')
+                       return 0
+                       ;;
                '-h'|'--help'|'-V'|'--version')
                        return 0
                        ;;
@@ -32,6 +35,7 @@ _lsirq_module()
                --output
                --softirq
                --sort
+               --threshold
                --help
                --version"
        COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
index 82a7757600737b1306a3411ab3c1f6a3024c21d9..11d28d234230d6c43f4cfcb284a0a083d2f083d2 100644 (file)
@@ -530,6 +530,7 @@ struct libscols_table *get_scols_table(struct irq_output *out,
                                              struct irq_stat *prev,
                                              struct irq_stat **xstat,
                                              int softirq,
+                                             unsigned long threshold,
                                              size_t setsize,
                                              cpu_set_t *cpuset)
 {
@@ -568,7 +569,8 @@ struct libscols_table *get_scols_table(struct irq_output *out,
        }
 
        for (i = 0; i < stat->nr_irq; i++)
-               add_scols_line(out, &result[i], table);
+               if (result[i].total >= threshold)
+                       add_scols_line(out, &result[i], table);
 
        free(result);
 
index 97366da033259a63556d4b57a354fb14632f6eef..cb68c58e524dd55f4e87513ce6a1a00c4190d6cf 100644 (file)
@@ -76,6 +76,7 @@ struct libscols_table *get_scols_table(struct irq_output *out,
                                               struct irq_stat *prev,
                                               struct irq_stat **xstat,
                                               int softirq,
+                                              unsigned long threshold,
                                               size_t setsize,
                                               cpu_set_t *cpuset);
 
index dc6f8dbe1e6eb9e5e8aefbbb42258650766f8c3a..443e23b84368907fa5c92f97a0f6b4d94f16a9cb 100644 (file)
@@ -40,6 +40,9 @@ Specify sort criteria by column name. See *--help* output to get column names. T
 *-S*, *--softirq*::
 Show softirqs information.
 
+*-t*, *--threshold* _min_::
+Only show IRQs with counters above the specified threshold. Human readable values are supported (e.g. 1.2K).
+
 include::man-common/help-version.adoc[]
 
 == INTERACTIVE MODE KEY COMMANDS
@@ -64,6 +67,7 @@ stop updates and exit program
 mailto:pizhenwei@bytedance.com[Zhenwei Pi],
 mailto:kerolasa@iki.fi[Sami Kerola],
 mailto:kzak@redhat.com[Karel Zak]
+mailto:robin@jarry.cc[Robin Jarry]
 
 include::man-common/bugreports.adoc[]
 
index 877e2b83600e3f82d68f83e042d9f463e7fa2e5b..0a732a1c3f704c5dd81eb9964cc8e1c6820b486f 100644 (file)
@@ -5,6 +5,7 @@
  *
  * Copyright (C) 2019 zhenwei pi <pizhenwei@bytedance.com>
  * Copyright (C) 2020 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2024 Robin Jarry <robin@jarry.cc>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -77,6 +78,7 @@ struct irqtop_ctl {
 
        struct itimerspec timer;
        struct irq_stat *prev_stat;
+       uintmax_t threshold;
        size_t setsize;
        cpu_set_t *cpuset;
 
@@ -107,8 +109,8 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
        char timestr[64], *data, *data0, *p;
 
        /* make irqs table */
-       table = get_scols_table(out, ctl->prev_stat, &stat, ctl->softirq, ctl->setsize,
-                               ctl->cpuset);
+       table = get_scols_table(out, ctl->prev_stat, &stat, ctl->softirq,
+                               ctl->threshold, ctl->setsize, ctl->cpuset);
        if (!table) {
                ctl->request_exit = 1;
                return 1;
@@ -264,6 +266,7 @@ static void __attribute__((__noreturn__)) usage(void)
        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);
+       fputs(_(" -t, --threshold <N>  only IRQs with counters above <N>\n"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(22));
 
@@ -294,13 +297,14 @@ static void parse_args(   struct irqtop_ctl *ctl,
                {"sort", required_argument, NULL, 's'},
                {"output", required_argument, NULL, 'o'},
                {"softirq", no_argument, NULL, 'S'},
+               {"threshold", required_argument, NULL, 't'},
                {"help", no_argument, NULL, 'h'},
                {"version", no_argument, NULL, 'V'},
                {NULL, 0, NULL, 0}
        };
        int o;
 
-       while ((o = getopt_long(argc, argv, "c:C:d:o:s:ShV", longopts, NULL)) != -1) {
+       while ((o = getopt_long(argc, argv, "c:C:d:o:s:St:hV", longopts, NULL)) != -1) {
                switch (o) {
                case 'c':
                        if (!strcmp(optarg, "auto"))
@@ -346,6 +350,9 @@ static void parse_args(     struct irqtop_ctl *ctl,
                case 'S':
                        ctl->softirq = 1;
                        break;
+               case 't':
+                       ctl->threshold = strtosize_or_err(optarg, _("error: --threshold"));
+                       break;
                case 'V':
                        print_version(EXIT_SUCCESS);
                case 'h':
index 67bd69023b8fd425c560e57ad8e06d2cc26b117e..8839af0e6b5ee6408a26061e0d16b8b8190699b4 100644 (file)
@@ -40,6 +40,9 @@ Produce output in the form of key="value" pairs. All potentially unsafe characte
 *-S*, *--softirq*::
 Show softirqs information.
 
+*-t*, *--threshold* _min_::
+Only show IRQs with counters above the specified threshold. Human readable values are supported (e.g. 1.2K).
+
 include::man-common/help-version.adoc[]
 
 == AUTHORS
@@ -47,6 +50,7 @@ include::man-common/help-version.adoc[]
 mailto:pizhenwei@bytedance.com[Zhenwei Pi],
 mailto:kerolasa@iki.fi[Sami Kerola],
 mailto:kzak@redhat.com[Karel Zak]
+mailto:robin@jarry.cc[Robin Jarry]
 
 include::man-common/bugreports.adoc[]
 
index 2b283d33cd629972a73674d93468a57dd6f98d80..6a2536068d680a936496e5194d89d56990a56a20 100644 (file)
@@ -5,6 +5,7 @@
  *
  * Copyright (C) 2019 zhenwei pi <pizhenwei@bytedance.com>
  * Copyright (C) 2020 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2024 Robin Jarry <robin@jarry.cc>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 
 #include "irq-common.h"
 
-static int print_irq_data(struct irq_output *out, int softirq)
+static int print_irq_data(struct irq_output *out,
+                         int softirq, unsigned long threshold)
 {
        struct libscols_table *table;
 
-       table = get_scols_table(out, NULL, NULL, softirq, 0, NULL);
+       table = get_scols_table(out, NULL, NULL, softirq, threshold, 0, NULL);
        if (!table)
                return -1;
 
@@ -59,6 +61,7 @@ static void __attribute__((__noreturn__)) usage(void)
        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);
+       fputs(_(" -t, --threshold <N>  only IRQs with counters above <N>\n"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(22));
 
@@ -78,6 +81,7 @@ int main(int argc, char **argv)
                {"sort", required_argument, NULL, 's'},
                {"noheadings", no_argument, NULL, 'n'},
                {"output", required_argument, NULL, 'o'},
+               {"threshold", required_argument, NULL, 't'},
                {"softirq", no_argument, NULL, 'S'},
                {"json", no_argument, NULL, 'J'},
                {"pairs", no_argument, NULL, 'P'},
@@ -92,11 +96,12 @@ int main(int argc, char **argv)
                {0}
        };
        int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+       uintmax_t threshold = 0;
        int softirq = 0;
 
        setlocale(LC_ALL, "");
 
-       while ((c = getopt_long(argc, argv, "no:s:ShJPV", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "no:s:t:ShJPV", longopts, NULL)) != -1) {
                err_exclusive_options(c, longopts, excl, excl_st);
 
                switch (c) {
@@ -118,6 +123,9 @@ int main(int argc, char **argv)
                case 'S':
                        softirq = 1;
                        break;
+               case 't':
+                       threshold = strtosize_or_err(optarg, _("error: --threshold"));
+                       break;
                case 'V':
                        print_version(EXIT_SUCCESS);
                case 'h':
@@ -141,5 +149,8 @@ int main(int argc, char **argv)
                                irq_column_name_to_id) < 0)
                exit(EXIT_FAILURE);
 
-       return print_irq_data(&out, softirq) == 0 ?  EXIT_SUCCESS : EXIT_FAILURE;
+       if (print_irq_data(&out, softirq, threshold) < 0)
+               return EXIT_FAILURE;
+
+       return EXIT_SUCCESS;
 }