Skip to contentSkip to conversation

perf jevents: Provide better path information for broken json

PATCH In review Ian Rogers 1 participant 2 messages Nov 14, 2024 – Dec 20, 2024 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf jevents: Provide better path information for broken json

If the json input to jevents.py is broken it can be problematic to work out which particular json file is broken. When processing files catch exceptions that occur that re-raise the exception with path details added.

---
 tools/perf/pmu-events/jevents.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/pmu-events/jevents.py +9 -2
index 6e71b09dbc2a..caeddd939cfe 100755
@@ -461,12 +461,16 @@ def preprocess_arch_std_files(archpath: str) -> None:
   """Read in all architecture standard events."""
   global _arch_std_events
   for item in os.scandir(archpath):
-    if item.is_file() and item.name.endswith('.json'):
+    if not item.is_file() or not item.name.endswith('.json'):
+      continue
+    try:
       for event in read_json_events(item.path, topic=''):
         if event.name:
           _arch_std_events[event.name.lower()] = event
         if event.metric_name:
           _arch_std_events[event.metric_name.lower()] = event
+    except Exception as e:
+        raise RuntimeError(f'Failure processing \'{item.name}\' in \'{archpath}\'') from e
 
 
 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
@@ -1255,7 +1259,10 @@ def main() -> None:
           item_path = '/'.join(parents) + ('/' if len(parents) > 0 else '') + item.name
           if 'test' not in item_path and 'common' not in item_path and item_path not in _args.model.split(','):
             continue
-      action(parents, item)
+      try:
+        action(parents, item)
+      except Exception as e:
+        raise RuntimeError(f'Action failure for \'{item.name}\' in {parents}') from e
       if item.is_dir():
         ftw(item.path, parents + [item.name], action)
 
Signature · 1 line
2.47.0.338.g60cca15819-goog
author reviewer
#1 lore raw
Quoted 7 lines · Ian Rogers

If the json input to jevents.py is broken it can be problematic to work out which particular json file is broken. When processing files catch exceptions that occur that re-raise the exception with path details added.

Ping.

Thanks,
Ian