From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 0/4] perf timechart: Small optimization for backtrace
Date: Thu, 4 Jun 2026 16:34:58 -0700 [thread overview]
Message-ID: <aiILolfi8MA27v2L@google.com> (raw)
In-Reply-To: <CAP-5=fU3JO3b+bPYzZd=TKoxDy4xYMgGXVtCZq6W3Lh3LNN8YA@mail.gmail.com>
Hi Ian,
On Thu, Jun 04, 2026 at 03:38:05PM -0700, Ian Rogers wrote:
> On Thu, Jun 4, 2026 at 2:49 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > Hello,
> >
> > I found an issue int timechart backtrace handling during the last review.
> > The goal is to reduce unnecessary work in generating backtrace string.
> >
> > v2 changes)
> > * fix memory leaks when backtrace is not used
> > * copy backtrace when it's used twice
>
> Hi Namhyung,
>
> thanks for cleaning this up and the fixes! Running a build of:
> $ make -C tools/perf O=/tmp/perf DEBUG=1
> EXTRA_CFLAGS="-fno-omit-frame-pointer -O0 -g -fsanitize=address" clean
> all
>
> I get an error but the test harness makes it look like the test is
> passing (I added set -x to the test and removed the "> /dev/null
> 2>&1"):
> ```
> $ sudo /tmp/perf/perf test -vv timechart
> 136: perf timechart tests
> 136: perf timechart tests:
> ---- start ----
> test child forked, pid 937043
> + err=0
> ++ mktemp /tmp/__perf_timechart_test.perf.data.XXXXX
> + perfdata=/tmp/__perf_timechart_test.perf.data.cXMvK
> ++ mktemp /tmp/__perf_timechart_test.output.XXXXX.svg
> + output=/tmp/__perf_timechart_test.output.xZXfy.svg
> + trap trap_cleanup EXIT TERM INT
> + perf check feature -q libtraceevent
> + test_timechart
> + echo 'Basic perf timechart test'
> Basic perf timechart test
> + perf timechart record -o /tmp/__perf_timechart_test.perf.data.cXMvK true
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 4.135 MB
> /tmp/__perf_timechart_test.perf.data.cXMvK (748 samples) ]
>
> =================================================================
> ==937049==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 136 byte(s) in 1 object(s) allocated from:
> #0 0x7fd211119a23 in calloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:74
> #1 0x555c44044416 in timechart__record ~/linux/tools/perf/builtin-timech
> art.c:1895
> #2 0x555c44046c19 in cmd_timechart ~/linux/tools/perf/builtin-timechart.
> c:2073
> #3 0x555c440828a4 in run_builtin ~/linux/tools/perf/perf.c:348
> #4 0x555c44082d42 in handle_internal_command ~/linux/tools/perf/perf.c:3
> 98
> #5 0x555c44083110 in run_argv ~/linux/tools/perf/perf.c:442
> #6 0x555c44083667 in main ~/linux/tools/perf/perf.c:549
> #7 0x7fd206e29f76 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
> #8 0x7fffcf8a352a ([stack]+0x2052a)
>
> Direct leak of 10 byte(s) in 2 object(s) allocated from:
> #0 0x7fd211113e20 in strdup
> ../../../../src/libsanitizer/asan/asan_interceptors.cpp:593
> #1 0x555c440444a1 in timechart__record ~/linux/tools/perf/builtin-timech
> art.c:1902
> #2 0x555c44046c19 in cmd_timechart ~/linux/tools/perf/builtin-timechart.
> c:2073
> #3 0x555c440828a4 in run_builtin ~/linux/tools/perf/perf.c:348
> #4 0x555c44082d42 in handle_internal_command ~/linux/tools/perf/perf.c:3
> 98
> #5 0x555c44083110 in run_argv ~/linux/tools/perf/perf.c:442
> #6 0x555c44083667 in main ~/linux/tools/perf/perf.c:549
> #7 0x7fd206e29f76 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
> #8 0x7fffcf8a352a ([stack]+0x2052a)
>
> Indirect leak of 44 byte(s) in 4 object(s) allocated from:
> #0 0x7fd211113e20 in strdup
> ../../../../src/libsanitizer/asan/asan_interceptors.cpp:593
> #1 0x555c440445ef in timechart__record ~/linux/tools/perf/builtin-timech
> art.c:1908
> #2 0x555c44046c19 in cmd_timechart ~/linux/tools/perf/builtin-timechart.
> c:2073
> #3 0x555c440828a4 in run_builtin ~/linux/tools/perf/perf.c:348
> #4 0x555c44082d42 in handle_internal_command ~/linux/tools/perf/perf.c:3
> 98
> #5 0x555c44083110 in run_argv ~/linux/tools/perf/perf.c:442
> #6 0x555c44083667 in main ~/linux/tools/perf/perf.c:549
> #7 0x7fd206e29f76 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
> #8 0x7fffcf8a352a ([stack]+0x2052a)
>
> Indirect leak of 41 byte(s) in 4 object(s) allocated from:
> #0 0x7fd211113e20 in strdup
> ../../../../src/libsanitizer/asan/asan_interceptors.cpp:593
> #1 0x555c44044696 in timechart__record ~/linux/tools/perf/builtin-timech
> art.c:1911
> #2 0x555c44046c19 in cmd_timechart ~/linux/tools/perf/builtin-timechart.
> c:2073
> #3 0x555c440828a4 in run_builtin ~/linux/tools/perf/perf.c:348
> #4 0x555c44082d42 in handle_internal_command ~/linux/tools/perf/perf.c:3
> 98
> #5 0x555c44083110 in run_argv ~/linux/tools/perf/perf.c:442
> #6 0x555c44083667 in main ~/linux/tools/perf/perf.c:549
> #7 0x7fd206e29f76 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
> #8 0x7fffcf8a352a ([stack]+0x2052a)
>
> Indirect leak of 11 byte(s) in 4 object(s) allocated from:
> #0 0x7fd211113e20 in strdup
> ../../../../src/libsanitizer/asan/asan_interceptors.cpp:593
> #1 0x555c440444a1 in timechart__record ~/linux/tools/perf/builtin-timech
> art.c:1902
> #2 0x555c44046c19 in cmd_timechart ~/linux/tools/perf/builtin-timechart.
> c:2073
> #3 0x555c440828a4 in run_builtin ~/linux/tools/perf/perf.c:348
> #4 0x555c44082d42 in handle_internal_command ~/linux/tools/perf/perf.c:3
> 98
> #5 0x555c44083110 in run_argv ~/linux/tools/perf/perf.c:442
> #6 0x555c44083667 in main ~/linux/tools/perf/perf.c:549
> #7 0x7fd206e29f76 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
> #8 0x7fffcf8a352a ([stack]+0x2052a)
>
> SUMMARY: AddressSanitizer: 242 byte(s) leaked in 15 allocation(s).
> + echo 'Basic perf timechart test [Skipped: perf timechart record
> failed (permissions/events?)]'
> Basic perf timechart test [Skipped: perf timechart record failed
> (permissions/events?)]
> + return
> + cleanup
> + rm -f /tmp/__perf_timechart_test.perf.data.cXMvK
> + rm -f /tmp/__perf_timechart_test.output.xZXfy.svg
> + trap - EXIT TERM INT
> + exit 0
> ---- end(0) ----
> 136: perf timechart tests
> : Ok
> ```
>
> It was this test that I was trying to make leak sanitizer clean when
> doing my fixes.
I think these leaks are pre-existing. I don't see where it frees cpu
samples and other events. I'll take a look and send a fix separately.
Thanks,
Namhyung
prev parent reply other threads:[~2026-06-04 23:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 21:49 [PATCH v2 0/4] perf timechart: Small optimization for backtrace Namhyung Kim
2026-06-04 21:49 ` [PATCH v2 1/4] perf timechart: Don't pass @event to cat_backtrace() Namhyung Kim
2026-06-04 21:49 ` [PATCH v2 2/4] perf timechart: Generate backtrace only if needed Namhyung Kim
2026-06-04 21:49 ` [PATCH v2 3/4] perf timechart: Remove unused backtrace in trace_handler Namhyung Kim
2026-06-04 21:49 ` [PATCH v2 4/4] perf timechart: Remove unnecessary copy of backtrace Namhyung Kim
2026-06-04 22:38 ` [PATCH v2 0/4] perf timechart: Small optimization for backtrace Ian Rogers
2026-06-04 23:34 ` Namhyung Kim [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aiILolfi8MA27v2L@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.