From 7150da3e4f6ff07bd0b791e77cb2e1fc76c92153 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Thu, 24 Oct 2024 15:58:37 +0200 Subject: [PATCH] cpumf/lshwc: Add flags to display counter values in hex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add flags to display all counter values in hexadecimal format with and without leading 0x indicator. Signed-off-by: Thomas Richter Reviewed-by: Hendrik Brueckner Signed-off-by: Jan Höppner --- cpumf/lshwc.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cpumf/lshwc.c b/cpumf/lshwc.c index 897529f9..8ef61658 100644 --- a/cpumf/lshwc.c +++ b/cpumf/lshwc.c @@ -1,4 +1,4 @@ -/* Copyright IBM Corp. 2021 +/* Copyright IBM Corp. 2021, 2024 * * s390-tools is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -54,6 +54,7 @@ static int cfvn, csvn, authorization; static unsigned long loop_count = 1; static unsigned char *ioctlbuffer; static bool allcpu; +static char *ctrformat = "%ld"; static unsigned int max_possible_cpus; /* No of possible CPUs */ static struct ctrname { /* List of defined counters */ @@ -337,7 +338,7 @@ static void line(char *header) continue; if (comma) putchar(','); - printf("%ld", ctrname[i].ccv[h]); + printf(ctrformat, ctrname[i].ccv[h]); comma = true; } putchar('\n'); @@ -352,7 +353,7 @@ static void line(char *header) continue; if (comma) putchar(','); - printf("%ld", ctrname[i].total); + printf(ctrformat, ctrname[i].total); comma = true; ctrname[i].total = 0; ctrname[i].hitcnt = false; @@ -605,6 +606,14 @@ static struct util_opt opt_vec[] = { .argument = "NUMBER", .desc = "Specifies interval between read operations (seconds)" }, + { + .option = { "hex0x", no_argument, NULL, 'X' }, + .desc = "Counter values in hexadecimal format with leading 0x" + }, + { + .option = { "hex", no_argument, NULL, 'x' }, + .desc = "Counter values in hexadecimal format" + }, UTIL_OPT_HELP, UTIL_OPT_VERSION, UTIL_OPT_END @@ -665,6 +674,12 @@ int main(int argc, char **argv) if (errno || *slash) errx(EXIT_FAILURE, "Invalid argument for -%c", ch); break; + case 'x': + ctrformat = "%lx"; + break; + case 'X': + ctrformat = "%#lx"; + break; case 'a': allcpu = true; break;