mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-21 09:12:05 +00:00
When the threshold isn't unknown add a value to the json like:
"metric-threshold" : "good"
A more complete example:
```
$ perf stat -a -j -I 1000
{"interval" : 1.001089747, "counter-value" : "16045.281449", "unit" : "msec", "event" : "cpu-clock", "event-runtime" : 16045355135, "pcnt-running" : 100.00, "metric-value" : "16.045281", "metric-unit" : "CPUs utilized"}
{"interval" : 1.001089747, "counter-value" : "10003.000000", "unit" : "", "event" : "context-switches", "event-runtime" : 16045314844, "pcnt-running" : 100.00, "metric-value" : "623.423156", "metric-unit" : "/sec"}
{"interval" : 1.001089747, "counter-value" : "328.000000", "unit" : "", "event" : "cpu-migrations", "event-runtime" : 16045321403, "pcnt-running" : 100.00, "metric-value" : "20.442147", "metric-unit" : "/sec"}
{"interval" : 1.001089747, "counter-value" : "20114.000000", "unit" : "", "event" : "page-faults", "event-runtime" : 16045355927, "pcnt-running" : 100.00, "metric-value" : "1.253577", "metric-unit" : "K/sec"}
{"interval" : 1.001089747, "counter-value" : "4066679471.000000", "unit" : "", "event" : "instructions", "event-runtime" : 16045369123, "pcnt-running" : 100.00, "metric-value" : "1.628330", "metric-unit" : "insn per cycle"}
{"interval" : 1.001089747, "counter-value" : "2497454658.000000", "unit" : "", "event" : "cycles", "event-runtime" : 16045374810, "pcnt-running" : 100.00, "metric-value" : "0.155650", "metric-unit" : "GHz"}
{"interval" : 1.001089747, "counter-value" : "914974294.000000", "unit" : "", "event" : "branches", "event-runtime" : 16045379877, "pcnt-running" : 100.00, "metric-value" : "57.024509", "metric-unit" : "M/sec"}
{"interval" : 1.001089747, "counter-value" : "9237201.000000", "unit" : "", "event" : "branch-misses", "event-runtime" : 16045375017, "pcnt-running" : 100.00, "metric-value" : "1.009559", "metric-unit" : "of all branches", "metric-threshold" : "good"}
{"interval" : 1.001089747, "event-runtime" : 16045397172, "pcnt-running" : 100.00, "metricgroup" : "TopdownL1"}
{"interval" : 1.001089747, "metric-value" : "22.036686", "metric-unit" : "% tma_backend_bound", "metric-threshold" : "bad"}
{"interval" : 1.001089747, "metric-value" : "7.610161", "metric-unit" : "% tma_bad_speculation", "metric-threshold" : "good"}
{"interval" : 1.001089747, "metric-value" : "36.729687", "metric-unit" : "% tma_frontend_bound", "metric-threshold" : "bad"}
{"interval" : 1.001089747, "metric-value" : "33.623465", "metric-unit" : "% tma_retiring"}
...
```
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Will Deacon <will@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20241017175356.783793-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
105 lines
3.6 KiB
Python
105 lines
3.6 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('--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,
|
|
'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,
|
|
}
|
|
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 <= 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:
|
|
pass
|
|
elif count == expected_items + 1 and 'metric-threshold' in item:
|
|
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_cluster 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
|