[PATCH v2 08/12] tools/arch/x86/pmtctl: Add 'stat --hex'
From: David E. Box
Date: Sun Nov 22 2026 - 14:35:12 EST
Add --hex to 'stat' to print the sampled values in hexadecimal, which
is easier to read for fields that hold flags, IDs or packed data.
Signed-off-by: David E. Box <david.e.box@xxxxxxxxxxxxxxx>
---
V2 changes:
- Split out of v1 14; no change in behavior.
tools/arch/x86/pmtctl/src/cmd_stat.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/tools/arch/x86/pmtctl/src/cmd_stat.c b/tools/arch/x86/pmtctl/src/cmd_stat.c
index 11a2ab1fa341..8377c2d1d194 100644
--- a/tools/arch/x86/pmtctl/src/cmd_stat.c
+++ b/tools/arch/x86/pmtctl/src/cmd_stat.c
@@ -50,6 +50,7 @@ enum {
OPT_STAT_DEVICE,
OPT_STAT_NO_HEADER,
OPT_STAT_VERTICAL,
+ OPT_STAT_HEX,
};
/* A value to sample on each device */
@@ -67,6 +68,7 @@ struct stat_opts {
uint32_t count; /* number of samples, 0 until interrupted */
bool no_header;
bool vertical;
+ bool hex;
};
/* The value of one request on one device */
@@ -127,6 +129,7 @@ static void stat_usage_full(FILE *out)
" -i, --interval <ms> Sampling interval (default 1000 ms).\n"
" -c, --count <N> Number of samples (default infinite).\n"
" --no-header Don't print the header.\n"
+ " --hex Output values in hex.\n"
" --vertical One line per value per sample: sample time_ms device\n"
" metric value. Required for more than one value.\n"
"\n"
@@ -204,6 +207,7 @@ static int stat_parse_options(struct stat_opts *opts, int argc, char **argv)
{ "count", required_argument, NULL, 'c' },
{ "no-header", no_argument, NULL, OPT_STAT_NO_HEADER },
{ "vertical", no_argument, NULL, OPT_STAT_VERTICAL },
+ { "hex", no_argument, NULL, OPT_STAT_HEX },
{}
};
int opt;
@@ -244,6 +248,9 @@ static int stat_parse_options(struct stat_opts *opts, int argc, char **argv)
case OPT_STAT_VERTICAL:
opts->vertical = true;
break;
+ case OPT_STAT_HEX:
+ opts->hex = true;
+ break;
default:
return -EINVAL;
}
@@ -419,7 +426,7 @@ static void print_column(const char *s, size_t width, bool right)
print_chars(' ', pad);
}
-static const char *format_value(const struct stat_cell *cell, char *buf, size_t len)
+static const char *format_value(const struct stat_cell *cell, bool hex, char *buf, size_t len)
{
if (!cell->present)
return STAT_VAL_ABSENT;
@@ -427,6 +434,11 @@ static const char *format_value(const struct stat_cell *cell, char *buf, size_t
if (!cell->valid)
return STAT_VAL_FAILED;
+ if (hex) {
+ snprintf(buf, len, "0x%" PRIx64, cell->value);
+ return buf;
+ }
+
snprintf(buf, len, "%" PRIu64, cell->value);
return buf;
@@ -505,7 +517,8 @@ static void print_sample(const struct stat_run *run, uint64_t sample, uint64_t t
for (size_t r = 0; r < run->opts.num_requests; r++) {
const char *value;
- value = format_value(&row->cells[r], value_buf, sizeof(value_buf));
+ value = format_value(&row->cells[r], run->opts.hex, value_buf,
+ sizeof(value_buf));
print_line_start(run, sample_buf, time_buf, row->dev->name);
if (run->opts.vertical) {
--
2.53.0