summaryrefslogtreecommitdiff
path: root/tools/perf/python/treport.py
AgeCommit message (Collapse)Author
2026-10-19perf treport: Fix profile builder type narrowing in progress callbackJames Clark
Mypy does not retain the narrowing of an optional local variable inside the nested progress callback, causing the perf build to fail with: python/treport.py:649: error: Item "None" of "ProfileBuilder | None" has no attribute "cancelled" [union-attr] Check the loading builder before assigning it to profile so the captured variable is inferred as ProfileBuilder rather than Optional[ProfileBuilder]. Keep the existing assertion and background loading behavior. Fixes: b379b70b7b7b ("perf treport: Show the profile while it loads") Assisted-by: Codex:GPT-6.1-Sol Signed-off-by: James Clark <james.clark@linaro.org> Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-10-03perf treport: Show the profile while it loadsAlice Rogers
Reading a large perf.data file caused a long stall before the treport app started. Start the app immediately and build the profile in a background thread, showing the report tree and flame graph as they are built with the progress in the header. The time between updates grows with the load time as updating the views costs more as the profile grows. A lock guards the profile shared between the threads. Quitting while loading cancels the load. Tree nodes are now created lazily as they are expanded, expanded nodes and the cursor are kept across updates, and events are kept in the order they are first seen as their values aren't comparable. Node names are escaped so they aren't interpreted as markup. Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Alice Rogers <alice.mei.rogers@gmail.com> Co-developed-by: Ian Rogers <irogers@google.com> Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-09-26perf python: Clean up pylint warnings in treport.pyIan Rogers
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>
2026-09-26perf python: Update callchain stubs and session thread lookupIan Rogers
Update pyrf_session__find_thread() in util/python.c to accept an optional tid parameter (defaulting to pid) and return None instead of raising TypeError when a thread is not found in the session machines. Update perf.pyi to match: - Set session.find_thread() signature to (pid: int, tid: int = -1) -> Optional[thread]. - Update callchain_node.symbol and callchain_node.dso to str (the C getters return "[unknown]" fallback strings rather than None) and add __iter__() to callchain. Also update treport.py to handle Optional[thread] returned by session.find_thread(). 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>
2026-09-09perf python: Add flamegraph support to treportAlice Rogers
Implement a flamegraph widget that recursively walks down a tree splitting line segments based on their value (summed up periods across call chains). A visitor pattern is used so that the same logic can both draw the line segments and locate which segment had a mouse click. Add a tab for the flame graph widget. Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Co-developed-by: Ian Rogers <irogers@google.com> Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Alice Rogers <alice.mei.rogers@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-09-09perf python: New treport scriptAlice Rogers
A textual app that displays the results of processing samples similar to perf report. The app displays a tree of first processes and then functions which drop down to show more detail on the functions they call. The functions with the largest number of samples are sorted first, after each function the percentage of time spent within it is highlighted. If more than one event is recorded then each event appears first, with the processes and functions sorted for that event beneath it. The app is written in python and requires the textual framework. Using the textual framework means that in most modern terminals the mouse is supported, the color scheme can be configured, and screenshots made. With perf report: ``` $ perf record -e cycles:u -g perf test -w brstack [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.008 MB perf.data (57 samples) ] $ perf report ... Samples: 57 of event 'cycles:u', Event count (approx.): 15907831 Children Self Command Shared Object Symbol - 88.86% 0.00% perf libc.so.6 [.] 0x000079b17df69ca8 0x79b17df69ca8 main handle_internal_command cmd_test - brstack - 84.27% brstack_bench - 40.69% brstack_foo brstack_bar 3.32% brstack_bar 3.31% brstack_bar 1.27% brstack_foo + 88.86% 0.00% perf perf [.] main + 88.86% 0.00% perf perf [.] handle_internal_command + 88.86% 0.00% perf perf [.] cmd_test + 88.86% 0.00% perf perf [.] brstack + 84.27% 40.26% perf perf [.] brstack_bench + 41.96% 30.71% perf perf [.] brstack_foo + 17.89% 17.89% perf perf [.] brstack_bar ``` With the treport script: ``` $ perf record -e cycles:u -g perf test -w brstack [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.008 MB perf.data (57 samples) ] $ tools/perf/python/treport.py O ReportApp Report ╸━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ▼ Profile └── ▼ cycles:u 100% └── ▼ perf (32963) 100% ├── ▼ /usr/lib/x86_64-linux-gnu/libc.so.6 0x79b17df6 │ └── ▼ main 56.1% │ └── ▼ handle_internal_command 56.1% │ └── ▼ cmd_test 56.1% │ └── ▼ brstack 56.1% ▁▁ │ ├── ▼ brstack_bench 52.6% │ │ ├── ▶ brstack_foo 24.6% │ │ └── brstack_bar 1.75% │ ├── brstack_foo 1.75% │ └── brstack_bar 1.75% ├── ▶ /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ▌ ^q Quit ▏^p palette ``` Committer testing: One needs to install 'python-textual' to have this working. Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Co-developed-by: Ian Rogers <irogers@google.com> Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Alice Rogers <alice.mei.rogers@gmail.com> Link: https://lore.kernel.org/r/20260809051820.2436530-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>