From: Namhyung Kim <namhyung@kernel.org>
To: Tabby <nyanpasu256@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`?
Date: Sat, 5 Dec 2026 00:20:59 -0800 [thread overview]
Message-ID: <axPJa1vWTn0MDFPd@google.com> (raw)
In-Reply-To: <CAL57YxZ5eVuKC6u0uRN96vx7Hr6Pa+2HgE2mLoj4H087ARoOEQ@mail.gmail.com>
Hello,
On Thu, Nov 26, 2026 at 10:29:32AM -0800, Tabby wrote:
> Hi,
>
> While using perf for userspace time-based profiling
> (speedscope/Firefox Profiler stack charts), I noticed an issue where
> `perf record -g` traces have incorrectly reconstructed stack traces
> when I run `perf script` and import the profiling trace into a
> time-axis viewer.
>
> For instance, when I run `perf record -e sched:sched_switch -e
> cycles/freq=99/ -g htop`, I get extra and missing stack frames when
> viewing the trace with `perf script` or `perf report`. Interestingly
> the perf.data file *does* have enough information to reconstruct
> proper call stacks, and `samply import` performs this but `perf
> report/script` does not.
>
> ## Debugging
>
> I initially suspected that perf failed to query all necessary debug
> info. Running `DEBUGINFOD_VERBOSE=1 perf script` shows that perf is
> querying debuginfod for every build ID found in `perf buildid-list`,
> but still outputs inaccurate frames from `-g/--call-graph fp` stacks.
> I do not know if perf can't find downloaded debug info, can't find
> on-disk binaries, or has an algorithmic deficiency.
>
> I took a look at the call stack captured by `sched:sched_switch`,
> where htop blocks on user input within wgetch.
>
> - `perf script` reports the blocking call stack as `_start >
> __libc_start_main > call_init > unknown > CommandLine_run >
> Platform_done > LibSensors_cleanup > ScreenManager_run > wgetch >
> [unknown] > __poll > syscall_cancel > internal_syscall_cancel.` This
> has both missing and incorrect stack frames; notably in the source
> code, `CommandLine_run()` directly calls `ScreenManager_run()` without
> the intermediate frames.
>
> - If I run `perf report` and view the call chain from `_start`, it
> reports the extraneous stack frames as `Platform_done (inlined)` and
> `LibSensors_cleanup (inlined)`. Expanding further, it reports that
> `wgetch` calls an unbranched chain of `0x7ffb69c4ada2 > __poll >
> syscall_cancel (inlined) > internal_syscall_cancel (inlined)`. Here it
> fails to resolve wgetch's function calls (whereas gdb and `layout src`
> reports that wgetch calls _nc_wgetch > check_mouse_activity >
> _nc_timed_wait > poll`.
>
> - If I run `samply import perf.data` on the same capture, and load the
> trace in Firefox Profiler, I see `start > _libc_start_main_impl >
> _libc_start_call_main > CommandLine_run > ScreenManager_run > wgetch >
> nc_wgetch > check_mouse_activity > _GI___poll > syscall_cancel >
> internal_syscall_cancel`. This shows that `samply import` and the
> Firefox Profiler it spawns knows to omit the false frames between
> CommandLine_run and ScreenManager_run, and properly resolves the
> frames between wgetch and ...poll... This call stack is also
> comparable to what gdb reports.
>
> - - Unfortunately samply is not a full replacement as-is, because it
> only includes the first `-e` (I've reported to Samply and not heard
> back yet) and doesn't symbolize in-kernel stack frames.
>
> Is there an explanation or possible solution for this issue?
IIUC you used frame-pointer based callchains then debug info won't help
the unwinding itself (it's already done in the kernel) but perf may add
inlined functions in the middle using the debug info.
I don't know what samply does but I guess it reads samples from the data
file. Then it's strange it sees different call stacks.
>
> Kernel: 7.3.5-arch1-1 (64-bit)
Can you please share your perf version as well? Is it the same when you
run the latest version (in perf-tools-next)?
Thanks,
Namhyung
>
> ## Prior art
>
> It does seem that perf unwinding is a subject in flux.
> https://lore.kernel.org/linux-perf-users/CAP-5=fWkUW787c4dGx9rccucqD67dfRgwBB_SoCxFnfZXtXP-w@mail.gmail.com/T/#t
> indicates that in-kernel DWARF unwinding is being proposed, but it
> presumably will not be ready for some months.
prev parent reply other threads:[~2026-12-05 8:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAL57YxZDQFH4cuv+dRbWwN5rv9K-45XbaznSQTQd9xBZLP9Dew@mail.gmail.com>
2026-11-26 18:29 ` Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`? Tabby
2026-12-05 8:20 ` 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=axPJa1vWTn0MDFPd@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nyanpasu256@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox