84.10. perf-7.2.11
The kernel's own profiler: sampling, counters, tracepoints and BPF
| Version | 7.2.11, release 1 |
| Shelf | devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities |
| Phase | 41_system (System), 382 of 1047 in build order |
| Licence | GPL-2.0-only |
| Homepage | https://perf.wiki.kernel.org/ |
| Build time | 1.9 SBU |
| Installed size | 25.2 MiB in 336 files |
| Recipe | ports/core/devtools/perf/kpkgbuild |
About
perf is the kernel’s own profiler: it samples where the processors spend their time, counts hardware and software events, records tracepoints and runs BPF programs that summarise in the kernel, then reports what it found (perf top, perf record and perf report, perf stat, perf trace). It is not a project of its own but tools/perf inside the kernel source, so the port’s tarball is the linux port’s tarball under another name, and the two carry the same version and hash. testing/preflight.sh fails the tree when they disagree, because a perf built from another kernel’s source does not fail: it reports unknown record types and misses the newer tracepoints.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/devtools.txt:
The kernel profiler. Built from the same tarball as the
linuxport and pinned to the same version: a perf built from a different kernel's source does not fail, it silently reports unknown record types.
Sources
perf-7.2.11.tar.xz(153.0 MiB)
sha256fd0fc479f983a8c05313f13e9c36330fe6651cf725396748c40d5cd93fa1e6a4
upstream: https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-7.2.11.tar.xz
archive copy: sources-1/boot--linux-7.2.11.tar.xz
Dependencies
Depends on: elfutils, zlib, slang, libtraceevent, libbpf, capstone, numactl, zstd, xz, openssl, python3, clang, llvm, flex, bison, asciidoctor, perl.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
perf-docs.patch— Shortens two AsciiDoc heading underlines to the length of the heading above them: theperf-check(1)title ofperf-check.txtand theOPTIONS for 'perf kwork top'section heading ofperf-kwork.txt.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install perf'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/devtools/perf.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/devtools/perf
echo 'fd0fc479f983a8c05313f13e9c36330fe6651cf725396748c40d5cd93fa1e6a4 perf-7.2.11.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/perf
SRC=$SRC_ROOT/perf-7.2.11
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf perf-7.2.11.tar.xz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/perf-docs.patch"
export LDFLAGS="$LDFLAGS -Wl,--strip-debug"
perf_make=(
make -C tools/perf
prefix=/usr
WERROR=0
EXTRA_CFLAGS="$CFLAGS $LDFLAGS"
LIBBPF_DYNAMIC=1
BUILD_BPF_SKEL=1
NO_LIBPFM4=1
NO_BABELTRACE2=1
NO_LIBDEBUGINFOD=1
NO_JVMTI=1
NO_SDT=1
NO_LIBLLVM=1
NO_PERF_READ_VDSO32=1
NO_PERF_READ_VDSOX32=1
NO_BACKTRACE=1
NO_RUST=1
LIBPERL=1
PYTHON_SETUPTOOLS_INSTALLED=no
)
"${perf_make[@]}"
"${perf_make[@]}" DESTDIR="$PKG" install-bin
make -C tools/perf/Documentation prefix=/usr DESTDIR="$PKG" \
USE_ASCIIDOCTOR=1 PERF_VERSION="$version" \
KBUILD_BUILD_TIMESTAMP="@$SOURCE_DATE_EPOCH" \
ASCIIDOC_EXTRA="-a compat-mode -I. -rasciidoctor-extensions -a mansource=perf -a manmanual=perf\\ Manual" \
install-man
rm -f "$PKG"/usr/libexec/perf-core/tests/pe-file.exe*
install -Dm644 "$PKG"/etc/bash_completion.d/perf "$PKG"/usr/share/bash-completion/completions/perf
rm -r "$PKG"/etc/bash_completion.d
rmdir --ignore-fail-on-non-empty "$PKG"/etc
The switches, and why each is set:
LDFLAGS— The tree’s link flags with-Wl,--strip-debugadded. Several of the libraries perf builds and links in,tools/lib/api,tools/lib/subcmd,tools/lib/symbolandtools/lib/perf, add their own-gor-ggdb3after the tree’s flags, and the linker drops that debug information from the programs it writes.prefix=/usr— perf compiles the prefix in: it finds its helper programs, scripts and tests under$prefix/libexec/perf-coreat run time. It also derives every install path from it, so it is on both the build and the install command line. Unset, the build takes$HOMEand the install, which setsDESTDIR, takes the empty string, so the package would stage into$PKG/binaround a binary that looks for its helpers in the build user’s home.WERROR=0— perf compiles with-Werrorunless this is set to 0. Over a kernel tree with the tree’s GCC and musl’s headers, any new warning would stop the build.EXTRA_CFLAGS— perf’sMakefile.configsetsCFLAGSfromEXTRA_CFLAGSinstead of adding to the environment’s, so this is where the tree’s$CFLAGSgo.$LDFLAGSgo there as well, because the rule that links thedlfiltersshared objects readsEXTRA_CFLAGSand notLDFLAGS; without them those objects would be linked without-z now. See The release flags.LIBBPF_DYNAMIC=1— Links the sharedlibbpffrom the libbpf port, instead of building the copy intools/lib/bpfand linking it statically.BUILD_BPF_SKEL=1— Builds the BPF skeletons behindperf lock contention,perf record --off-cpu,perf stat --bpf-countersand others: BPF programs compiled with clang and wrapped by a bpftool perf builds for itself. The default is on, butMakefile.configturns it off with only a warning when libelf, zlib, libbpf, OpenSSL or clang is missing; the ports that provide them are all independs.NO_LIBPFM4=1— Leaves out libpfm4’s named raw hardware events. The tree has no libpfm port.NO_BABELTRACE2=1— Leaves outperf data convert --to-ctf, the export to the CTF trace format, which needs babeltrace2’s CTF writer. The tree has no babeltrace2 port.NO_LIBDEBUGINFOD=1— Leaves out fetching debug information from a debuginfod server. The elfutils port is configured with--disable-libdebuginfod, so there is nolibdebuginfodto link.NO_JVMTI=1— Does not build the JVMTI agent that lets perf name the methods of Java code the JIT compiled. It compiles against a JDK’s headers, and openjdk is not one of this port’s dependencies.NO_SDT=1— perf defines no SDT markers (static probes) in its own code; this needssys/sdt.hfrom systemtap, which the tree does not carry. As upstream notes, perf still finds and uses the SDT markers in other programs.NO_LIBLLVM=1— Without it, perf finds LLVM and links every libraryllvm-config --libs allnames, for source-line lookup and forperf annotate’s disassembler. This tree’s LLVM is one shared library per component, so every one of them would load at each perf start, for work libdw (source lines) and capstone (disassembly) already do.NO_PERF_READ_VDSO32=1,NO_PERF_READ_VDSOX32=1— Do not build the two helpers that read the 32-bit and x32 compatibility vDSOs. Each is compiled with-m32or-mx32, which needs a C library for that ABI, and the tree has only the 64-bit one.NO_BACKTRACE=1— Leaves out perf printing its own stack when it crashes, which usesbacktrace()fromexecinfo.h. musl has noexecinfo.h.NO_RUST=1— Upstream uses Rust only for test workloads ofperf test; the switch skips the probe for a Rust compiler.LIBPERL=1— Off by default upstream. It builds the Perl engine behindperf script -s foo.pl, which linkslibperl.so; the perl port is configured with-Duseshrplibso that library exists. WithLIBPERLset, a perl without it stops the build.PYTHON_SETUPTOOLS_INSTALLED=no— perf builds its Python extension module,python/perf.so, when Python can import setuptools, and itsinstallnever installs the module. Answering the probe keeps the build the same whether or not some other port has put setuptools in the chroot. The embedded Python engine ofperf scriptdoes not depend on it.install-bin— perf’sinstalltarget isinstall-binfollowed bytry-install-man, which would render the manuals the AsciiDoc and DocBook way. The recipe installs the programs withinstall-binfrom the same argument list as the build, so make does not repeat every feature probe with different answers and relink the tool, and renders the manuals on its own line.USE_ASCIIDOCTOR=1— Renders each manual straight to a man page with asciidoctor, instead of going through DocBook, xmlto and xsltproc. On that route theperf-c2cpage nests the stylesheet’sstring.substtemplate past libxslt’s limit of 3000, which xmlto has no way to raise.ASCIIDOC_EXTRA— The Documentation makefile adds asciidoc’s--unsafe -f asciidoc.confto this variable on the Asciidoctor route too, and asciidoctor refuses them, so the recipe gives the whole value itself: the options upstream’s Asciidoctor route sets (-a compat-mode,-rasciidoctor-extensions,mansourceandmanmanual).tools/perf/Documentationis run directly becauseMakefile.perfpasses the variable on unquoted and would split the value at its spaces.PERF_VERSION,KBUILD_BUILD_TIMESTAMP— Run directly, the Documentation makefile does not inherit the versionMakefile.perfwould pass it, so the recipe names it. The timestamp,SOURCE_DATE_EPOCH, gives the date printed in every page, which the makefile otherwise takes fromgit log.install-man— Unliketry-install-man, whichinstallruns, it stops when asciidoctor is missing instead of warning and installing no manuals.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/perf, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf perf-7.2.11-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/perf, and runs the triggers its paths call for.
Contents
Installed programs: perf, trace.
Installed directories: /usr/include/perf, /usr/libexec/perf-core, /usr/share/doc/perf-tip, /usr/share/licenses/perf.
Short descriptions
perf |
Performance analysis tools for Linux |
Notes
- Some features depend only on
depends. perf has no switch that demands slang, capstone, numactl, Python, zlib, xz or zstd, only aNO_…that refuses each one, and it builds without any it does not find. Their place independsis what keeps theperf reportandperf toptext interface, the capstone disassembler,perf bench numa mem, Python inperf script, and compressed kernel modules andperf record -z. - No libunwind.
LIBUNWINDis opt-in upstream and is not set. perf unwinds DWARF call graphs with libdw from elfutils; built with libunwind as well, it only gains a second unwinder that it tries when libdw returns nothing. - The Windows test files are removed.
install-testscopiespe-file.exeand its debug file in beside the shell tests, for aperf testcase that reads build IDs from PE binaries.build.shdeletes them. - The bash completion moves. perf installs it as
/etc/bash_completion.d/perf; the recipe moves it to/usr/share/bash-completion/completions/perf, where bash-completion loads it on demand, and removes the empty/etc.