From nobody Mon Jun 8 07:23:01 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 3C9DF329E6C; Thu, 4 Jun 2026 21:49:32 +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=1780609774; cv=none; b=EHhud9q1CmWFNKlutNtesw96XssSAJjYGQ+Nr/nFD3daQ5qo1fXQZXzVOkVdFSpWnUfOaIw8hEWzqV5kHEgCcSjZLpX8e6W9eBJn7dkypl/B4HPH+umXFLaBez/59fCHGFsrGtxBO935GL7+vPiLvlAQ0uy7vDkaEca06Uxwze8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780609774; c=relaxed/simple; bh=s9T70sQxiQJvjGYD/9kQcsxcsPLn/NwTDO7wW7XLcLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+KbCn56aTm7CRNJ26se/AWIQtQWLW64zNHA1ak36p9sPkbmkC8ne8v5Ou1iN/WUOxVLIgxyw8yCZhDr71aaCuHhf4uuLzFJmf3zMX3hHSTZqRRRh4jS0UfsdBrMPhCgZXTJw+GE40+jY7zulE+HdH/YujcG5YfGI0Fsg3Dtm5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPI2RBfp; 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="KPI2RBfp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F5361F00898; Thu, 4 Jun 2026 21:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780609772; bh=X7r0P5w2HbxKFj1JMinted+quLZ0T7Kak6r1aDsmJWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KPI2RBfpXISn6d3ycTjkmMCEmyS6abmqRurYMVtU8sFLxgpDMwAH5+7jcglLulMIi UIfn1RYZind/ZvkP4Y5cBtQGdvWlLpEwxeDu/HuFsvQOsQHcLZ6jZTQ508pAfl+W0/ EXFftecI8XNyIk2/tvT60vJJblbocdryfVF8Kmv+1rpE7ZjNDpW/YLb2H9xLhSSeu0 m8ETYXiPgD+ipve4gxDQIHjKR2plOPGGqoS1a6jbgnkedyfSMoP+XvhB1ohYEjTjZF jBMHPXfzLZqrZZkBzXKaIE3dQ9ObLvaHOezVS5e8l5pMZlTWv4/MCeBWvADjQhR2sv PzQMh5hDWnL4Q== 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 v2 1/4] perf timechart: Don't pass @event to cat_backtrace() Date: Thu, 4 Jun 2026 14:49:27 -0700 Message-ID: <20260604214931.2202322-2-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604214931.2202322-1-namhyung@kernel.org> References: <20260604214931.2202322-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:23:01 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 54269377563; Thu, 4 Jun 2026 21:49:33 +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=1780609774; cv=none; b=m2gXT7uC/PcAC/UgdpPysfT779KBiiNZYWCAE8/mOODWA8mS4516FrJQ2NiRilrBskzOmgzY274m9PqmmoxlV0uyjKSJY5LXTU/8W3S9norEpcPblr29ddhp/H6fDoMzBu7Xwb8yxdqebIfSUu2QV0Fp8FVxuxMCctDto6NQURs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780609774; c=relaxed/simple; bh=MmD10+K+SOetY9s8vYbxiW2ds80rp9fUZttdunNkuZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oRD5BSQ1n1QpJPZ5bmy2HyKVlxzrhUywyMBvrlXv/NVI5+YNyGs3aWN9sEYx+DbLqy+kArKQLCOntplQaoVjQIf5AN8p1iYbfQPX8tw8xH28wJPPhAzDjqDZLkL1yWVKw16o1Yniojkna7sNCDCovuEj2+6u/UQPFrPfApvZe0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=itB/hEqx; 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="itB/hEqx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F11311F00899; Thu, 4 Jun 2026 21:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780609773; bh=XGd7nZPU7g+n5UU8EOXjz8Hg+yquzcf4PxcMBg6MSCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=itB/hEqxXNPoWVBoFxSJNVvUm10LvHD1utYzxNPeCpmoBzvOrT9wq9+YSSJeOuzaT MywJXoTo5fDr8hzxKfzJd2gK0ykYs68RbPxCVkuHE4VN2ZFFugrE6baiba6jfuqhNs RpqLKtCQbKDopyM3VqhdlFd9T4N3IGiXzvhaLQuf9LF7UjZBqbUvF2tyaVYol5iZ5y kJxsr17XiC6K5kDE0+7vl02alqr4BVLKQ+7qSFK7bixdaqWyTsXVdVW0dVmsWOIkZT tW6XqF/ET/BnQwPsil7vaLK806EPe+/yK9MAWWWoPg6F+7HPY1FVd/juv1N2gffD1x xQTXJXgYP9aVQ== 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 v2 2/4] perf timechart: Generate backtrace only if needed Date: Thu, 4 Jun 2026 14:49:28 -0700 Message-ID: <20260604214931.2202322-3-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604214931.2202322-1-namhyung@kernel.org> References: <20260604214931.2202322-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:23:01 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 B61A236607C; Thu, 4 Jun 2026 21:49:33 +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=1780609774; cv=none; b=bLJSK7dJ/awahMUdtCoS92eDtiqTIwd0p+1CXb1svyfY6Xnef9Jvs+djTNnlyfXaox8gjm1RyGtMHyjK0EGxB6pEC9HDLXaHlqKND7I2x5346uvIpWUIkmFeo0qfimcGXwzAmnzatBZyAr10iOU5ACCXuDEdc4l0FP1mhj1xNew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780609774; 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=i3nC+rLeR+449EhN8AXYnutIPgwHI1r0vyvrTuug+ZlchWshTuOV/NQWWOlwP/UBFD2QFfGg8vItxsi9nEbzpIJQL94kYTZ0VQ7TWwuWK6Iy4HnmkOQAz173BsH3QGctCGYyhCsT3JOk3HmsdZhXIngNEfM1JTxEXAmYFAVDWeo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n2z/5ADI; 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="n2z/5ADI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D7D41F0089C; Thu, 4 Jun 2026 21:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780609773; bh=N+VvgQE3Pcoy6/O8RxZuhyvDE6MlJ/x53ALB+DgYqaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n2z/5ADI4c2LeondsstBA/Kq18KoHuv1gdFdixoYPNBrszQPvUNOEeOHJJ44UXeFN C3Pgru60BJrupRERWTbsedaO7bEBFFNTaG8BW1C5FS3nVd49gQXk9+qtiR35yxKwe0 rZCialWAm/zi8wpqLb/ZpAqZXnZk7AbywgVnR7OWjWAGnRxot/9B3Hf+hgewedMNoN lTK30vSTIzPzJWAbS9esOMqquanQfAeTJGtLVMIkAzFXCJdHmyQFVYVOex4Y0t+XN6 j5oL49Unqw4ID+qTcX/WNY/Giji6WPNreS+iGjCMRGg9QQLfrTIvg0FEAA/6wMcjY3 +2Yjw4bReMDGw== 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 v2 3/4] perf timechart: Remove unused backtrace in trace_handler Date: Thu, 4 Jun 2026 14:49:29 -0700 Message-ID: <20260604214931.2202322-4-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604214931.2202322-1-namhyung@kernel.org> References: <20260604214931.2202322-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:23:01 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 52A053AB298; Thu, 4 Jun 2026 21:49:34 +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=1780609775; cv=none; b=mYaodILeVaes1qLPGYWNYXHLL/wCPO2/w63A3fHbvXiH22b34JpLbz7in/UayyjrcseTJFcCxFzYosLgszy6KkWxWxVmV/6AwN5fuTo3+w42y7AhOjSPIef5qgyFnTYQD/6jSGKHdshJ8ywFiI0wvVBYVCYsxa0wH58607U0agc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780609775; c=relaxed/simple; bh=v99ERl0mvlavTFiAOqQv/oE8nGh7o84bP2ip0E5pQ3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ijQy5yk3uA3oZBi8V5Yi7uvD+Zl1K7Oy3detSEnKAWZ89zObzFb860/PAXCVnemQAEnRvBgFO4PwiTlh0w1v7nHJpsjL+yrQ0IHI4m1juYbfnfKKel5Ama/s5JIpCpkMQ+HOIrljmKTKvwTWD2V8GU6Y27ZBUCYchdhsQo+gD5Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JSTR/qyK; 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="JSTR/qyK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BED571F00893; Thu, 4 Jun 2026 21:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780609774; bh=5UAw5XE5RZgXmMye4BK+b2VKFEwiLzlKG3Am1FCVSlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JSTR/qyKXXK8Oehbr+uNLKsFkv+0ZzkPK27s/ZLBsR+Kwl85XejfKGhdSpqfLPpGR fjeSJrorDIABTejer2c1X2dgkg8c560n0pFhy+tdHdwWwAaHi8Z6HBgIBSL10tFdmG zwTdFn9JCCB65SWr5jRIuAk3TYSal7XZRcGSW0h63vSvz7kCGZqchRJ9yEi4tJShQz NvjvYghnlvSe3vnMac3cIsJt/y5VDXN5L9dEJJ8cbIm9djOjB0w8Ixo76xiAsGjOgm myu9mItnxyQEAOkz0/skUa4Qy2BDafBXDNKOEE/ZoldEK5dzgUGTVF+EZOMZi8dp3u Tp3U7pDSf+LYg== 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 v2 4/4] perf timechart: Remove unnecessary copy of backtrace Date: Thu, 4 Jun 2026 14:49:30 -0700 Message-ID: <20260604214931.2202322-5-namhyung@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260604214931.2202322-1-namhyung@kernel.org> References: <20260604214931.2202322-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 | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 4efac73a714c5e5f..04dbb944a42720b4 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) { @@ -429,12 +429,14 @@ static void sched_wakeup(struct timechart *tchart, in= t cpu, u64 timestamp, struct per_pid *p; struct wake_event *we =3D zalloc(sizeof(*we)); =20 - if (!we) + if (!we) { + free((char *)backtrace); return; + } =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; @@ -461,20 +463,28 @@ static void sched_switch(struct timechart *tchart, in= t cpu, u64 timestamp, const char *backtrace) { struct per_pid *p =3D NULL, *prev_p; + bool backtrace_used =3D false; =20 prev_p =3D find_create_pid(tchart, prev_pid); =20 p =3D find_create_pid(tchart, next_pid); =20 - if (prev_p->current && prev_p->current->state !=3D TYPE_NONE) + if (prev_p->current && prev_p->current->state !=3D TYPE_NONE) { pid_put_sample(tchart, prev_pid, TYPE_RUNNING, cpu, prev_p->current->state_since, timestamp, backtrace); + backtrace_used =3D true; + } if (p && p->current) { - if (p->current->state !=3D TYPE_NONE) + if (p->current->state !=3D TYPE_NONE) { + if (backtrace && backtrace_used) + backtrace =3D strdup(backtrace); + pid_put_sample(tchart, next_pid, p->current->state, cpu, p->current->state_since, timestamp, backtrace); + backtrace_used =3D true; + } =20 p->current->state_since =3D timestamp; p->current->state =3D TYPE_RUNNING; @@ -488,6 +498,9 @@ static void sched_switch(struct timechart *tchart, int = cpu, u64 timestamp, if (prev_state =3D=3D 0) prev_p->current->state =3D TYPE_WAITING; } + + if (!backtrace_used) + free((char *)backtrace); } =20 /* @@ -655,7 +668,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 +690,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