Skip to content

Commit ad2483b

Browse files
james-c-linarogregkh
authored andcommitted
perf stat: Fix trailing comma when there is no metric unit
[ Upstream commit 9673648 ] Now that printing metric-value and metric-unit is optional, print_running_json() shouldn't add the comma in case it becomes trailing. Replace all manual JSON comma stuff with a json_out() function that uses the existing os->first tracking and auto inserts a comma if it's needed. Update the test to handle that two of the fields can be missing. This fixes the following test failure on Cortex A57 where the branch misses metric is missing a required event: $ perf test -vvv "json output" 106: perf stat JSON output linter: --- start --- test child forked, pid 665682 Checking json output: no args Test failed for input: {"counter-value" : "3112.000000", "unit" : "", "event" : "armv8_pmuv3_1/branch-misses/", "event-runtime" : 20699340, "pcnt-running" : 100.00, } ... json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 12 column 144 (char 2109) ---- end(-1) ---- 106: perf stat JSON output linter : FAILED! Fixes: e1cc918 ("perf stat: Drop metric-unit if unit is NULL") Signed-off-by: James Clark <[email protected]> Tested-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tim Chen <[email protected]> Cc: Yicong Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 3d635b1 commit ad2483b

File tree

2 files changed

+104
-87
lines changed

2 files changed

+104
-87
lines changed

tools/perf/tests/shell/lib/perf_json_output_lint.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ def check_json_output(expected_items):
6969
for item in json.loads(input):
7070
if expected_items != -1:
7171
count = len(item)
72-
if count != expected_items and count >= 1 and count <= 7 and 'metric-value' in item:
72+
if count not in expected_items and count >= 1 and count <= 7 and 'metric-value' in item:
7373
# Events that generate >1 metric may have isolated metric
7474
# values and possibly other prefixes like interval, core,
7575
# aggregate-number, or event-runtime/pcnt-running from multiplexing.
7676
pass
77-
elif count != expected_items and count >= 1 and count <= 5 and 'metricgroup' in item:
77+
elif count not in expected_items and count >= 1 and count <= 5 and 'metricgroup' in item:
7878
pass
79-
elif count == expected_items + 1 and 'metric-threshold' in item:
79+
elif count - 1 in expected_items and 'metric-threshold' in item:
8080
pass
81-
elif count != expected_items:
81+
elif count not in expected_items:
8282
raise RuntimeError(f'wrong number of fields. counted {count} expected {expected_items}'
8383
f' in \'{item}\'')
8484
for key, value in item.items():
@@ -90,11 +90,11 @@ def check_json_output(expected_items):
9090

9191
try:
9292
if args.no_args or args.system_wide or args.event:
93-
expected_items = 7
93+
expected_items = [5, 7]
9494
elif args.interval or args.per_thread or args.system_wide_no_aggr:
95-
expected_items = 8
95+
expected_items = [6, 8]
9696
elif args.per_core or args.per_socket or args.per_node or args.per_die or args.per_cluster or args.per_cache:
97-
expected_items = 9
97+
expected_items = [7, 9]
9898
else:
9999
# If no option is specified, don't check the number of items.
100100
expected_items = -1

0 commit comments

Comments
 (0)