* Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`?
[not found] <CAL57YxZDQFH4cuv+dRbWwN5rv9K-45XbaznSQTQd9xBZLP9Dew@mail.gmail.com>
@ 2026-11-26 18:29 ` Tabby
2026-12-05 8:20 ` Namhyung Kim
0 siblings, 1 reply; 2+ messages in thread
From: Tabby @ 2026-11-26 18:29 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim
Cc: linux-perf-users, linux-kernel
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?
Kernel: 7.3.5-arch1-1 (64-bit)
## 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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`?
2026-11-26 18:29 ` Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`? Tabby
@ 2026-12-05 8:20 ` Namhyung Kim
0 siblings, 0 replies; 2+ messages in thread
From: Namhyung Kim @ 2026-12-05 8:20 UTC (permalink / raw)
To: Tabby
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
linux-perf-users, linux-kernel
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 8:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 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.