mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-11 20:39:55 +00:00
The recent --per-cache option test caused a problem. According to the
option name, I think it should check args.per_cache instead of
args.per_cache_instance.
$ sudo ./perf test -v 99
99: perf stat JSON output linter :
--- start ---
test child forked, pid 3086101
Checking json output: no args [Success]
Checking json output: system wide [Success]
Checking json output: interval [Success]
Checking json output: event [Success]
Checking json output: per thread [Success]
Checking json output: per node [Success]
Checking json output: system wide no aggregation [Success]
Checking json output: per core [Success]
Checking json output: per cache_instance Test failed for input:
...
Traceback (most recent call last):
File "linux/tools/perf/tests/shell/lib/perf_json_output_lint.py", line 88, in <module>
elif args.per_core or args.per_socket or args.per_node or args.per_die or args.per_cache_instance:
AttributeError: 'Namespace' object has no attribute 'per_cache_instance'
test child finished with -1
---- end ----
perf stat JSON output linter: FAILED!
Fixes: bfce728db3 ("pert tests: Add tests for new "perf stat --per-cache" aggregation option")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230524210600.3095830-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
97 lines
3.1 KiB
Python
97 lines
3.1 KiB
Python
#!/usr/bin/python
|
|
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
|
# Basic sanity check of perf JSON output as specified in the man page.
|
|
|
|
import argparse
|
|
import sys
|
|
import json
|
|
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument('--no-args', action='store_true')
|
|
ap.add_argument('--interval', action='store_true')
|
|
ap.add_argument('--system-wide-no-aggr', action='store_true')
|
|
ap.add_argument('--system-wide', action='store_true')
|
|
ap.add_argument('--event', action='store_true')
|
|
ap.add_argument('--per-core', action='store_true')
|
|
ap.add_argument('--per-thread', action='store_true')
|
|
ap.add_argument('--per-cache', action='store_true')
|
|
ap.add_argument('--per-die', action='store_true')
|
|
ap.add_argument('--per-node', action='store_true')
|
|
ap.add_argument('--per-socket', action='store_true')
|
|
ap.add_argument('--file', type=argparse.FileType('r'), default=sys.stdin)
|
|
args = ap.parse_args()
|
|
|
|
Lines = args.file.readlines()
|
|
|
|
def isfloat(num):
|
|
try:
|
|
float(num)
|
|
return True
|
|
except ValueError:
|
|
return False
|
|
|
|
|
|
def isint(num):
|
|
try:
|
|
int(num)
|
|
return True
|
|
except ValueError:
|
|
return False
|
|
|
|
def is_counter_value(num):
|
|
return isfloat(num) or num == '<not counted>' or num == '<not supported>'
|
|
|
|
def check_json_output(expected_items):
|
|
checks = {
|
|
'aggregate-number': lambda x: isfloat(x),
|
|
'core': lambda x: True,
|
|
'counter-value': lambda x: is_counter_value(x),
|
|
'cgroup': lambda x: True,
|
|
'cpu': lambda x: isint(x),
|
|
'cache': lambda x: True,
|
|
'die': lambda x: True,
|
|
'event': lambda x: True,
|
|
'event-runtime': lambda x: isfloat(x),
|
|
'interval': lambda x: isfloat(x),
|
|
'metric-unit': lambda x: True,
|
|
'metric-value': lambda x: isfloat(x),
|
|
'node': lambda x: True,
|
|
'pcnt-running': lambda x: isfloat(x),
|
|
'socket': lambda x: True,
|
|
'thread': lambda x: True,
|
|
'unit': lambda x: True,
|
|
}
|
|
input = '[\n' + ','.join(Lines) + '\n]'
|
|
for item in json.loads(input):
|
|
if expected_items != -1:
|
|
count = len(item)
|
|
if count != expected_items and count >= 1 and count <= 4 and 'metric-value' in item:
|
|
# Events that generate >1 metric may have isolated metric
|
|
# values and possibly other prefixes like interval, core and
|
|
# aggregate-number.
|
|
pass
|
|
elif count != expected_items:
|
|
raise RuntimeError(f'wrong number of fields. counted {count} expected {expected_items}'
|
|
f' in \'{item}\'')
|
|
for key, value in item.items():
|
|
if key not in checks:
|
|
raise RuntimeError(f'Unexpected key: key={key} value={value}')
|
|
if not checks[key](value):
|
|
raise RuntimeError(f'Check failed for: key={key} value={value}')
|
|
|
|
|
|
try:
|
|
if args.no_args or args.system_wide or args.event:
|
|
expected_items = 7
|
|
elif args.interval or args.per_thread or args.system_wide_no_aggr:
|
|
expected_items = 8
|
|
elif args.per_core or args.per_socket or args.per_node or args.per_die or args.per_cache:
|
|
expected_items = 9
|
|
else:
|
|
# If no option is specified, don't check the number of items.
|
|
expected_items = -1
|
|
check_json_output(expected_items)
|
|
except:
|
|
print('Test failed for input:\n' + '\n'.join(Lines))
|
|
raise
|