2 * lsirq - utility to display kernel interrupt information.
4 * Copyright (C) 2019 zhenwei pi <pizhenwei@bytedance.com>
5 * Copyright (C) 2020 Karel Zak <kzak@redhat.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/types.h>
32 #include <libsmartcols.h>
34 #include "closestream.h"
39 #include "irq-common.h"
41 static int print_irq_data(struct irq_output
*out
, int softirq
)
43 struct libscols_table
*table
;
45 table
= get_scols_table(out
, NULL
, NULL
, softirq
, 0, NULL
);
49 scols_print_table(table
);
50 scols_unref_table(table
);
54 static void __attribute__((__noreturn__
)) usage(void)
56 fputs(USAGE_HEADER
, stdout
);
57 printf(_(" %s [options]\n"), program_invocation_short_name
);
58 fputs(USAGE_SEPARATOR
, stdout
);
60 puts(_("Utility to display kernel interrupt information."));
62 fputs(USAGE_OPTIONS
, stdout
);
63 fputs(_(" -J, --json use JSON output format\n"), stdout
);
64 fputs(_(" -P, --pairs use key=\"value\" output format\n"), stdout
);
65 fputs(_(" -n, --noheadings don't print headings\n"), stdout
);
66 fputs(_(" -o, --output <list> define which output columns to use\n"), stdout
);
67 fputs(_(" -s, --sort <column> specify sort column\n"), stdout
);
68 fputs(_(" -S, --softirq show softirqs instead of interrupts\n"), stdout
);
69 fputs(USAGE_SEPARATOR
, stdout
);
70 printf(USAGE_HELP_OPTIONS(22));
72 fputs(USAGE_COLUMNS
, stdout
);
73 irq_print_columns(stdout
, 1);
75 printf(USAGE_MAN_TAIL("lsirq(1)"));
79 int main(int argc
, char **argv
)
81 struct irq_output out
= {
84 static const struct option longopts
[] = {
85 {"sort", required_argument
, NULL
, 's'},
86 {"noheadings", no_argument
, NULL
, 'n'},
87 {"output", required_argument
, NULL
, 'o'},
88 {"softirq", no_argument
, NULL
, 'S'},
89 {"json", no_argument
, NULL
, 'J'},
90 {"pairs", no_argument
, NULL
, 'P'},
91 {"help", no_argument
, NULL
, 'h'},
92 {"version", no_argument
, NULL
, 'V'},
96 const char *outarg
= NULL
;
97 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
101 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
104 setlocale(LC_ALL
, "");
106 while ((c
= getopt_long(argc
, argv
, "no:s:ShJPV", longopts
, NULL
)) != -1) {
107 err_exclusive_options(c
, longopts
, excl
, excl_st
);
123 set_sort_func_by_name(&out
, optarg
);
129 print_version(EXIT_SUCCESS
);
133 errtryhelp(EXIT_FAILURE
);
139 out
.columns
[out
.ncolumns
++] = COL_IRQ
;
140 out
.columns
[out
.ncolumns
++] = COL_TOTAL
;
141 out
.columns
[out
.ncolumns
++] = COL_NAME
;
144 /* add -o [+]<list> to putput */
145 if (outarg
&& string_add_to_idarray(outarg
, out
.columns
,
146 ARRAY_SIZE(out
.columns
),
148 irq_column_name_to_id
) < 0)
151 return print_irq_data(&out
, softirq
) == 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;