]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsirq: add new command
authorKarel Zak <kzak@redhat.com>
Fri, 6 Mar 2020 15:21:10 +0000 (16:21 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 6 Mar 2020 15:21:10 +0000 (16:21 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
.gitignore
configure.ac
sys-utils/Makemodule.am
sys-utils/irq-common.c
sys-utils/irq-common.h
sys-utils/irqtop.c
sys-utils/lsirq.1 [new file with mode: 0644]
sys-utils/lsirq.c [new file with mode: 0644]

index 0cd0b90785faf198c752a69c454c3d4ba1b94de2..a6f3791465ffa75a9f2e8ad16acfa32d7d592a6b 100644 (file)
@@ -115,6 +115,7 @@ ylwrap
 /losetup
 /lsblk
 /lsipc
+/lsirq
 /lscpu
 /lslocks
 /lslogins
index 76c23993ee8c08f4acd30bbd6288ffce49779ad0..28852e6d946436f46f13ab3c9a2f45c10be3fb9f 100644 (file)
@@ -1768,14 +1768,28 @@ AC_ARG_ENABLE([ipcs],
 UL_BUILD_INIT([ipcs])
 AM_CONDITIONAL([BUILD_IPCS], [test "x$build_ipcs" = xyes])
 
+
 AC_ARG_ENABLE([irqtop],
   AS_HELP_STRING([--disable-irqtop], [do not build irqtop]),
   [], [UL_DEFAULT_ENABLE([irqtop], [yes])]
 )
 UL_BUILD_INIT([irqtop])
 UL_REQUIRES_LINUX([irqtop])
+UL_REQUIRES_BUILD([irqtop], [libsmartcols])
+UL_REQUIRES_HAVE([irqtop], [open_memstream], [open_memstream function])
+UL_REQUIRES_HAVE([irqtop], [ncursesw,slang,ncurses], [ncursesw, ncurses or slang library])
 AM_CONDITIONAL([BUILD_IRQTOP], [test "x$build_irqtop" = xyes])
 
+AC_ARG_ENABLE([lsirq],
+  AS_HELP_STRING([--disable-lsirq], [do not build lsirq]),
+  [], [UL_DEFAULT_ENABLE([lsirq], [yes])]
+)
+UL_BUILD_INIT([lsirq])
+UL_REQUIRES_LINUX([lsirq])
+UL_REQUIRES_BUILD([lsirq], [libsmartcols])
+AM_CONDITIONAL([BUILD_LSIRQ], [test "x$build_lsirq" = xyes])
+
+
 UL_BUILD_INIT([choom], [check])
 UL_REQUIRES_LINUX([choom])
 AM_CONDITIONAL([BUILD_CHOOM], [test "x$build_choom" = xyes])
index 5a9e8c69226e8a7732339c928390b3f82cf7356d..daeb34f8904841f5e40cfa4938fe71c9805b891f 100644 (file)
@@ -61,6 +61,16 @@ irqtop_LDADD = $(LDADD) libcommon.la $(NCURSES_LIBS) $(REALTIME_LIBS) libsmartco
 irqtop_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS) -I$(ul_libsmartcols_incdir)
 endif
 
+if BUILD_LSIRQ
+usrbin_exec_PROGRAMS += lsirq
+dist_man_MANS += sys-utils/lsirq.1
+lsirq_SOURCES =        sys-utils/lsirq.c \
+               sys-utils/irq-common.c \
+               sys-utils/irq-common.h
+lsirq_LDADD = $(LDADD) libcommon.la libsmartcols.la
+lsirq_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
+endif
+
 if BUILD_LSIPC
 usrbin_exec_PROGRAMS += lsipc
 dist_man_MANS += sys-utils/lsipc.1
index e0f5c720c3535f43e2dcd3b4ee42402d3b06c1c8..f3dc49b4396cdf34532f546c80401fc369cbfd27 100644 (file)
@@ -85,12 +85,15 @@ static inline const struct colinfo *get_column_info(
        return &infos[get_column_id(out, num)];
 }
 
-void irq_print_columns(FILE *f)
+void irq_print_columns(FILE *f, int nodelta)
 {
        size_t i;
 
-       for (i = 0; i < ARRAY_SIZE(infos); i++)
+       for (i = 0; i < ARRAY_SIZE(infos); i++) {
+               if (nodelta && i == COL_DELTA)
+                       continue;
                fprintf(f, "  %-5s  %s\n", infos[i].name, _(infos[i].help));
+       }
 }
 
 static struct libscols_table *new_scols_table(struct irq_output *out)
index a0646b129d8e807f4404d559ec43cfa899267124..f5884b711442c7cf2dab448daa78be812cd9472b 100644 (file)
@@ -48,7 +48,7 @@ struct irq_output {
 int irq_column_name_to_id(char const *const name, size_t const namesz);
 void free_irqstat(struct irq_stat *stat);
 
-void irq_print_columns(FILE *f);
+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);
index 2739e4e352b927caf1e12886ddde076813005db6..107bcdf6dfac67d32b516cc2f43a6801077b0c30 100644 (file)
@@ -232,7 +232,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("  q Q    quit program\n"), stdout);
 
        fputs(USAGE_COLUMNS, stdout);
-       irq_print_columns(stdout);
+       irq_print_columns(stdout, 0);
 
        printf(USAGE_MAN_TAIL("irqtop(1)"));
        exit(EXIT_SUCCESS);
diff --git a/sys-utils/lsirq.1 b/sys-utils/lsirq.1
new file mode 100644 (file)
index 0000000..4050643
--- /dev/null
@@ -0,0 +1,47 @@
+.TH IRQTOP "1" "February 2020" "util-linux" "User Commands"
+.SH NAME
+lsirq \- utility to display kernel interrupt information
+.SH SYNOPSIS
+.B lsirq
+[options]
+.SH DESCRIPTION
+Display kernel interrupt counter information.
+.PP
+The default output is subject to change. So  whenever possible,
+you should avoid using default outputs in your scripts.  Always
+explicitly define expected columns by using \fB\-\-output\fR.
+.SH OPTIONS
+.TP
+.BR \-o , " \-\-output " \fIlist\fP
+Specify which output columns to print.  Use \fB\-\-help\fR to get a list of all supported columns.
+The default list of columns may be extended if list is specified in the format +list.
+.TP
+.BR \-s , " \-\-sort " \fIcolumn\fP
+Specify sort criteria by column name.  See \fB\-\-help\fR output to get column
+names.
+.TP
+.BR \-J , " \-\-json
+Update interrupt output every
+.TP
+.BR \-V ", " \-\-version
+Display version information and exit.
+.TP
+.BR \-h ,\  \-\-help
+Display help text and exit.
+.SH AUTHORS
+.MT pizhenwei@\:bytedance.com
+Zhenwei Pi
+.ME
+.br
+.MT kerolasa@\:iki.fi
+Sami Kerola
+.ME
+.br
+.MT kzak@\:redhat.com 
+Karel Zak
+.ME
+.SH AVAILABILITY
+The example command is part of the util-linux package and is available from
+.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
+Linux Kernel Archive
+.UE .
diff --git a/sys-utils/lsirq.c b/sys-utils/lsirq.c
new file mode 100644 (file)
index 0000000..7853af0
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * lsirq - utility to display kernel interrupt information.
+ *
+ * Copyright (C) 2019 zhenwei pi <pizhenwei@bytedance.com>
+ * Copyright (C) 2020 Karel Zak <kzak@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+#include <ctype.h>
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <libsmartcols.h>
+
+#include "closestream.h"
+#include "strutils.h"
+#include "xalloc.h"
+
+#include "irq-common.h"
+
+static int print_irq_data(struct irq_output *out)
+{
+       struct libscols_table *table;
+
+       table = get_scols_table(out, NULL, NULL);
+       if (!table)
+               return -1;
+
+       scols_print_table(table);
+       scols_unref_table(table);
+       return 0;
+}
+
+static void __attribute__((__noreturn__)) usage(void)
+{
+       fputs(USAGE_HEADER, stdout);
+       printf(_(" %s [options]\n"), program_invocation_short_name);
+       fputs(USAGE_SEPARATOR, stdout);
+
+       puts(_("Utility to display kernel interrupt information."));
+
+       fputs(USAGE_OPTIONS, stdout);
+       fputs(_(" -J, --json           use JSON output format\n"), stdout);
+       fputs(_(" -o, --output <list>  define which output columns to use\n"), stdout);
+       fputs(_(" -s, --sort <column>  specify sort column\n"), stdout);
+       fputs(USAGE_SEPARATOR, stdout);
+       printf(USAGE_HELP_OPTIONS(22));
+
+       fputs(USAGE_COLUMNS, stdout);
+       irq_print_columns(stdout, 1);
+
+       printf(USAGE_MAN_TAIL("lsirq(1)"));
+       exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+       struct irq_output out = {
+               .ncolumns = 0
+       };
+       static const struct option longopts[] = {
+               {"sort", required_argument, NULL, 's'},
+               {"output", required_argument, NULL, 'o'},
+               {"json", no_argument, NULL, 'J'},
+               {"help", no_argument, NULL, 'h'},
+               {"version", no_argument, NULL, 'V'},
+               {NULL, 0, NULL, 0}
+       };
+       int c;
+       const char *outarg = NULL;
+
+       setlocale(LC_ALL, "");
+
+       while ((c = getopt_long(argc, argv, "o:s:hJV", longopts, NULL)) != -1) {
+               switch (c) {
+               case 'J':
+                       out.json = 1;
+                       break;
+               case 'o':
+                       outarg = optarg;
+                       break;
+               case 's':
+                       set_sort_func_by_name(&out, optarg);
+                       break;
+               case 'V':
+                       print_version(EXIT_SUCCESS);
+               case 'h':
+                       usage();
+               default:
+                       errtryhelp(EXIT_FAILURE);
+               }
+       }
+
+       /* default */
+       if (!out.ncolumns) {
+               out.columns[out.ncolumns++] = COL_IRQ;
+               out.columns[out.ncolumns++] = COL_TOTAL;
+               out.columns[out.ncolumns++] = COL_NAME;
+       }
+
+       /* add -o [+]<list> to putput */
+       if (outarg && string_add_to_idarray(outarg, out.columns,
+                               ARRAY_SIZE(out.columns),
+                               &out.ncolumns,
+                               irq_column_name_to_id) < 0)
+               exit(EXIT_FAILURE);
+
+       return print_irq_data(&out) == 0 ?  EXIT_SUCCESS : EXIT_FAILURE;
+}