From: TAKANO Mitsuhiro <takano32@gmail.com>
To: linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
James Clark <james.clark@linaro.org>,
John Garry <john.garry@linux.dev>,
linux-kernel@vger.kernel.org,
TAKANO Mitsuhiro <takano32@gmail.com>
Subject: [PATCH v7 1/1] perf jevents: Check the keys of the JSON tables
Date: Thu, 12 Nov 2026 16:28:23 +0000 [thread overview]
Message-ID: <20261112162823.139419-2-takano32@gmail.com> (raw)
In-Reply-To: <20261112162823.139419-1-takano32@gmail.com>
jevents.py takes the fields it wants out of each JSON object by name and
ignores the rest, so a key that is spelled differently is dropped without
a word and the object is built without whatever that field held. Two of
those are in the tree: "PublicDescrition" in 16 entries of an Arm table,
and "BriefDescript6ion" in one entry each of three AMD tables.
A table may carry 51 keys; 47 of them jevents.py reads, one more metric.py
reads, and three are read by nothing although the tables hold them
(Counter, CountersNumFixed, CountersNumGeneric). A key outside that list
is reported with the file that carries it. There is no cut-off, no
similarity and nothing that depends on what a run of the generator
happened to read.
The check is not a JSON schema because perf's build would then require
jsonschema, which it does not use today and which is not in every
builder's python. It runs as a perf test, not as part of the build.
On the tree today it reports 19 keys in four tables.
Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com>
---
v7: one patch instead of three. Patches 1 and 2 are dropped with the
Makefile target, the arch filter, the summary line and the handling
of tables that hold a single object; what is left is the walk, the
set difference against the list, and the file the object is in.
tools/perf/pmu-events/jevents.py | 38 +++++++++++++++++++++++++
tools/perf/tests/shell/jevents_check.sh | 24 ++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100755 tools/perf/tests/shell/jevents_check.sh
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 080e04b51b8c..397b4fc97749 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -7,6 +7,7 @@ import json
import metric
import os
import sys
+from pathlib import Path
from typing import (Callable, Dict, Optional, Sequence, Set, Tuple)
import collections
@@ -1450,6 +1451,38 @@ def _init_worker(std_events: dict) -> None:
global _arch_std_events
_arch_std_events = std_events
+# The keys a json object under arch/ may carry. jevents.py takes the fields it
+# wants by name and ignores the rest, so a key that is spelled differently is
+# dropped without a word; this is the list a table is allowed to contain.
+_TABLE_KEYS: Set[str] = {
+ 'AggregationMode', 'AnyThread', 'ArchStdEvent', 'BriefDescription',
+ 'Compat', 'ConfigCode', 'Counter', 'CounterMask',
+ 'CountersNumFixed', 'CountersNumGeneric', 'Data_LA', 'DefaultMetricgroupName',
+ 'DefaultShowEvents', 'Deprecated', 'EdgeDetect', 'EnAllCores',
+ 'EnAllSlices', 'Errata', 'EventCode', 'EventidCode',
+ 'EventName', 'Experimental', 'ExtSel', 'FCMask',
+ 'Filter', 'Invert', 'LegacyCacheCode', 'LegacyConfigCode',
+ 'MetricConstraint', 'MetricExpr', 'MetricGroup', 'MetricgroupNoGroup',
+ 'MetricName', 'MetricThreshold', 'MSRIndex', 'MSRValue',
+ 'NodeType', 'PEBS', 'PerPkg', 'PortMask',
+ 'PublicDescription', 'RdWrMask', 'RetirementLatencyMax', 'RetirementLatencyMean',
+ 'RetirementLatencyMin', 'SampleAfterValue', 'ScaleUnit', 'SliceId',
+ 'ThreadMask', 'UMask', 'Unit',
+}
+
+def _check_tables(root: str) -> int:
+ """Report the keys in the tables under root that a table may not carry."""
+ bad = 0
+ for path in sorted(Path(root).rglob('*.json')):
+ if path.name.endswith('metricgroups.json'):
+ # A dictionary keyed by metric group name, not a list of events.
+ continue
+ for obj in json.loads(path.read_text(encoding='utf-8')):
+ if extra := set(obj) - _TABLE_KEYS:
+ print(f'{path}: {sorted(extra)}')
+ bad += 1
+ return 1 if bad else 0
+
def main() -> None:
global _args
@@ -1494,8 +1527,13 @@ such as "arm/cortex-a34".''',
'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout)
ap.add_argument(
'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None)
+ ap.add_argument('--check', action='store_true',
+ help='check the keys of the tables under starting_dir and exit')
_args = ap.parse_args()
+ if _args.check:
+ sys.exit(_check_tables(_args.starting_dir))
+
_args.output_file.write(f"""/* SPDX-License-Identifier: GPL-2.0 */
/* THIS FILE WAS AUTOGENERATED BY `jevents.py arch={_args.arch} model={_args.model}` ! */
""")
diff --git a/tools/perf/tests/shell/jevents_check.sh b/tools/perf/tests/shell/jevents_check.sh
new file mode 100755
index 000000000000..eb3125e1486a
--- /dev/null
+++ b/tools/perf/tests/shell/jevents_check.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# jevents_check: an unknown key in a table is reported (no_mlock)
+#
+# A key that is spelled differently is dropped without a word, so the keys of
+# the tables are checked against the list jevents.py reads.
+
+jevents=$(dirname "$0")/../../pmu-events/jevents.py
+[ -r "${jevents}" ] || exit 2
+
+tmp=$(mktemp -d)
+trap 'rm -rf "${tmp}"' EXIT
+tables="${tmp}/arch/x86/model"
+mkdir -p "${tables}"
+
+# Known keys pass.
+printf '[{"EventName": "a", "EventCode": "0x1"}]\n' > "${tables}/events.json"
+python3 "${jevents}" x86 all "${tmp}/arch" --check > /dev/null || exit 1
+
+# A key the generator does not read is reported.
+printf '[{"EventName": "a", "NotAKey": "x"}]\n' > "${tables}/events.json"
+python3 "${jevents}" x86 all "${tmp}/arch" --check > /dev/null && exit 1
+
+exit 0
--
2.53.0
next prev parent reply other threads:[~2026-11-12 16:28 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 22:22 [PATCH 0/3] perf jevents: Report the JSON keys that jevents.py never reads TAKANO Mitsuhiro
2026-11-10 22:22 ` [PATCH 1/3] perf jevents: Name the metric when a MetricExpr is missing TAKANO Mitsuhiro
2026-11-10 22:44 ` sashiko-bot
2026-11-10 22:22 ` [PATCH 2/3] perf jevents: Make the model argument optional TAKANO Mitsuhiro
2026-11-10 22:43 ` sashiko-bot
2026-11-10 22:22 ` [PATCH 3/3] perf jevents: Check the JSON keys that jevents.py never reads TAKANO Mitsuhiro
2026-11-10 22:49 ` sashiko-bot
2026-11-11 2:33 ` TAKANO Mitsuhiro
2026-11-11 2:34 ` [PATCH v2 0/3] perf jevents: Report " TAKANO Mitsuhiro
2026-11-11 2:34 ` [PATCH v2 1/3] perf jevents: Name the metric when a MetricExpr is missing TAKANO Mitsuhiro
2026-11-11 3:05 ` sashiko-bot
2026-11-11 2:34 ` [PATCH v2 2/3] perf jevents: Make the model argument optional TAKANO Mitsuhiro
2026-11-11 3:15 ` sashiko-bot
2026-11-11 2:34 ` [PATCH v2 3/3] perf jevents: Check the JSON keys that jevents.py never reads TAKANO Mitsuhiro
2026-11-11 3:31 ` sashiko-bot
2026-11-11 3:43 ` [PATCH v3 0/3] perf jevents: Report " TAKANO Mitsuhiro
2026-11-11 3:43 ` [PATCH v3 1/3] perf jevents: Name the metric when a MetricExpr is missing TAKANO Mitsuhiro
2026-11-11 3:54 ` sashiko-bot
2026-11-11 3:43 ` [PATCH v3 2/3] perf jevents: Make the model argument optional TAKANO Mitsuhiro
2026-11-11 3:50 ` sashiko-bot
2026-11-11 3:43 ` [PATCH v3 3/3] perf jevents: Check the JSON keys that jevents.py never reads TAKANO Mitsuhiro
2026-11-11 3:59 ` sashiko-bot
2026-11-11 4:10 ` [PATCH v4 0/3] perf jevents: Report " TAKANO Mitsuhiro
2026-11-11 4:10 ` [PATCH v4 1/3] perf jevents: Name the metric when a MetricExpr is missing TAKANO Mitsuhiro
2026-11-11 4:22 ` sashiko-bot
2026-11-11 4:10 ` [PATCH v4 2/3] perf jevents: Make the model argument optional TAKANO Mitsuhiro
2026-11-11 4:16 ` sashiko-bot
2026-11-11 4:10 ` [PATCH v4 3/3] perf jevents: Check the JSON keys that jevents.py never reads TAKANO Mitsuhiro
2026-11-11 4:19 ` sashiko-bot
2026-11-11 13:26 ` [PATCH v5 0/3] perf jevents: Check the JSON keys a table may carry TAKANO Mitsuhiro
2026-11-11 13:26 ` [PATCH v5 1/3] perf jevents: Name the metric when a MetricExpr is missing TAKANO Mitsuhiro
2026-11-11 14:11 ` sashiko-bot
2026-11-11 13:26 ` [PATCH v5 2/3] perf jevents: Make the model argument optional TAKANO Mitsuhiro
2026-11-11 14:05 ` sashiko-bot
2026-11-11 13:26 ` [PATCH v5 3/3] perf jevents: Check the JSON keys a table may carry TAKANO Mitsuhiro
2026-11-11 14:12 ` sashiko-bot
2026-11-11 15:09 ` [PATCH v6 0/3] " TAKANO Mitsuhiro
2026-11-11 15:09 ` [PATCH v6 1/3] perf jevents: Name the metric and the file when a MetricExpr is missing TAKANO Mitsuhiro
2026-11-11 16:17 ` sashiko-bot
2026-11-11 15:09 ` [PATCH v6 2/3] perf jevents: Make the model argument optional TAKANO Mitsuhiro
2026-11-11 16:28 ` sashiko-bot
2026-11-11 15:09 ` [PATCH v6 3/3] perf jevents: Check the JSON keys a table may carry TAKANO Mitsuhiro
2026-11-11 16:36 ` sashiko-bot
2026-11-12 16:28 ` [PATCH v7 0/1] perf jevents: Check the keys of the JSON tables TAKANO Mitsuhiro
2026-11-12 16:28 ` TAKANO Mitsuhiro [this message]
2026-11-12 16:38 ` [PATCH v7 1/1] " sashiko-bot
2026-11-12 17:32 ` [PATCH v8 0/1] " TAKANO Mitsuhiro
2026-11-12 17:32 ` [PATCH v8 1/1] " TAKANO Mitsuhiro
2026-11-12 17:46 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112162823.139419-2-takano32@gmail.com \
--to=takano32@gmail.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=john.garry@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox