[PATCH v3 04/49] perf python: Clean up pylint warnings in treport.py
From: Ian Rogers
Date: Wed Sep 23 2026 - 14:13:08 EST
Clean up pylint warnings in treport.py so that it passes pylint without
warning suppression comments:
- Replace broad 'except Exception:' clauses (W0718:
broad-exception-caught) with specific exception tuples.
- Pass both pid and sample_tid to session.find_thread() so guest and
process threads are resolved accurately.
- Rename parameter 'args' to 'pos_args' in FlameGraph.__init__() to
avoid shadowing the outer scope variable 'args' (W0621:
redefined-outer-name).
- Clear session = None in a finally block after session.process_events()
to break the C perf_session reference cycle before launching the TUI.
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/python/treport.py | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/tools/perf/python/treport.py b/tools/perf/python/treport.py
index 786b852f471c..0921b428b1aa 100755
--- a/tools/perf/python/treport.py
+++ b/tools/perf/python/treport.py
@@ -91,9 +91,9 @@ class ProfileNode:
pid = sample.sample_pid
try:
assert session
- thread = session.find_thread(sample.sample_tid)
+ thread = session.find_thread(pid, sample.sample_tid)
comm = (thread.comm() if thread else None) or f"unknown ({pid})"
- except Exception:
+ except (OSError, ValueError, KeyError, RuntimeError, TypeError, AttributeError):
comm = f"unknown ({pid})"
period = sample.sample_period
@@ -412,9 +412,9 @@ class FlameGraph(ScrollView):
}
"""
- def __init__(self, root: ProfileNode, *args, **kwargs):
+ def __init__(self, root: ProfileNode, *pos_args, **kwargs):
"""Initialize the FlameGraph widget."""
- super().__init__(*args, **kwargs)
+ super().__init__(*pos_args, **kwargs)
self.root = root
self.cursor = root
self.selected = root
@@ -549,12 +549,15 @@ if __name__ == "__main__":
profile = ProfileBuilder()
try:
session = perf.session(perf.data(input_file), sample=profile.process_event)
- except Exception as e:
+ except (OSError, ValueError, RuntimeError) as e:
print(f"Error opening session: {e}", file=sys.stderr)
sys.exit(1)
# profile.process_event is called for each perf event to build the profile.
- session.process_events()
+ try:
+ session.process_events()
+ finally:
+ session = None
# Visualize data.
app = ReportApp(profile.root)
--
2.56.0.rc1.310.g51773c2048-goog