summaryrefslogtreecommitdiff
path: root/tools/perf/python
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-09-25 23:19:31 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-09-26 20:49:27 +0200
commit2997739214ce6e0825f127e1a71d0f82526aa83a (patch)
tree4def2e5647e1a0f4a7755f4be8acc37b593e108f /tools/perf/python
parent2dfe9eaec5c28f8f885c17d5b643299f685451b7 (diff)
perf python: Clean up pylint warnings in treport.py
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@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/python')
-rwxr-xr-xtools/perf/python/treport.py15
1 files 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)