Skip to content

Commit

Permalink
perf stat: Fix trailing comma when there is no metric unit
Browse files Browse the repository at this point in the history
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 <james.clark@linaro.org>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/r/20241112160048.951213-2-james.clark@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
james-c-linaro authored and acmel committed Dec 26, 2024
1 parent 00c6405 commit 9673648
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 87 deletions.
14 changes: 7 additions & 7 deletions tools/perf/tests/shell/lib/perf_json_output_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ def check_json_output(expected_items):
for item in json.loads(input):
if expected_items != -1:
count = len(item)
if count != expected_items and count >= 1 and count <= 7 and 'metric-value' in item:
if count not in expected_items and count >= 1 and count <= 7 and 'metric-value' in item:
# Events that generate >1 metric may have isolated metric
# values and possibly other prefixes like interval, core,
# aggregate-number, or event-runtime/pcnt-running from multiplexing.
pass
elif count != expected_items and count >= 1 and count <= 5 and 'metricgroup' in item:
elif count not in expected_items and count >= 1 and count <= 5 and 'metricgroup' in item:
pass
elif count == expected_items + 1 and 'metric-threshold' in item:
elif count - 1 in expected_items and 'metric-threshold' in item:
pass
elif count != expected_items:
elif count not in expected_items:
raise RuntimeError(f'wrong number of fields. counted {count} expected {expected_items}'
f' in \'{item}\'')
for key, value in item.items():
Expand All @@ -90,11 +90,11 @@ def check_json_output(expected_items):

try:
if args.no_args or args.system_wide or args.event:
expected_items = 7
expected_items = [5, 7]
elif args.interval or args.per_thread or args.system_wide_no_aggr:
expected_items = 8
expected_items = [6, 8]
elif args.per_core or args.per_socket or args.per_node or args.per_die or args.per_cluster or args.per_cache:
expected_items = 9
expected_items = [7, 9]
else:
# If no option is specified, don't check the number of items.
expected_items = -1
Expand Down
Loading

0 comments on commit 9673648

Please sign in to comment.