mirror of
https://github.com/torvalds/linux.git
synced 2026-04-25 01:52:32 -04:00
Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/
The patch adds unit aggregation during evsel merge the aggregated uncore
counters. Change the name of the column to `ctrs` and `counters` for
json mode.
Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and
cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events
1.001085024 S0 1 9615386315 clockticks
1.001085024 S1 1 9614287448 clockticks
perf stat -e clockticks -I 1000 --per-node
# time node cpus counts unit events
1.001029867 N0 1 3205726984 clockticks
1.001029867 N1 1 3205444421 clockticks
1.001029867 N2 1 3205234018 clockticks
1.001029867 N3 1 3205224660 clockticks
1.001029867 N4 1 3205207213 clockticks
1.001029867 N5 1 3205528246 clockticks
After:
perf stat -e clockticks -I 1000 --per-socket
# time socket ctrs counts unit events
1.001026071 S0 12 9619677996 clockticks
1.001026071 S1 12 9618612614 clockticks
perf stat -e clockticks -I 1000 --per-node
# time node ctrs counts unit events
1.001027449 N0 4 3207251859 clockticks
1.001027449 N1 4 3207315930 clockticks
1.001027449 N2 4 3206981828 clockticks
1.001027449 N3 4 3206566126 clockticks
1.001027449 N4 4 3206032609 clockticks
1.001027449 N5 4 3205651355 clockticks
Tested with JSON output linter:
perf test "perf stat JSON output linter"
94: perf stat JSON output linter : Ok
Suggested-by: Ian Rogers <irogers@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Link: https://lore.kernel.org/r/20250627201818.479421-1-ctshao@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
112 lines
3.9 KiB
Python
112 lines
3.9 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-cluster', 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('--metric-only', 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 = {
|
|
'counters': 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,
|
|
'cluster': 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),
|
|
'metric-threshold': lambda x: x in ['unknown', 'good', 'less good', 'nearly bad', 'bad'],
|
|
'metricgroup': lambda x: True,
|
|
'node': lambda x: True,
|
|
'pcnt-running': lambda x: isfloat(x),
|
|
'socket': lambda x: True,
|
|
'thread': lambda x: True,
|
|
'unit': lambda x: True,
|
|
'insn per cycle': lambda x: isfloat(x),
|
|
'GHz': lambda x: True, # FIXME: it seems unintended for --metric-only
|
|
}
|
|
input = '[\n' + ','.join(Lines) + '\n]'
|
|
for item in json.loads(input):
|
|
if expected_items != -1:
|
|
count = len(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,
|
|
# counters, or event-runtime/pcnt-running from multiplexing.
|
|
pass
|
|
elif count not in expected_items and count >= 1 and count <= 5 and 'metricgroup' in item:
|
|
pass
|
|
elif count - 1 in expected_items and 'metric-threshold' in item:
|
|
pass
|
|
elif count in expected_items and 'insn per cycle' in item:
|
|
pass
|
|
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():
|
|
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 = [5, 7]
|
|
elif args.interval or args.per_thread or args.system_wide_no_aggr:
|
|
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 = [7, 9]
|
|
elif args.metric_only:
|
|
expected_items = [1, 2]
|
|
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
|