[PATCH v3 20/25] perf timechart: Don't pass evsel with sample

From: Ian Rogers

Date: Fri Mar 20 2026 - 04:13:33 EST


The sample contains the evsel and so it is unnecessary to pass the
evsel as well. Add missing backtrace argument to tracepoint_handler
functions and mark them unused. Fix missing free from cat_backtrace.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/builtin-timechart.c | 71 ++++++++++++++++------------------
1 file changed, 33 insertions(+), 38 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 657aab126477..13edcfe39d2d 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -489,9 +489,9 @@ static void sched_switch(struct timechart *tchart, int cpu, u64 timestamp,
}
}

-static const char *cat_backtrace(union perf_event *event,
- struct perf_sample *sample,
- struct machine *machine)
+static char *cat_backtrace(union perf_event *event,
+ struct perf_sample *sample,
+ struct machine *machine)
{
struct addr_location al;
unsigned int i;
@@ -567,7 +567,6 @@ static const char *cat_backtrace(union perf_event *event,
}

typedef int (*tracepoint_handler)(struct timechart *tchart,
- struct evsel *evsel,
struct perf_sample *sample,
const char *backtrace);

@@ -578,6 +577,7 @@ static int process_sample_event(const struct perf_tool *tool,
{
struct timechart *tchart = container_of(tool, struct timechart, tool);
struct evsel *evsel = sample->evsel;
+ int ret = 0;

if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) {
if (!tchart->first_time || tchart->first_time > sample->time)
@@ -588,16 +588,17 @@ static int process_sample_event(const struct perf_tool *tool,

if (evsel->handler != NULL) {
tracepoint_handler f = evsel->handler;
- return f(tchart, evsel, sample,
- cat_backtrace(event, sample, machine));
+ char *backtrace = cat_backtrace(event, sample, machine);
+
+ ret = f(tchart, sample, backtrace);
+ free(backtrace);
}

- return 0;
+ return ret;
}

static int
process_sample_cpu_idle(struct timechart *tchart __maybe_unused,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace __maybe_unused)
{
@@ -617,7 +618,6 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused,

static int
process_sample_cpu_frequency(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace __maybe_unused)
{
@@ -630,7 +630,6 @@ process_sample_cpu_frequency(struct timechart *tchart,

static int
process_sample_sched_wakeup(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace)
{
@@ -644,7 +643,6 @@ process_sample_sched_wakeup(struct timechart *tchart,

static int
process_sample_sched_switch(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace)
{
@@ -660,7 +658,6 @@ process_sample_sched_switch(struct timechart *tchart,
#ifdef SUPPORT_OLD_POWER_EVENTS
static int
process_sample_power_start(struct timechart *tchart __maybe_unused,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace __maybe_unused)
{
@@ -673,7 +670,6 @@ process_sample_power_start(struct timechart *tchart __maybe_unused,

static int
process_sample_power_end(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace __maybe_unused)
{
@@ -683,7 +679,6 @@ process_sample_power_end(struct timechart *tchart,

static int
process_sample_power_frequency(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
struct perf_sample *sample,
const char *backtrace __maybe_unused)
{
@@ -853,8 +848,8 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type,

static int
process_enter_read(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long fd = perf_sample__intval(sample, "fd");
return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ,
@@ -863,8 +858,8 @@ process_enter_read(struct timechart *tchart,

static int
process_exit_read(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long ret = perf_sample__intval(sample, "ret");
return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ,
@@ -873,8 +868,8 @@ process_exit_read(struct timechart *tchart,

static int
process_enter_write(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long fd = perf_sample__intval(sample, "fd");
return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE,
@@ -883,8 +878,8 @@ process_enter_write(struct timechart *tchart,

static int
process_exit_write(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long ret = perf_sample__intval(sample, "ret");
return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE,
@@ -893,8 +888,8 @@ process_exit_write(struct timechart *tchart,

static int
process_enter_sync(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long fd = perf_sample__intval(sample, "fd");
return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC,
@@ -903,8 +898,8 @@ process_enter_sync(struct timechart *tchart,

static int
process_exit_sync(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long ret = perf_sample__intval(sample, "ret");
return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC,
@@ -913,8 +908,8 @@ process_exit_sync(struct timechart *tchart,

static int
process_enter_tx(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long fd = perf_sample__intval(sample, "fd");
return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX,
@@ -923,8 +918,8 @@ process_enter_tx(struct timechart *tchart,

static int
process_exit_tx(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long ret = perf_sample__intval(sample, "ret");
return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX,
@@ -933,8 +928,8 @@ process_exit_tx(struct timechart *tchart,

static int
process_enter_rx(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long fd = perf_sample__intval(sample, "fd");
return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX,
@@ -943,8 +938,8 @@ process_enter_rx(struct timechart *tchart,

static int
process_exit_rx(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long ret = perf_sample__intval(sample, "ret");
return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX,
@@ -953,8 +948,8 @@ process_exit_rx(struct timechart *tchart,

static int
process_enter_poll(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long fd = perf_sample__intval(sample, "fd");
return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL,
@@ -963,8 +958,8 @@ process_enter_poll(struct timechart *tchart,

static int
process_exit_poll(struct timechart *tchart,
- struct evsel *evsel __maybe_unused,
- struct perf_sample *sample)
+ struct perf_sample *sample,
+ const char *backtrace __maybe_unused)
{
long ret = perf_sample__intval(sample, "ret");
return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL,
--
2.53.0.959.g497ff81fa9-goog