From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796523768; b=CoHRD5hizLg/8pYB33EdLPgzjVl4W8aUMwionD229rqarW6JNKmqAE4h7EbA3H3P4WDA 7NFgPcJlrdJ5cVhyj8VlNy54/SZapPm+IsKH9KybcVxZhAiIOT5/hhpc7TArLZsGqo7mT NUFBOHKElNA1glCShlxiznqkITeEJPXA46RnPpgfAXx2ZHAlccmh5kpx9fqNQ+M6RZULR gh7I/kNekae0km0sy9unauIPAG6hzdzIQ/mDYT7EkrWPowyHs1oDBKFVrYzit5Cc7cUx/ VQ2u/P/y1HFko8crrluo5zj91CtBjko6RCzO8p5edElEuIkhcR5og84d6By2dDwAHgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796523768; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=6EBa58GvyAUe7+AJaMdE77DsrCo58Ls5+jAOLBurhgs=; b=w78DZansgy6/Qmag98Tb+Sim++39vTYreUcOzCENksMqPcuGWNSC98u1oXfui3v9m81P FEPKAm+Z/MlnHp9NeujnGj9/EEXTRjIORJbTNYog4875Ff70KD4wTpHed+vSqVU+AywTI prAmwxyCQIwXdkEM62lZt8IMpBCMMtkSSelWF6S3lvEYqb7GrQAGSU+Es/MbXRMzJBzYD e4lpgJVZHs8x86Adp6LXXLnffpmbY1OY9LM3C2F99JY8EXuG+Ete+9eUYW3VGwHA2zW2H ZR7GjYHnH6oJZ+seFtWFkUpiSlIvCZx7mSEeNZase8CKZVumNkt70yMO/9lRs4mjWTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bXR6Afzm; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92038606A31F for ; Sun, 6 Dec 2026 02:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bXR6Afzm Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EA451F0092B; Sun, 6 Dec 2026 02:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796523768; bh=6EBa58GvyAUe7+AJaMdE77DsrCo58Ls5+jAOLBurhgs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=bXR6AfzmoJyA0ENP4gF6a/XEfcjpOcLCeu6BzYfymSEebXDpxENRjsN3VTaJklsRt M0vdFAWltFvpd62c+zHeUbpjqyP/Z9ne/4GxZtN3RwPPkDyBy6N0+ACAOCxZlnsp3z HxRlpwLnV4sBKtD5YJRjEoNbhFmItuizG03DsLuZqytYcMw0g7H4FQ6aUUQTpBe9UT G9m4RJ9KtInEJ6IVRKPk9qefyifKy/hq/gjLkwajxYreXb7mIr0DeUivSUqZGEJWZo 9kuyr4OvUSDydQyBxSATIn1Crfa50F6slOA+OGWRhq07S4iN0L1u6WceHOJoBzzpau N4fEme3hVwPsw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/8] perf pmu-events: Ignore backup and non-event JSON files in metric.py Reply-To: sashiko-reviews@lists.linux.dev To: "Ian Rogers" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261206021147.3036701-2-irogers@google.com> References: <20261206021147.3036701-1-irogers@google.com> <20261206021147.3036701-2-irogers@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 02:22:47 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] perf pmu-events: duplicated JSON loading and validation logic in LoadEvents() - [Low] perf pmu-events: missing Fixes trailer for LoadEvents() bug fix -- commit ce7e6cca0e67fa4bb5378fdef562b5943d45c114 Author: Ian Rogers > perf pmu-events: Ignore backup and non-event JSON files in metric.py > > LoadEvents() in metric.py scans model directories and their parent > architecture tree for any filename ending in ".json". Editor lockfiles > and backup files ending in ".json", such as Emacs dangling symlinks > (".#cache.json"), hidden files (".cache.json"), multi-dot backups > ("cache.bak.json"), or git mergetool backups ("cache_BACKUP_*.json"), > can crash LoadEvents() with FileNotFoundError or pollute the loaded > event set. Likewise, metricgroups.json files contain JSON objects > rather than event arrays, and leftover generated files > (extra-metrics.json, extra-metricgroups.json, legacy-cache.json) do not > define raw PMU events. > > Filter filenames via _is_valid_event_json(), check os.path.isfile() > before opening, verify parsed JSON is a list of dicts before reading > event keys, and prune hidden or dotted subdirectories during os.walk(). > > Signed-off-by: Ian Rogers [Severity: Low] This fixes FileNotFoundError crashes and non-event JSON parsing in LoadEvents(). Should it include Fixes trailers for the commits that introduced the unfiltered scans? Fixes: 6bd6c5ef6c7a ("perf jevents: Add load event JSON to verify and all= ow fallbacks") Fixes: e205952db771 ("perf jevents: Validate that all names given an Even= t") > diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metr= ic.py > index f5d81eccd5c3f..f7d5ab6143ee4 100644 > --- a/tools/perf/pmu-events/metric.py > +++ b/tools/perf/pmu-events/metric.py > @@ -13,6 +13,25 @@ all_events: Set[str] =3D set() > experimental_events: Set[str] =3D set() > all_events_all_models: Set[str] =3D set() > =20 > +_MERGETOOL_BACKUP_RE =3D re.compile(r'_(?:BACKUP|BASE|LOCAL|REMOTE)_\d+\= .json$') > +_SKIP_EVENT_JSON_NAMES =3D frozenset({ > + 'legacy-cache.json', > + 'extra-metrics.json', > + 'extra-metricgroups.json', > +}) > + > + > +def _is_valid_event_json(filename: str) -> bool: > + """Return True if filename is a checked-in PMU event JSON table.""" > + if filename.startswith('.') or not filename.endswith('.json'): > + return False > + if filename.count('.') !=3D 1 or _MERGETOOL_BACKUP_RE.search(filename): > + return False > + if filename.endswith('metricgroups.json') or filename in _SKIP_EVENT_J= SON_NAMES: > + return False > + return True > + > + > def LoadEvents(directory: str) -> None: > """Populate a global set of all known events for the purpose of valida= ting Event names""" > global all_events > @@ -26,37 +45,48 @@ def LoadEvents(directory: str) -> None: > } > for file in os.listdir(os.fsencode(directory)): > filename =3D os.fsdecode(file) > - if filename.endswith(".json"): > + path =3D f"{directory}/{filename}" > + if _is_valid_event_json(filename) and os.path.isfile(path): > try: > - with open(f"{directory}/{filename}", encoding=3D"utf-8") as f: > - for x in json.load(f): > - if "Unit" in x: > - all_pmus.add(x["Unit"]) > - if "EventName" in x: > - all_events.add(x["EventName"]) > - if "Experimental" in x and x["Experimental"] =3D=3D "1": > - experimental_events.add(x["EventName"]) > - elif "ArchStdEvent" in x: > - all_events.add(x["ArchStdEvent"]) > + with open(path, encoding=3D"utf-8") as f: > + data =3D json.load(f) > except json.decoder.JSONDecodeError: > - # The generated directory may be the same as the input, which > - # causes partial json files. Ignore errors. > - pass > + # Ignore partially written JSON files if present. > + continue > + if not isinstance(data, list): > + continue > + for x in data: > + if not isinstance(x, dict): > + continue > + if "Unit" in x: > + all_pmus.add(x["Unit"]) > + if "EventName" in x: > + all_events.add(x["EventName"]) > + if "Experimental" in x and x["Experimental"] =3D=3D "1": > + experimental_events.add(x["EventName"]) > + elif "ArchStdEvent" in x: > + all_events.add(x["ArchStdEvent"]) > all_events_all_models =3D all_events.copy() > - for root, _, files in os.walk(directory + ".."): > + for root, dirs, files in os.walk(directory + ".."): > + dirs[:] =3D [d for d in dirs if not d.startswith('.') and '.' not in= d] > for filename in files: > - if filename.endswith(".json"): > + path =3D f"{root}/{filename}" > + if _is_valid_event_json(filename) and os.path.isfile(path): > try: > - with open(f"{root}/{filename}", encoding=3D"utf-8") as f: > - for x in json.load(f): > - if "EventName" in x: > - all_events_all_models.add(x["EventName"]) > - elif "ArchStdEvent" in x: > - all_events_all_models.add(x["ArchStdEvent"]) > + with open(path, encoding=3D"utf-8") as f: > + data =3D json.load(f) > except json.decoder.JSONDecodeError: > - # The generated directory may be the same as the input, which > - # causes partial json files. Ignore errors. > - pass > + # Ignore partially written JSON files if present. > + continue > + if not isinstance(data, list): > + continue > + for x in data: > + if not isinstance(x, dict): > + continue > + if "EventName" in x: > + all_events_all_models.add(x["EventName"]) > + elif "ArchStdEvent" in x: > + all_events_all_models.add(x["ArchStdEvent"]) [Severity: Low] Can the duplicated file filtering, JSON loading, and list/dict validation logic in the two LoadEvents() loops be extracted into a helper such as _iter_event_dicts(directory, filename)? Keeping a single copy avoids the two loops drifting out of sync on future filtering changes. Also, in the os.walk() directory filter, "not d.startswith('.')" is redundant with "'.' not in d". Similarly, 'extra-metricgroups.json' in _SKIP_EVENT_JSON_NAMES is already matched by filename.endswith('metricgroups.json'). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206021147.3036= 701-1-irogers@google.com?part=3D1