perf timechart: Add an interactive --tui mode

Add ttimechart.py, a textual based interactive timechart, and a --tui
option to perf timechart that launches it through perf script. Rather
than writing an SVG file, per-CPU (busy, frequency and idle state),
per-task (running, runnable and blocked) and I/O timelines are shown in
the terminal along with a summary table. The timelines can be zoomed,
panned and the state of the selected row at the cursor is described,
including the task that woke it. The -i, -P, -T and -p options are
passed to the script.

The data is loaded in a background thread and the timelines are shown
and updated as it loads. A --dump option prints a text summary without
the UI.

Committer testing:

Fist record a short session with:

  root@x2:/home/acme/git/perf-tools-next# perf timechart record
  ^C[ perf record: Woken up 9 times to write data ]
  [ perf record: Captured and wrote 4.489 MB perf.data (29719 samples) ]
  root@x2:/home/acme/git/perf-tools-next#

Then try the TUI with:

  root@x2:/home/acme/git/perf-tools-next# tools/perf/python/ttimechart.py

or:

  root@x2:/home/acme/git/perf-tools-next# perf timechart --tui

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>
This commit is contained in:
Alice Rogers 2026-10-02 11:26:19 -07:00 committed by Arnaldo Carvalho de Melo
parent 434735dfa2
commit e7a72d6919
3 changed files with 1859 additions and 0 deletions

View File

@ -53,6 +53,14 @@ TIMECHART OPTIONS
-f::
--force::
Don't complain, do it.
--tui::
Rather than writing an SVG file, interactively display the timechart
in the terminal using the 'ttimechart' python script (see
linkperf:perf-script[1]). The script requires the perf python module
and the python 'textual' library. The CPU, task, I/O and summary views
can be zoomed ('+'/'-'), panned (shift+arrows) and the state of the
selected row at the cursor is described. The -i, -P, -T and -p options
are passed to the script, other output options are ignored.
--symfs=<directory[,layout]>::
Look for files with symbols relative to this directory. The optional
layout can be 'hierarchy' (default, matches full path) or 'flat'

View File

@ -10,6 +10,7 @@
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include "builtin.h"
#include "util/color.h"
@ -68,6 +69,7 @@ struct timechart {
with_backtrace,
topology;
bool force;
bool use_tui;
/* IO related settings */
bool io_only,
skip_eagain;
@ -1756,6 +1758,41 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
return ret;
}
/*
* Launch the interactive textual based python script via 'perf script' that
* finds the script, sets up the python environment and passes the global
* input_name (set by -i) to the script as '-i <input_name>'.
*/
static int timechart__tui(struct timechart *tchart)
{
struct process_filter *filt;
const char **script_argv;
int script_argc = 0, nr_args = 5, ret;
for (filt = process_filter; filt; filt = filt->next)
nr_args += 2;
script_argv = calloc(nr_args + 1, sizeof(*script_argv));
if (!script_argv)
return -ENOMEM;
script_argv[script_argc++] = "script";
script_argv[script_argc++] = "ttimechart";
script_argv[script_argc++] = "--";
if (tchart->power_only)
script_argv[script_argc++] = "-P";
if (tchart->tasks_only)
script_argv[script_argc++] = "-T";
for (filt = process_filter; filt; filt = filt->next) {
script_argv[script_argc++] = "-p";
script_argv[script_argc++] = filt->name;
}
ret = cmd_script(script_argc, script_argv);
free(script_argv);
return ret;
}
static int timechart__io_record(int argc, const char **argv, const char *output_data)
{
unsigned int rec_argc, i;
@ -2079,6 +2116,8 @@ int cmd_timechart(int argc, const char **argv)
"merge events that are merge-dist us apart",
parse_time),
OPT_BOOLEAN('f', "force", &tchart.force, "don't complain, do it"),
OPT_BOOLEAN(0, "tui", &tchart.use_tui,
"interactive terminal timechart using the ttimechart python script"),
OPT_PARENT(timechart_common_options),
};
const char * const timechart_subcommands[] = { "record", NULL };
@ -2146,6 +2185,11 @@ int cmd_timechart(int argc, const char **argv)
} else if (argc)
usage_with_options(timechart_usage, timechart_options);
if (tchart.use_tui) {
ret = timechart__tui(&tchart);
goto out;
}
setup_pager();
ret = __cmd_timechart(&tchart, output_name);

1807
tools/perf/python/ttimechart.py Executable file

File diff suppressed because it is too large Load Diff