perf python: Clean up pylint warnings in ilist.py

Replace bare 'except:' clauses (pylint W0702: bare-except) in ilist.py
with specific exception tuples (OSError, ValueError, RuntimeError,
TypeError, KeyError) and use a safe '.get("name", "")' sort key in
IListApp.compose() so that ilist.py passes pylint without warning
suppression comments and handles unnamed PMU events gracefully.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2026-09-25 23:19:30 -07:00 committed by Arnaldo Carvalho de Melo
parent 514ecdfd00
commit 2dfe9eaec5

View File

@ -82,7 +82,7 @@ class Metric(TreeValue):
try:
val = evlist.compute_metric(self.metric_name, cpu, thread)
return 0 if math.isnan(val) else val
except:
except (OSError, ValueError, RuntimeError, TypeError):
# Be tolerant of failures to compute metrics on particular CPUs/threads.
return 0
@ -419,7 +419,7 @@ class IListApp(App):
if self.evlist:
self.evlist.open()
self.evlist.enable()
except:
except (OSError, ValueError, RuntimeError):
self.evlist = None
if not self.evlist:
@ -450,7 +450,7 @@ class IListApp(App):
pmu_name = pmu.name().lower()
pmu_node = pmus.add(pmu_name)
try:
for event in sorted(pmu.events(), key=lambda x: x["name"]):
for event in sorted(pmu.events(), key=lambda x: x.get("name", "")):
if "deprecated" in event:
continue
if "name" in event:
@ -460,7 +460,7 @@ class IListApp(App):
data=PmuEvent(pmu_name, e))
else:
pmu_node.add_leaf(e, data=PmuEvent(pmu_name, e))
except:
except (OSError, ValueError, RuntimeError, KeyError, TypeError):
# Reading events may fail with EPERM, ignore.
pass
metrics = tree.root.add("Metrics")