/*
* irqinfo - parse the system's interrupts
*/
-static struct irq_stat *get_irqinfo(int softirq, size_t setsize, cpu_set_t *cpuset)
+static struct irq_stat *get_irqinfo(const char *input_file, int softirq,
+ size_t setsize, cpu_set_t *cpuset)
{
FILE *irqfile;
char *line = NULL, *tmp;
stat->irq_info = xmalloc(sizeof(*stat->irq_info) * IRQ_INFO_LEN);
stat->nr_irq_info = IRQ_INFO_LEN;
- if (softirq)
- irqfile = fopen(_PATH_PROC_SOFTIRQS, "r");
- else
- irqfile = fopen(_PATH_PROC_INTERRUPTS, "r");
+ irqfile = fopen(input_file, "r");
if (!irqfile) {
- warn(_("cannot open %s"), _PATH_PROC_INTERRUPTS);
+ warn(_("cannot open %s"), input_file);
goto free_stat;
}
/* read header firstly */
if (getline(&line, &len, irqfile) < 0) {
- warn(_("cannot read %s"), _PATH_PROC_INTERRUPTS);
+ warn(_("cannot read %s"), input_file);
goto close_file;
}
stat->cpus = xcalloc(stat->nr_active_cpu, sizeof(struct irq_cpu));
- /* parse each line of _PATH_PROC_INTERRUPTS */
+ /* parse each line of input file */
while (getline(&line, &len, irqfile) >= 0) {
unsigned long count;
size_t index;
return NULL;
}
-struct libscols_table *get_scols_table(struct irq_output *out,
+struct libscols_table *get_scols_table(const char *input_file,
+ struct irq_output *out,
struct irq_stat *prev,
struct irq_stat **xstat,
int softirq,
size_t i;
/* the stats */
- stat = get_irqinfo(softirq, setsize, cpuset);
+ stat = get_irqinfo(input_file, softirq, setsize, cpuset);
if (!stat)
return NULL;
struct irq_stat *stat;
time_t now = time(NULL);
char timestr[64], *data, *data0, *p;
+ char *input_file;
/* make irqs table */
- table = get_scols_table(out, ctl->prev_stat, &stat, ctl->softirq,
- ctl->threshold, ctl->setsize, ctl->cpuset);
+ if (ctl->softirq)
+ input_file = xstrdup(_PATH_PROC_SOFTIRQS);
+ else
+ input_file = xstrdup(_PATH_PROC_INTERRUPTS);
+
+ table = get_scols_table(input_file, out, ctl->prev_stat, &stat,
+ ctl->softirq, ctl->threshold, ctl->setsize,
+ ctl->cpuset);
+ free(input_file);
if (!table) {
ctl->request_exit = 1;
return 1;
#include "optutils.h"
#include "strutils.h"
#include "xalloc.h"
+#include "pathnames.h"
#include "irq-common.h"
-static int print_irq_data(struct irq_output *out,
+static int print_irq_data(const char *input_file, struct irq_output *out,
int softirq, unsigned long threshold,
size_t setsize, cpu_set_t *cpuset)
{
struct libscols_table *table;
- table = get_scols_table(out, NULL, NULL, softirq, threshold, setsize, cpuset);
+ table = get_scols_table(input_file, out, NULL, NULL, softirq, threshold, setsize, cpuset);
if (!table)
return -1;
fputs(USAGE_OPTIONS, stdout);
fputs(_(" -J, --json use JSON output format\n"), stdout);
fputs(_(" -P, --pairs use key=\"value\" output format\n"), stdout);
+ fputs(_(" -i, --input read data from input file\n"), stdout);
fputs(_(" -n, --noheadings don't print headings\n"), stdout);
fputs(_(" -o, --output <list> define which output columns to use\n"), stdout);
fputs(_(" -s, --sort <column> specify sort column\n"), stdout);
static const struct option longopts[] = {
{"sort", required_argument, NULL, 's'},
{"noheadings", no_argument, NULL, 'n'},
+ {"input", required_argument, NULL, 'i'},
{"output", required_argument, NULL, 'o'},
{"threshold", required_argument, NULL, 't'},
{"cpu-list", required_argument, NULL, 'C'},
cpu_set_t *cpuset = NULL;
size_t setsize = 0;
int softirq = 0;
+ char *input_file = NULL;
setlocale(LC_ALL, "");
- while ((c = getopt_long(argc, argv, "no:s:t:C:ShJPV", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "i:no:s:t:C:ShJPV", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
switch (c) {
case 'P':
out.pairs = 1;
break;
+ case 'i':
+ input_file = xstrdup(optarg);
+ break;
case 'n':
out.no_headings = 1;
break;
}
}
+ if (input_file == NULL) {
+ if (softirq == 1)
+ input_file = xstrdup(_PATH_PROC_SOFTIRQS);
+ else
+ input_file = xstrdup(_PATH_PROC_INTERRUPTS);
+ }
+
/* default */
if (!out.ncolumns) {
out.columns[out.ncolumns++] = COL_IRQ;
irq_column_name_to_id) < 0)
exit(EXIT_FAILURE);
- if (print_irq_data(&out, softirq, threshold, setsize, cpuset) < 0)
+ if (print_irq_data(input_file, &out, softirq, threshold, setsize, cpuset) < 0)
return EXIT_FAILURE;
+ free(input_file);
+
return EXIT_SUCCESS;
}