OK, looks like there are several parts to this:
I'm on x86_64, where most distros build with
-fomit-frame-pointer
by default, andperf
can't follow the stack without frame pointers;.... unless it's a newer version built with
libunwind
support, in which case it supportsperf record -g dwarf
.
See:
- the patch adding libunwind support to Perf
- Debian bug 725075.
- linux perf: how to interpret and find hotspots
I'm on Fedora 18, but the same issue applies. So if you're profiling code you're working on (as is likely on Stack Overflow), rebuild with -fno-omit-frame-pointer
and -ggdb
.
I landed up rebuilding perf
because I wanted to be able to compare to the stock RPMs:
sudo yum build-dep perf
sudo yum install yum-utils rpmdevtools libunwind-devel
yumdownloader --source perf
or download the appropriatekernel-.....src.rpm
srpmrpmdev-setuptree
rpm -Uvh kernel-*.src.rpm
cd $HOME/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec
At this point you can just build a new perf
if you want:
cd $HOME/rpmbuild/BUILD/kernel-*/linux-*/tools/perf
make
... which I did and tested that the updated perf
does in fact capture a useful stack if built with libunwind available.
You can also build a new rpm:
edit kernel.spec, uncomment the line
%define buildid ...
, change buildid to something like.perfunwind
. Note it's%define
not% define
.In the same spec file, find:
%global perf_make \ make %{?_smp_mflags} -C tools/perf -s V=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_LIBNUMA=1 NO_STRLCPY=1 prefix=%{_prefix}
and delete
NO_LIBUNWIND=1
rpmbuild -bb --without up --without mp --without pae --without debug --without doc --without headers --without debuginfo --without bootwrapper --without with_vdso_install --with perf kernel.spec
to produce newperf
RPMs without building the whole kernel. Or if you want, omit the--without
for the kernel flavour you want, in which case you'll also want to build headers, debuginfo, etc.sudo rpm -Uvh $HOME/rpmbuild/RPMS/x86_64/perf-*.fc19.x86_64.rpm
See the fedora project guide on building a custom kernel.
I've reported the issue to Fedora; they shouldn't be using NO_LIBUNWIND=1
. See bug 1025603.
Once you have a rebuilt perf
you can use perf record -g dwarf
to get full stacks.