all_pmus = set()
all_events = set()
experimental_events = set()
+all_events_all_models = 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
global experimental_events
+ global all_events_all_models
all_events = {
"context\\-switches",
"cpu\\-cycles",
# The generated directory may be the same as the input, which
# causes partial json files. Ignore errors.
pass
+ all_events_all_models = all_events.copy()
+ for root, dirs, files in os.walk(directory + ".."):
+ for filename in files:
+ if filename.endswith(".json"):
+ try:
+ for x in json.load(open(f"{root}/{filename}")):
+ if "EventName" in x:
+ all_events_all_models.add(x["EventName"])
+ elif "ArchStdEvent" in x:
+ all_events_all_models.add(x["ArchStdEvent"])
+ except json.decoder.JSONDecodeError:
+ # The generated directory may be the same as the input, which
+ # causes partial json files. Ignore errors.
+ pass
def CheckPmu(name: str) -> bool:
return name in all_events
+def CheckEveryEvent(*names: str) -> None:
+ """Check all the events exist in at least one json file"""
+ global all_events_all_models
+ if len(all_events_all_models) == 0:
+ assert len(names) == 1, f"Cannot determine valid events in {names}"
+ # No events loaded so assume any event is good.
+ return
+
+ for name in names:
+ # Remove trailing modifier.
+ if ':' in name:
+ name = name[:name.find(':')]
+ elif '/' in name:
+ name = name[:name.find('/')]
+ if any([name.startswith(x) for x in ['amd', 'arm', 'cpu', 'msr', 'power']]):
+ continue
+ if name not in all_events_all_models:
+ raise Exception(f"Is {name} a named json event?")
+
def IsExperimentalEvent(name: str) -> bool:
global experimental_events
def __init__(self, *args: str):
error = ""
+ CheckEveryEvent(*args)
for name in args:
if CheckEvent(name):
self.name = _FixEscapes(name)