From 283ae4dd2f4cc92956e9b09bbe5d2a799f245338 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Wed, 27 Nov 2024 14:36:14 +0100 Subject: [PATCH] cpumf/lshwc: Add flag to hide undefined counters of each counter set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add command line option -H to hide counter value numbers from counters which are not defined in a counter set. They are usually all zero and are of no interest. Signed-off-by: Thomas Richter Reviewed-by: Hendrik Brueckner Signed-off-by: Jan Höppner --- cpumf/lshwc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cpumf/lshwc.c b/cpumf/lshwc.c index bb58bf94..fbd9e210 100644 --- a/cpumf/lshwc.c +++ b/cpumf/lshwc.c @@ -56,6 +56,7 @@ static unsigned char *ioctlbuffer; static bool allcpu; static char *ctrformat = "%ld"; static bool shortname; +static bool hideundef; static unsigned int max_possible_cpus; /* No of possible CPUs */ static struct ctrname { /* List of defined counters */ @@ -343,6 +344,8 @@ static void show_header(void) for (size_t i = 0; i < ARRAY_SIZE(ctrname); ++i) { if (!ctrname[i].hitcnt) continue; + if (hideundef && !ctrname[i].name) + continue; if (comma) putchar(','); if (shortname) { @@ -376,6 +379,8 @@ static void line(char *header) for (size_t i = 0; i < ARRAY_SIZE(ctrname); ++i) { if (!ctrname[i].hitcnt) continue; + if (hideundef && !ctrname[i].name) + continue; if (comma) putchar(','); printf(ctrformat, ctrname[i].ccv[h]); @@ -391,6 +396,8 @@ static void line(char *header) for (size_t i = 0; i < ARRAY_SIZE(ctrname); ++i) { if (!ctrname[i].hitcnt) continue; + if (hideundef && !ctrname[i].name) + continue; if (comma) putchar(','); printf(ctrformat, ctrname[i].total); @@ -658,6 +665,10 @@ static struct util_opt opt_vec[] = { .option = { "hex", no_argument, NULL, 'x' }, .desc = "Counter values in hexadecimal format" }, + { + .option = { "hide", no_argument, NULL, 'H' }, + .desc = "Do not display undefined counters of a counter set" + }, UTIL_OPT_HELP, UTIL_OPT_VERSION, UTIL_OPT_END @@ -718,6 +729,9 @@ int main(int argc, char **argv) if (errno || *slash) errx(EXIT_FAILURE, "Invalid argument for -%c", ch); break; + case 'H': + hideundef = true; + break; case 's': shortname = true; break;