From nobody Mon Jun 8 07:22:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ADDF37646E; Thu, 4 Jun 2026 19:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600095; cv=none; b=bygHsnZTA+c6yiRuDbo90nznJkG+RXMic1TDPTEZXymEfPQT68/E2utYhL7r9rZNg+gTlxy/NTGnqfQGSosBX8AediCROeaXBKh2R/37BSA2xOL3XJ0VuIItXZEQvjIb3MvAV6eyQBa+brXrNJ5IdDys9wislmSNQHtApH7Hg5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600095; c=relaxed/simple; bh=s9T70sQxiQJvjGYD/9kQcsxcsPLn/NwTDO7wW7XLcLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I3z0XRJS4hr7hln6dOR9NHtyQuiGZ6QbRf6PgO+R+2LWI1eJHvtMcck0wRlGqQC+k428cgejjCBNQXIglNEnOIYNWzHcyCnRU07flmqHgD27a80xNjIHcJ3QJNJOMXmT9YypQGpQ16M5P/507sFNuouXlxA7WAG8O2QeX4y/BPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lOGFM32c; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lOGFM32c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2F941F0089B; Thu, 4 Jun 2026 19:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780600093; bh=X7r0P5w2HbxKFj1JMinted+quLZ0T7Kak6r1aDsmJWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lOGFM32cUMm5Kj0GvDtKRYbIhLqt2SxkhpVm/ZS2WW56TxO88RRbpUJI5TrvlMeN5 7GjdLItdjzpUPewYIlmuQwVzOZZUWDdr2EW3F+Z1oThufnLX9t/SzV37pZNfrZHHQN h1Eh4jMP/cOCGSqAbT7jgmHU97Q5HGmCKRBBDAZTQRmh2OJ5GAqA78Udnik8vvEvlc lhnn/brffynfgU7HEfY48OzWQXRJ2XbWAq7/UXiGTa/WR7y6SI8mUi1ehIlJkBIr6U pyCPCIVu0Ckc9ikkeNYJQKrukSvZ4dHgqX933muh7IhjQ79JQ8P822BNoF+m2RcBR6 eXqQ8s/NHikPQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/4] perf timechart: Don't pass @event to cat_backtrace() Date: Thu, 4 Jun 2026 12:08:07 -0700 Message-ID: <20260604190812.2168118-2-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604190812.2168118-1-namhyung@kernel.org> References: <20260604190812.2168118-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The cat_backtrace() is only called from process_sample_event() which means the event type is always PERF_RECORD_SAMPLE. We don't need to pass the event just because to print already known info. Signed-off-by: Namhyung Kim --- tools/perf/builtin-timechart.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 85a9ad0455aecccd..dafd361ecf9d8cd7 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -493,8 +493,7 @@ static void sched_switch(struct timechart *tchart, int = cpu, u64 timestamp, * Returns a malloc'd backtrace string built via open_memstream, or NULL * on error. Caller must free() the returned pointer. */ -static char *cat_backtrace(union perf_event *event, - struct perf_sample *sample, +static char *cat_backtrace(struct perf_sample *sample, struct machine *machine) { struct addr_location al; @@ -516,9 +515,8 @@ static char *cat_backtrace(union perf_event *event, goto exit; =20 if (machine__resolve(machine, &al, sample) < 0) { - pr_err("problem processing %s (%u) event at offset %#" PRIx64 ", skippin= g it.\n", - perf_event__name(event->header.type), event->header.type, - sample->file_offset); + pr_err("problem processing SAMPLE (%u) event at offset %#" PRIx64 ", ski= pping it.\n", + PERF_RECORD_SAMPLE, sample->file_offset); goto exit; } =20 @@ -578,7 +576,7 @@ typedef int (*tracepoint_handler)(struct timechart *tch= art, const char *backtrace); =20 static int process_sample_event(const struct perf_tool *tool, - union perf_event *event, + union perf_event *event __maybe_unused, struct perf_sample *sample, struct machine *machine) { @@ -595,7 +593,7 @@ static int process_sample_event(const struct perf_tool = *tool, =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - char *backtrace =3D cat_backtrace(event, sample, machine); + char *backtrace =3D cat_backtrace(sample, machine); =20 ret =3D f(tchart, sample, backtrace); free(backtrace); --=20 2.54.0.1032.g2f8565e1d1-goog From nobody Mon Jun 8 07:22:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7221437997E; Thu, 4 Jun 2026 19:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600095; cv=none; b=DqbRJyveyvSz/0mOy2/ib8a9IINbZw3WtqoveTq2kBKemq86SB/Q/XCbYUbRofkiVd7EmU/LyZ7mg4G8zTr8D/94cZH42stoXT2n57HW7M21F3E/ynbAerhvyvDeUsMZRjUPD32DX+AMkWPzNTmemjHlt2FOKaW2UKNTyLUdZ5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600095; c=relaxed/simple; bh=MmD10+K+SOetY9s8vYbxiW2ds80rp9fUZttdunNkuZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RTYPPDslKlUkA/Jlt7rfQz2djJ0N3k8FQ5e13oEXmFh/znOiz6GQTu4zsh632qp9udZvtGmA0IdLnHSr9xgvZaWzweO0G1ntyKGFl2MkubPKdHehFzIooQ4+x0lUDNFkIUFaCBMdk2/S20vRpZlSfwOZ6D7h5UZe96Sg8z7IQwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XbhXE1sk; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XbhXE1sk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17CBA1F0089A; Thu, 4 Jun 2026 19:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780600094; bh=XGd7nZPU7g+n5UU8EOXjz8Hg+yquzcf4PxcMBg6MSCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XbhXE1skzUaJM4//QhEdwym8yVL2lmgg6v0fJwbo3XU+XD9plvntA08tFgQarh1SC JQ0HbIKnpG4EO42sy/Q+s94nIeFAShk8J6pgO/okOYV6hUs2iQHPFKuFJuxK5VYM3P SocKRS0k8RVvIgMV1phXemfntBbc08eqy5lC9tS4f8KgzkBi9DlnmI4+3ciwfBc94T xezuxm0XxUy+r0a4NjUKMwbzsDdoq8TSD2zlMWBqKEcjkoW5zHEndCuBF6evtqROpq JovDlyW3uE7BW56nUL+9zd0gKo4CJ23JN9Y2fJtCi1ATzRHZXIgebKAu7byYaH5j09 ZuMjgRT1dhz7g== From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/4] perf timechart: Generate backtrace only if needed Date: Thu, 4 Jun 2026 12:08:08 -0700 Message-ID: <20260604190812.2168118-3-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604190812.2168118-1-namhyung@kernel.org> References: <20260604190812.2168118-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The backtrace was used by sched-switch and sched-wakeup only. No need to call cat_backtrace() in the process_sample_event(). Let's pass NULL backtrace and generate it from the sched events. As it needs a pointer to the 'machine', let's save the session in the timechart struct and use the host machine of the session instead of passing the pointer to all handlers. It should be fine to assume the host machine as timechart command doesn't deal with guest machines and there's no way to get tracepoints from the guest events. Signed-off-by: Namhyung Kim --- tools/perf/builtin-timechart.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index dafd361ecf9d8cd7..337ae547d008ea0b 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -56,6 +56,7 @@ struct timechart { struct per_pid *all_data; struct power_event *power_events; struct wake_event *wake_events; + struct perf_session *session; int proc_num; unsigned int numcpus; u64 min_freq, /* Lowest CPU frequency seen */ @@ -578,7 +579,7 @@ typedef int (*tracepoint_handler)(struct timechart *tch= art, static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, - struct machine *machine) + struct machine *machine __maybe_unused) { struct timechart *tchart =3D container_of(tool, struct timechart, tool); struct evsel *evsel =3D sample->evsel; @@ -593,10 +594,8 @@ static int process_sample_event(const struct perf_tool= *tool, =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - char *backtrace =3D cat_backtrace(sample, machine); =20 - ret =3D f(tchart, sample, backtrace); - free(backtrace); + ret =3D f(tchart, sample, NULL); } =20 return ret; @@ -656,7 +655,10 @@ process_sample_sched_wakeup(struct timechart *tchart, sample->file_offset, sample->cpu); return -1; } + + backtrace =3D cat_backtrace(sample, &tchart->session->machines.host); sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, back= trace); + free((char *)backtrace); return 0; } =20 @@ -675,8 +677,11 @@ process_sample_sched_switch(struct timechart *tchart, sample->file_offset, sample->cpu); return -1; } + + backtrace =3D 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; } =20 @@ -1661,6 +1666,7 @@ static int __cmd_timechart(struct timechart *tchart, = const char *output_name) if (IS_ERR(session)) return PTR_ERR(session); =20 + tchart->session =3D session; symbol__init(perf_session__env(session)); =20 (void)perf_header__process_sections(&session->header, --=20 2.54.0.1032.g2f8565e1d1-goog From nobody Mon Jun 8 07:22:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E12CA372069; Thu, 4 Jun 2026 19:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600096; cv=none; b=i1LVnJP2mMj3gaJgt48WGOiXz9u8/fB0ZP3Dgve1JBq6f4NfgKD+zt2TsaXr4cGKJt9/7mMc0t3SV8h4BpIZpJSTHxLaT5MsEK/L7+oZgOYiFJd4EmEmSNsXr0uTYhQJuuf16lJzY+fyt6HYQtJDZspsV1OEzhnBZzXIzNNVvww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600096; c=relaxed/simple; bh=I09/5Vx7pX70v3M6E8LVuJiEffdvMyax+D/hwDY7iJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gJwO85G+n6TVVL3WTlQW1IRG7C1Qca7oQ4SYkK7DHzvqLOsaFPN/Zs7AH4R5IYNJfy2PkDhjTRdFq8Xt5nKdolorgd+zk8peTj1do6PWUyYmrZapbbqy+E5ufdzkF93F1c0AugPMuBRO2ohA+RYSJQSaTJbpvk2CF410CA6VD/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lIK6icBn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lIK6icBn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C87B1F0089D; Thu, 4 Jun 2026 19:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780600094; bh=N+VvgQE3Pcoy6/O8RxZuhyvDE6MlJ/x53ALB+DgYqaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lIK6icBngI7gJ8KwsqVy3dIa61s1eUe8e9LquXU45O1tRoAz8QvFuH3JnU+NoIURj 8TSBSa6q9jAdIKJ3cGbj7C4hLWc1Ua2B+3VL0zaiptduiyqadDe8KKeiK+SQKgiINd B0tUzliNeQAQ1wN1vrw5UXZN1qNgMgewmC1dHxELREJg82W2oOt220ntczWG9LZSL/ 9MsLMuvmzcor6dPAxS386ytOCWvV8UTGY1vpBlhksGWicY44xmdAx4l01AJ7Pdoixi ssNGIhtM7Yw7oeC3AJEGkHUrc5kpOb93ix3p/7c24+P1O1QkXElYN9xwZa3uwaYVxp hK3W9w2w6+s6w== From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 3/4] perf timechart: Remove unused backtrace in trace_handler Date: Thu, 4 Jun 2026 12:08:09 -0700 Message-ID: <20260604190812.2168118-4-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604190812.2168118-1-namhyung@kernel.org> References: <20260604190812.2168118-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Now the backtrace argument is not used in any handler. Let's get rid of it. Signed-off-by: Namhyung Kim --- tools/perf/builtin-timechart.c | 64 ++++++++++++---------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 337ae547d008ea0b..4efac73a714c5e5f 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -573,8 +573,7 @@ static char *cat_backtrace(struct perf_sample *sample, } =20 typedef int (*tracepoint_handler)(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace); + struct perf_sample *sample); =20 static int process_sample_event(const struct perf_tool *tool, union perf_event *event __maybe_unused, @@ -595,7 +594,7 @@ static int process_sample_event(const struct perf_tool = *tool, if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; =20 - ret =3D f(tchart, sample, NULL); + ret =3D f(tchart, sample); } =20 return ret; @@ -603,8 +602,7 @@ static int process_sample_event(const struct perf_tool = *tool, =20 static int process_sample_cpu_idle(struct timechart *tchart __maybe_unused, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { u32 state =3D perf_sample__intval(sample, "state"); u32 cpu_id =3D perf_sample__intval(sample, "cpu_id"); @@ -624,8 +622,7 @@ process_sample_cpu_idle(struct timechart *tchart __mayb= e_unused, =20 static int process_sample_cpu_frequency(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { u32 state =3D perf_sample__intval(sample, "state"); u32 cpu_id =3D perf_sample__intval(sample, "cpu_id"); @@ -642,12 +639,12 @@ process_sample_cpu_frequency(struct timechart *tchart, =20 static int process_sample_sched_wakeup(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace) + struct perf_sample *sample) { u8 flags =3D perf_sample__intval(sample, "common_flags"); int waker =3D perf_sample__intval(sample, "common_pid"); int wakee =3D perf_sample__intval(sample, "pid"); + char *backtrace; =20 /* perf.data is untrusted input =E2=80=94 CPU may be absent or corrupted = */ if (sample->cpu >=3D MAX_CPUS) { @@ -664,12 +661,12 @@ process_sample_sched_wakeup(struct timechart *tchart, =20 static int process_sample_sched_switch(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace) + struct perf_sample *sample) { int prev_pid =3D perf_sample__intval(sample, "prev_pid"); int next_pid =3D perf_sample__intval(sample, "next_pid"); u64 prev_state =3D perf_sample__intval(sample, "prev_state"); + char *backtrace; =20 /* perf.data is untrusted input =E2=80=94 CPU may be absent or corrupted = */ if (sample->cpu >=3D MAX_CPUS) { @@ -688,8 +685,7 @@ process_sample_sched_switch(struct timechart *tchart, #ifdef SUPPORT_OLD_POWER_EVENTS static int process_sample_power_start(struct timechart *tchart __maybe_unused, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { u64 cpu_id =3D perf_sample__intval(sample, "cpu_id"); u64 value =3D perf_sample__intval(sample, "value"); @@ -706,8 +702,7 @@ process_sample_power_start(struct timechart *tchart __m= aybe_unused, =20 static int process_sample_power_end(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { /* perf.data is untrusted input =E2=80=94 CPU may be absent or corrupted = */ if (sample->cpu >=3D MAX_CPUS) { @@ -721,8 +716,7 @@ process_sample_power_end(struct timechart *tchart, =20 static int process_sample_power_frequency(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { u64 cpu_id =3D perf_sample__intval(sample, "cpu_id"); u64 value =3D perf_sample__intval(sample, "value"); @@ -895,8 +889,7 @@ static int pid_end_io_sample(struct timechart *tchart, = int pid, int type, =20 static int process_enter_read(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -905,8 +898,7 @@ process_enter_read(struct timechart *tchart, =20 static int process_exit_read(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ, @@ -915,8 +907,7 @@ process_exit_read(struct timechart *tchart, =20 static int process_enter_write(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -925,8 +916,7 @@ process_enter_write(struct timechart *tchart, =20 static int process_exit_write(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE, @@ -935,8 +925,7 @@ process_exit_write(struct timechart *tchart, =20 static int process_enter_sync(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -945,8 +934,7 @@ process_enter_sync(struct timechart *tchart, =20 static int process_exit_sync(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC, @@ -955,8 +943,7 @@ process_exit_sync(struct timechart *tchart, =20 static int process_enter_tx(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -965,8 +952,7 @@ process_enter_tx(struct timechart *tchart, =20 static int process_exit_tx(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX, @@ -975,8 +961,7 @@ process_exit_tx(struct timechart *tchart, =20 static int process_enter_rx(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -985,8 +970,7 @@ process_enter_rx(struct timechart *tchart, =20 static int process_exit_rx(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX, @@ -995,8 +979,7 @@ process_exit_rx(struct timechart *tchart, =20 static int process_enter_poll(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long fd =3D perf_sample__intval(sample, "fd"); return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL, @@ -1005,8 +988,7 @@ process_enter_poll(struct timechart *tchart, =20 static int process_exit_poll(struct timechart *tchart, - struct perf_sample *sample, - const char *backtrace __maybe_unused) + struct perf_sample *sample) { long ret =3D perf_sample__intval(sample, "ret"); return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL, --=20 2.54.0.1032.g2f8565e1d1-goog From nobody Mon Jun 8 07:22:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 959F9399356; Thu, 4 Jun 2026 19:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600096; cv=none; b=IwX2FQ3Ko7g/eSMaXPrz6TvkACL/n5KElNOu42SVFHKmGMRjdw7tzI113YyHJn5do4bOgUTOF7GS7PlZV8t8QQrFzFTjyAlOg1Pu5wCVgBS/DUxKSK8MXGr9a67oORm3S1EhOn7OvRq2ceqqunCEI4A4Yss25WcsP7gqjxvo5ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780600096; c=relaxed/simple; bh=iVvQK26xzewh/ezcla6riJcZNs4qsd6p4TMQrAhISHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MN8NlsLcng4TTd/5XJ3kirp75/hSCzon3MvaksD8hEuZYfihN5VnTzAqqbSQcLP2sn/PXeeV9qxsNePSbFJWSTM144wGu1SgdZwxJee6U6c4ybL9S0jS1sD5Uy3SuQZD3hp8FrM9iTRHmRTGuJm59AEUkih2oFHBC+BiW+4N+u4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CsghUPJQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CsghUPJQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED7C91F00898; Thu, 4 Jun 2026 19:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780600095; bh=9wFwJ5M3pONz8/3u/PgQq2F5W42CicFiZ39P0JfaKcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CsghUPJQCHys/GmfiisMmt3I1CzrHdLkVEoEb281m1amfyU0lsJQFHKJD/MoZCLlb YmE0HCACIg5FtXEtZu+dE8/6kZZ4lOtqCknIrJkeqRuWqiz/x0u6Tr6hvOa1mZrmrX f0aW5B1qLbxS2hCTRM3qhEb26MW3zizbkGS6E1/6Q0MtHZ0PcP3A4Ip2BFhp+/c0HJ AYPw+wW1BffHN7fHZGRFUvqa8neR6oTExzfZKHgnI5dAZjJ31XU47K11M1TIiPtLZF El5iQXoJFfUSlAVgEBjlxImHU8BjZN7Zzi01gCdVgUiqlkXfcOFRDHrqiiETDkkIJp D0znCRcQoHLgQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 4/4] perf timechart: Remove unnecessary copy of backtrace Date: Thu, 4 Jun 2026 12:08:10 -0700 Message-ID: <20260604190812.2168118-5-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604190812.2168118-1-namhyung@kernel.org> References: <20260604190812.2168118-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The pattern of strdup() and free() is found, and I think it just can use the original backtrace directly. Signed-off-by: Namhyung Kim --- 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, in= t pid, int type, sample->type =3D type; sample->next =3D c->samples; sample->cpu =3D cpu; - sample->backtrace =3D backtrace ? strdup(backtrace) : NULL; + sample->backtrace =3D backtrace; c->samples =3D sample; =20 if (sample->type =3D=3D TYPE_RUNNING && end > start && start > 0) { @@ -434,7 +434,7 @@ static void sched_wakeup(struct timechart *tchart, int = cpu, u64 timestamp, =20 we->time =3D timestamp; we->waker =3D waker; - we->backtrace =3D backtrace ? strdup(backtrace) : NULL; + we->backtrace =3D backtrace; =20 if ((flags & TRACE_FLAG_HARDIRQ) || (flags & TRACE_FLAG_SOFTIRQ)) we->waker =3D -1; @@ -655,7 +655,6 @@ process_sample_sched_wakeup(struct timechart *tchart, =20 backtrace =3D cat_backtrace(sample, &tchart->session->machines.host); sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, back= trace); - free((char *)backtrace); return 0; } =20 @@ -678,7 +677,6 @@ process_sample_sched_switch(struct timechart *tchart, backtrace =3D 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; } =20 --=20 2.54.0.1032.g2f8565e1d1-goog