[PATCH 4/4] perf timechart: Remove unnecessary copy of backtrace

From: Namhyung Kim

Date: Thu Jun 04 2026 - 15:08:44 EST


The pattern of strdup() and free() is found, and I think it just can
use the original backtrace directly.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-timechart.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 4efac73a714c5e5f..2fd24d3aaa837743 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -300,7 +300,7 @@ static void pid_put_sample(struct timechart *tchart, int pid, int type,
sample->type = type;
sample->next = c->samples;
sample->cpu = cpu;
- sample->backtrace = backtrace ? strdup(backtrace) : NULL;
+ sample->backtrace = backtrace;
c->samples = sample;

if (sample->type == TYPE_RUNNING && end > start && start > 0) {
@@ -434,7 +434,7 @@ static void sched_wakeup(struct timechart *tchart, int cpu, u64 timestamp,

we->time = timestamp;
we->waker = waker;
- we->backtrace = backtrace ? strdup(backtrace) : NULL;
+ we->backtrace = backtrace;

if ((flags & TRACE_FLAG_HARDIRQ) || (flags & TRACE_FLAG_SOFTIRQ))
we->waker = -1;
@@ -655,7 +655,6 @@ process_sample_sched_wakeup(struct timechart *tchart,

backtrace = cat_backtrace(sample, &tchart->session->machines.host);
sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace);
- free((char *)backtrace);
return 0;
}

@@ -678,7 +677,6 @@ process_sample_sched_switch(struct timechart *tchart,
backtrace = cat_backtrace(sample, &tchart->session->machines.host);
sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid,
prev_state, backtrace);
- free((char *)backtrace);
return 0;
}

--
2.54.0.1032.g2f8565e1d1-goog