Skip to content

Commit 3de34f8

Browse files
captain5050acmel
authored andcommitted
perf test: Avoid counting commas in json linter
Commas may appear in events like: cpu/INT_MISC.RECOVERY_CYCLES,cmask=1,edge/ which causes the count of commas to see more items than expected. Switch to counting the entries in the dictionary, which is 1 more than the number of commas. Signed-off-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Claire Jensen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sumanth Korikkar <[email protected]> Cc: Thomas Richter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d3e104b commit 3de34f8

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,6 @@ def is_counter_value(num):
4040
return isfloat(num) or num == '<not counted>' or num == '<not supported>'
4141

4242
def check_json_output(expected_items):
43-
if expected_items != -1:
44-
for line in Lines:
45-
if 'failed' not in line:
46-
count = 0
47-
count = line.count(',')
48-
if count != expected_items and count >= 1 and count <= 3 and 'metric-value' in line:
49-
# Events that generate >1 metric may have isolated metric
50-
# values and possibly other prefixes like interval, core and
51-
# aggregate-number.
52-
continue
53-
if count != expected_items:
54-
raise RuntimeError(f'wrong number of fields. counted {count} expected {expected_items}'
55-
f' in \'{line}\'')
5643
checks = {
5744
'aggregate-number': lambda x: isfloat(x),
5845
'core': lambda x: True,
@@ -73,6 +60,16 @@ def check_json_output(expected_items):
7360
}
7461
input = '[\n' + ','.join(Lines) + '\n]'
7562
for item in json.loads(input):
63+
if expected_items != -1:
64+
count = len(item)
65+
if count != expected_items and count >= 1 and count <= 4 and 'metric-value' in item:
66+
# Events that generate >1 metric may have isolated metric
67+
# values and possibly other prefixes like interval, core and
68+
# aggregate-number.
69+
pass
70+
elif count != expected_items:
71+
raise RuntimeError(f'wrong number of fields. counted {count} expected {expected_items}'
72+
f' in \'{item}\'')
7673
for key, value in item.items():
7774
if key not in checks:
7875
raise RuntimeError(f'Unexpected key: key={key} value={value}')
@@ -82,11 +79,11 @@ def check_json_output(expected_items):
8279

8380
try:
8481
if args.no_args or args.system_wide or args.event:
85-
expected_items = 6
86-
elif args.interval or args.per_thread or args.system_wide_no_aggr:
8782
expected_items = 7
88-
elif args.per_core or args.per_socket or args.per_node or args.per_die:
83+
elif args.interval or args.per_thread or args.system_wide_no_aggr:
8984
expected_items = 8
85+
elif args.per_core or args.per_socket or args.per_node or args.per_die:
86+
expected_items = 9
9087
else:
9188
# If no option is specified, don't check the number of items.
9289
expected_items = -1

0 commit comments

Comments
 (0)