Test fixes and debug logging
Ian Rogers
reviewercover Test fixes and debug logging
Testing in a hypervisor guest showed some issues that these patches try to address, or improve the debug situation upon.
Ian Rogers (4):
perf test: Be tolerant of missing json metric none value perf parse-events: Add debug logging to perf_event perf test: Don't fail if user rdpmc returns 0 when disabled perf stat-shadow: Display metric-only for 0 counters
tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/shell/lib/perf_json_output_lint.py | 7 +++++-- tools/perf/util/parse-events.c | 2 ++ tools/perf/util/stat-display.c | 3 +++ tools/perf/util/stat-shadow.c | 11 ++++------- 5 files changed, 15 insertions(+), 10 deletions(-)
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Ian Rogers
reviewerPATCH 1/4 perf test: Be tolerant of missing json metric none value
print_metric_only_json and print_metric_end in stat-display.c may create a metric value of "none" which fails validation as isfloat. Add a helper to properly validate metric numeric values.
--- tools/perf/tests/shell/lib/perf_json_output_lint.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/tests/shell/lib/perf_json_output_lint.py +5 -2
@@ -43,6 +43,9 @@ def isint(num): def is_counter_value(num): return isfloat(num) or num == '<not counted>' or num == '<not supported>' +def is_metric_value(num): + return isfloat(num) or num == 'none' + def check_json_output(expected_items): checks = { 'counters': lambda x: isfloat(x),
@@ -57,7 +60,7 @@ def check_json_output(expected_items): 'event-runtime': lambda x: isfloat(x), 'interval': lambda x: isfloat(x), 'metric-unit': lambda x: True, - 'metric-value': lambda x: isfloat(x), + 'metric-value': lambda x: is_metric_value(x), 'metric-threshold': lambda x: x in ['unknown', 'good', 'less good', 'nearly bad', 'bad'], 'metricgroup': lambda x: True, 'node': lambda x: True,
@@ -65,7 +68,7 @@ def check_json_output(expected_items): 'socket': lambda x: True, 'thread': lambda x: True, 'unit': lambda x: True, - 'insn per cycle': lambda x: isfloat(x), + 'insn per cycle': lambda x: is_metric_value(x), 'GHz': lambda x: True, # FIXME: it seems unintended for --metric-only } input = '[\n' + ','.join(Lines) + '\n]'
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Ian Rogers
reviewerPATCH 2/4 perf parse-events: Add debug logging to perf_event
In reply to Ian RogersIf verbose is enabled and parse_event is called, typically by tests, log failures.
--- tools/perf/util/parse-events.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/parse-events.c +2 -0
@@ -2211,6 +2211,8 @@ int parse_event(struct evlist *evlist, const char *str)parse_events_error__init (&err); ret =parse_events (evlist, str, &err); +if (ret && verbose >0 ) +parse_events_error__print (&err, str);parse_events_error__exit (&err);return ret; }
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Ian Rogers
reviewerPATCH 3/4 perf test: Don't fail if user rdpmc returns 0 when disabled
In reply to Ian RogersIn certain hypervisor set ups the value 0 may be returned but this is only erroneous if the user rdpmc isn't disabled.
--- tools/perf/tests/mmap-basic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/mmap-basic.c +1 -1
@@ -322,7 +322,7 @@ static int test_stat_user_read(u64 event, enum user_read_state enabled) }perf_evsel__read (evsel,0 ,0 , &counts); -if (counts.val ==0 ) { +if (rdpmc_supported && counts.val ==0 ) {pr_err ("User space counter reading for PMU %s [Failed read]\n" , pmu->name); ret =TEST_FAIL ; goto cleanup;
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Ian Rogers
reviewerPATCH 4/4 perf stat-shadow: Display metric-only for 0 counters
In reply to Ian Rogers0 counters may occur in hypervisor settings but metric-only output is always expected. This resolves an issue in the "perf stat STD output linter" test.
--- tools/perf/util/stat-display.c | 3 +++ tools/perf/util/stat-shadow.c | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
tools/perf/util/stat-display.c +3 -0
@@ -944,6 +944,9 @@ static bool should_skip_zero_counter(struct perf_stat_config *config,if (verbose ==0 && counter->skippable && !counter->supported)return true; +/* Metric only counts won't be displayed but the metric wants to be computed. */ +if (config->metric_only) +return false;/* * Skip value 0 when enabling --per-thread globally, * otherwise it will have too many 0 output.
tools/perf/util/stat-shadow.c +4 -7
@@ -320,13 +320,10 @@ static void print_instructions(struct perf_stat_config *config,double max_stalled =max (find_stat (evsel, aggr_idx,STAT_STALLED_CYCLES_FRONT ),find_stat (evsel, aggr_idx,STAT_STALLED_CYCLES_BACK )); -if (cycles) { -print_metric (config, ctxp,METRIC_THRESHOLD_UNKNOWN ,"%7.2f " , -"insn per cycle" , instructions / cycles); - }else { -print_metric (config, ctxp,METRIC_THRESHOLD_UNKNOWN ,/*fmt=*/ NULL , -"insn per cycle" ,0 ); - } +print_metric (config, ctxp,METRIC_THRESHOLD_UNKNOWN ,"%7.2f " , +"insn per cycle" , +fpclassify (cycles) ==FP_ZERO ?0 : instructions / cycles); +if (max_stalled && instructions) {if (out->new_line) out->new_line (config, ctxp);
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Quoted 8 lines · Ian Rogers
Testing in a hypervisor guest showed some issues that these patches try to address, or improve the debug situation upon.
Ian Rogers (4):
perf test: Be tolerant of missing json metric none value perf parse-events: Add debug logging toperf_eventperf test: Don't fail if user rdpmc returns 0 when disabled perf stat-shadow: Display metric-only for 0 counters
Applied, but while checking before/after on a host, I see that these are quite unstable:
root@x1:~# perf test -r10 linter 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : FAILED! 99: perf stat STD output linter : FAILED! 99: perf stat STD output linter : Ok 99: perf stat STD output linter : FAILED! 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : FAILED! root@x1:~#
root@x1:~# for a in $(seq 20) ; do perf test linter ; echo "------" ; done 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : FAILED! ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : FAILED! ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ 94: perf stat CSV output linter : FAILED! 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok ------ root@x1:~#
root@x1:~# uname -a Linux x1 6.16.5-200.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep 4 16:37:21 UTC 2025 x86_64 GNU/Linux root@x1:~# grep -m1 "model name" /proc/cpuinfo model name : 13th Gen Intel(R) Core(TM) i7-1365U root@x1:~#
All is well on AMD land:
root@number:~# perf test linter 94: perf stat CSV output linter : Ok 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok root@number:~# perf test -r 5 linter 94: perf stat CSV output linter : Ok 94: perf stat CSV output linter : Ok 94: perf stat CSV output linter : Ok 94: perf stat CSV output linter : Ok 94: perf stat CSV output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 97: perf stat JSON output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok 99: perf stat STD output linter : Ok root@number:~# uname -a Linux number 6.16.7-200.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep 11 17:46:54 UTC 2025 x86_64 GNU/Linux root@number:~# grep -m1 "model name" /proc/cpuinfo model name : AMD Ryzen 9 9950X3D 16-Core Processor root@number:~#
acme@number:~/git/perf-tools-next$ git log --oneline -5 58c26aeac5132152 (HEAD -> perf-tools-next, perf-tools-next/tmp.perf-tools-next) perf stat-shadow: Display metric-only for 0 counters f46533cc149e39bd perf test: Don't fail if user rdpmc returns 0 when disabled 9bb146fd8a342ae1 perf parse-events: Add debug logging to perf_event 64b3eae288bb4370 perf test: Be tolerant of missing json metric none value 0dc96cae063cbf9e perf build-id: Ensure snprintf string is empty when size is 0 acme@number:~/git/perf-tools-next$ sudo su - root@number:~# perf -v perf version 6.17.rc6.g58c26aeac513 root@number:~#
- Arnaldo
Quoted 8 lines · Ian Rogers
Testing in a hypervisor guest showed some issues that these patches try to address, or improve the debug situation upon.
Ian Rogers (4):
perf test: Be tolerant of missing json metric none value perf parse-events: Add debug logging toperf_eventperf test: Don't fail if user rdpmc returns 0 when disabled perf stat-shadow: Display metric-only for 0 counters
Thanks, applied to perf-tools-next,
- Arnaldo
Ian Rogers
reviewerQuoted 5 lines · Arnaldo Carvalho de Melo
Quoted 3 lines · Ian Rogers
Testing in a hypervisor guest showed some issues that these patches try to address, or improve the debug situation upon.
Quoted 7 lines
Quoted 5 lines
Ian Rogers (4):
perf test: Be tolerant of missing json metric none value perf parse-events: Add debug logging toperf_eventperf test: Don't fail if user rdpmc returns 0 when disabled perf stat-shadow: Display metric-only for 0 countersThanks, applied to perf-tools-next,
Thanks Arnaldo,
there was some follow up in:
https://lore.kernel.org/lkml/[email protected]/
I think I've also noticed that logging introducing newlines that impacts the tests column counts. I'll take a further look as we tried to harden against that with an output file option.
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerQuoted 8 lines · Ian Rogers
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Ian Rogers
Ian Rogers (4):
perf test: Be tolerant of missing json metric none value perf parse-events: Add debug logging toperf_eventperf test: Don't fail if user rdpmc returns 0 when disabled perf stat-shadow: Display metric-only for 0 counters
Quoted 7 lines
Quoted 1 line
Thanks, applied to perf-tools-next,
there was some follow up in:
https://lore.kernel.org/lkml/[email protected]/
I think I've also noticed that logging introducing newlines that impacts the tests column counts. I'll take a further look as we tried to harden against that with an output file option.
I'll make sure I get the most uptodate version, if/when available.
I'm attending Kernel Recipes, so there is an additional delay on processing patches, but I should be back processing patches RSN.
- Arnaldo