From: Ian Rogers Date: Tue, 27 Jan 2026 18:44:45 +0000 (-0800) Subject: perf jevents: Add CheckPmu to see if a PMU is in loaded JSON events X-Git-Tag: v7.0-rc1~16^2~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61b7b2ef64f8c9cf48ae1b0bfe2ee0bcb9bb3181;p=thirdparty%2Flinux.git perf jevents: Add CheckPmu to see if a PMU is in loaded JSON events CheckPmu can be used to determine if hybrid events are present, allowing for hybrid conditional metrics/events/pmus to be premised on the JSON files rather than hard coded tables. Signed-off-by: Ian Rogers Tested-by: Thomas Falcon Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Benjamin Gray Cc: Caleb Biggers Cc: Edward Baker Cc: Ingo Molnar Cc: James Clark Cc: Jing Zhang Cc: Jiri Olsa Cc: John Garry Cc: Leo Yan Cc: Namhyung Kim Cc: Perry Taylor Cc: Peter Zijlstra Cc: Sandipan Das Cc: Weilin Wang Cc: Xu Yang Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py index e33e163b2815..62d1a1e1d458 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -8,10 +8,12 @@ import re from enum import Enum from typing import Dict, List, Optional, Set, Tuple, Union +all_pmus = set() all_events = set() def LoadEvents(directory: str) -> None: """Populate a global set of all known events for the purpose of validating Event names""" + global all_pmus global all_events all_events = { "context\\-switches", @@ -26,6 +28,8 @@ def LoadEvents(directory: str) -> None: if filename.endswith(".json"): try: for x in json.load(open(f"{directory}/{filename}")): + if "Unit" in x: + all_pmus.add(x["Unit"]) if "EventName" in x: all_events.add(x["EventName"]) elif "ArchStdEvent" in x: @@ -36,6 +40,10 @@ def LoadEvents(directory: str) -> None: pass +def CheckPmu(name: str) -> bool: + return name in all_pmus + + def CheckEvent(name: str) -> bool: """Check the event name exists in the set of all loaded events""" global all_events