2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * lsirq - utility to display kernel interrupt information.
6 * Copyright (C) 2019 zhenwei pi <pizhenwei@bytedance.com>
7 * Copyright (C) 2020 Karel Zak <kzak@redhat.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
22 #include <sys/types.h>
25 #include <libsmartcols.h>
27 #include "closestream.h"
32 #include "irq-common.h"
34 static int print_irq_data(struct irq_output
*out
, int softirq
)
36 struct libscols_table
*table
;
38 table
= get_scols_table(out
, NULL
, NULL
, softirq
, 0, NULL
);
42 scols_print_table(table
);
43 scols_unref_table(table
);
47 static void __attribute__((__noreturn__
)) usage(void)
49 fputs(USAGE_HEADER
, stdout
);
50 printf(_(" %s [options]\n"), program_invocation_short_name
);
51 fputs(USAGE_SEPARATOR
, stdout
);
53 fputs(_("Utility to display kernel interrupt information."), stdout
);
55 fputs(USAGE_OPTIONS
, stdout
);
56 fputs(_(" -J, --json use JSON output format\n"), stdout
);
57 fputs(_(" -P, --pairs use key=\"value\" output format\n"), stdout
);
58 fputs(_(" -n, --noheadings don't print headings\n"), stdout
);
59 fputs(_(" -o, --output <list> define which output columns to use\n"), stdout
);
60 fputs(_(" -s, --sort <column> specify sort column\n"), stdout
);
61 fputs(_(" -S, --softirq show softirqs instead of interrupts\n"), stdout
);
62 fputs(USAGE_SEPARATOR
, stdout
);
63 fprintf(stdout
, USAGE_HELP_OPTIONS(22));
65 fputs(USAGE_COLUMNS
, stdout
);
66 irq_print_columns(stdout
, 1);
68 fprintf(stdout
, USAGE_MAN_TAIL("lsirq(1)"));
72 int main(int argc
, char **argv
)
74 struct irq_output out
= {
77 static const struct option longopts
[] = {
78 {"sort", required_argument
, NULL
, 's'},
79 {"noheadings", no_argument
, NULL
, 'n'},
80 {"output", required_argument
, NULL
, 'o'},
81 {"softirq", no_argument
, NULL
, 'S'},
82 {"json", no_argument
, NULL
, 'J'},
83 {"pairs", no_argument
, NULL
, 'P'},
84 {"help", no_argument
, NULL
, 'h'},
85 {"version", no_argument
, NULL
, 'V'},
89 const char *outarg
= NULL
;
90 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
94 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
97 setlocale(LC_ALL
, "");
99 while ((c
= getopt_long(argc
, argv
, "no:s:ShJPV", longopts
, NULL
)) != -1) {
100 err_exclusive_options(c
, longopts
, excl
, excl_st
);
116 set_sort_func_by_name(&out
, optarg
);
122 print_version(EXIT_SUCCESS
);
126 errtryhelp(EXIT_FAILURE
);
132 out
.columns
[out
.ncolumns
++] = COL_IRQ
;
133 out
.columns
[out
.ncolumns
++] = COL_TOTAL
;
134 out
.columns
[out
.ncolumns
++] = COL_NAME
;
137 /* add -o [+]<list> to putput */
138 if (outarg
&& string_add_to_idarray(outarg
, out
.columns
,
139 ARRAY_SIZE(out
.columns
),
141 irq_column_name_to_id
) < 0)
144 return print_irq_data(&out
, softirq
) == 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;