diff --git a/cpumf/lspai.c b/cpumf/lspai.c index 9dfebe99..e831f442 100644 --- a/cpumf/lspai.c +++ b/cpumf/lspai.c @@ -64,6 +64,10 @@ static struct util_opt opt_vec[] = { .option = { "numeric", no_argument, NULL, 'n' }, .desc = "Sort PAI counters by counter number" }, + { + .option = { "short", no_argument, NULL, 's' }, + .desc = "Abbreviate counter name with counter set letter and number" + }, { .option = { "type", required_argument, NULL, 't' }, .argument = "TYPE", @@ -95,6 +99,7 @@ static const struct util_prg prg = { }; static bool numsort; /* If true sort counter numerically */ +static bool shortname; /* Use abbreviated counter names */ static int output_format = -1; /* Generate style if >= 0 */ static unsigned int max_cpus; /* # of CPUs to read counter values from */ static unsigned int max_fds; /* # of file descriptor to read counter values */ @@ -155,6 +160,20 @@ static unsigned long pai_type_base(enum pai_types t) return 0; } +/* Return character for this counter set. */ +static char pai_type_char(enum pai_types t) +{ + switch (t) { + case pai_type_crypto: + return 'C'; + case pai_type_nnpa: + return 'N'; + case pai_type_max: + break; + } + return 'U'; +} + /* Test PAI counter name from command line option. */ static const char *pai_type_name(enum pai_types t) { @@ -259,6 +278,10 @@ static void format_painode(enum util_fmt_t fmt) for (int i = 0; i < node->ctridx; ++i) { util_fmt_obj_start(FMT_ROW, "counter"); util_fmt_pair(FMT_QUOTE, "name", "%s", node->ctrlist[i].name); + if (shortname) + util_fmt_pair(FMT_QUOTE, "name", "%c%d", + pai_type_char(node->type), + node->ctrlist[i].nr - node->base); util_fmt_pair(FMT_DEFAULT, "config", "%d", node->ctrlist[i].nr); util_fmt_pair(FMT_DEFAULT, "id", "%d", node->ctrlist[i].nr - node->base); util_fmt_obj_end(); @@ -380,8 +403,13 @@ static void line_header(void) for (int i = 0; i < node->ctridx; ++i) { if (comma) putchar(','); - printf("%s(%ld)", node->ctrlist[i].name ?: node->name_uc, - node->ctrlist[i].nr - node->base); + if (shortname) { + printf("%c%ld", pai_type_char(node->type), + node->ctrlist[i].nr - node->base); + } else { + printf("%s(%ld)", node->ctrlist[i].name ?: node->name_uc, + node->ctrlist[i].nr - node->base); + } comma = true; } } @@ -433,6 +461,10 @@ static void format_line_out(time_t now, char *now_text) for (int i = 0; i < node->ctridx; ++i) { util_fmt_obj_start(FMT_ROW, "counter"); util_fmt_pair(FMT_QUOTE, "name", "%s", node->ctrlist[i].name); + if (shortname) + util_fmt_pair(FMT_QUOTE, "shortname", "%c%d", + pai_type_char(node->type), + node->ctrlist[i].nr - node->base); util_fmt_pair(FMT_DEFAULT, "config", "%d", node->ctrlist[i].nr); util_fmt_pair(FMT_DEFAULT, "id", "%d", node->ctrlist[i].nr - node->base); util_fmt_pair(FMT_DEFAULT, "value", ctrformat, node->ctrlist[i].total); @@ -664,6 +696,10 @@ int main(int argc, char **argv) case 'n': numsort = true; break; + case 's': + list_only = false; + shortname = true; + break; case 't': check_type_name(optarg); break; diff --git a/cpumf/man/lspai.8 b/cpumf/man/lspai.8 index 62f8aabc..c8c8d64a 100644 --- a/cpumf/man/lspai.8 +++ b/cpumf/man/lspai.8 @@ -30,7 +30,7 @@ .IR SECONDS ] .RB [ \-l .IR COUNT ] -.RB [ \-x ][ \-X ] +.RB [ \-s ][ \-x ][ \-X ] .RI [ CPULIST ] .br \*c @@ -49,6 +49,7 @@ and numbers in various formats. If .I CPULIST is specified or any of the options +.BR \-s , .BR \-x , .BR \-X , .B \-l @@ -76,6 +77,25 @@ Displays help information, then exits. Displays version information, then exits. . .TP +.BR \-s ", " \-\-short +Displays counter names as short names in the heading. +A short name consists of +a letter for the counter set followed by a number. +For example, +this flag displays counter number 0 in the PAI crypto counter +set as +.B C0 +instead of +.BR CRYPTO_ALL . +Valid counter set letters are: +.RS +.IP C +PAI crypto counter set +.IP N +PAI NNPA counter set +.RE +. +.TP .BR \-t ", " \-\-type "\ \fITYPE\fP" Specifies the PAI counter set to list. Valid counter set values are