1SUMMARY = "Performance analysis tools for Linux" 2DESCRIPTION = "Performance counters for Linux are a new kernel-based \ 3subsystem that provide a framework for all things \ 4performance analysis. It covers hardware level \ 5(CPU/PMU, Performance Monitoring Unit) features \ 6and software features (software counters, tracepoints) \ 7as well." 8HOMEPAGE = "https://perf.wiki.kernel.org/index.php/Main_Page" 9 10LICENSE = "GPL-2.0-only" 11 12PR = "r9" 13 14PACKAGECONFIG ??= "scripting tui libunwind" 15PACKAGECONFIG[dwarf] = ",NO_DWARF=1" 16PACKAGECONFIG[scripting] = ",NO_LIBPERL=1 NO_LIBPYTHON=1,perl python3 python3-setuptools-native" 17# gui support was added with kernel 3.6.35 18# since 3.10 libnewt was replaced by slang 19# to cover a wide range of kernel we add both dependencies 20PACKAGECONFIG[tui] = ",NO_NEWT=1,libnewt slang" 21PACKAGECONFIG[libunwind] = ",NO_LIBUNWIND=1 NO_LIBDW_DWARF_UNWIND=1,libunwind" 22PACKAGECONFIG[libnuma] = ",NO_LIBNUMA=1" 23PACKAGECONFIG[systemtap] = ",NO_SDT=1,systemtap" 24PACKAGECONFIG[jvmti] = ",NO_JVMTI=1" 25# libaudit support would need scripting to be enabled 26PACKAGECONFIG[audit] = ",NO_LIBAUDIT=1,audit" 27PACKAGECONFIG[manpages] = ",,xmlto-native asciidoc-native" 28PACKAGECONFIG[cap] = ",,libcap" 29# Arm CoreSight 30PACKAGECONFIG[coresight] = "CORESIGHT=1,,opencsd" 31 32# libunwind is not yet ported for some architectures 33PACKAGECONFIG:remove:arc = "libunwind" 34PACKAGECONFIG:remove:riscv32 = "libunwind" 35 36DEPENDS = " \ 37 virtual/${MLPREFIX}libc \ 38 ${MLPREFIX}elfutils \ 39 ${MLPREFIX}binutils \ 40 bison-native flex-native xz \ 41" 42 43do_configure[depends] += "virtual/kernel:do_shared_workdir" 44 45PROVIDES = "virtual/perf" 46 47inherit linux-kernel-base kernel-arch manpages 48 49# needed for building the tools/perf Python bindings 50inherit ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'python3targetconfig', '', d)} 51inherit python3-dir 52export PYTHON_SITEPACKAGES_DIR 53 54#kernel 3.1+ supports WERROR to disable warnings as errors 55export WERROR = "0" 56 57do_populate_lic[depends] += "virtual/kernel:do_shared_workdir" 58 59# needed for building the tools/perf Perl binding 60include ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'perf-perl.inc', '', d)} 61 62inherit kernelsrc 63 64S = "${WORKDIR}/${BP}" 65SPDX_S = "${S}/tools/perf" 66 67# The LDFLAGS is required or some old kernels fails due missing 68# symbols and this is preferred than requiring patches to every old 69# supported kernel. 70LDFLAGS="-ldl -lutil" 71 72EXTRA_OEMAKE = '\ 73 V=1 \ 74 -C ${S}/tools/perf \ 75 O=${B} \ 76 CROSS_COMPILE=${TARGET_PREFIX} \ 77 ARCH=${ARCH} \ 78 CC="${CC}" \ 79 CCLD="${CC}" \ 80 LDSHARED="${CC} -shared" \ 81 AR="${AR}" \ 82 LD="${LD}" \ 83 EXTRA_CFLAGS="-ldw" \ 84 YFLAGS='-y --file-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}' \ 85 EXTRA_LDFLAGS="${PERF_EXTRA_LDFLAGS}" \ 86 perfexecdir=${libexecdir} \ 87 NO_GTK2=1 \ 88 ${PACKAGECONFIG_CONFARGS} \ 89 TMPDIR="${B}" \ 90 LIBUNWIND_DIR=${STAGING_EXECPREFIXDIR} \ 91' 92 93EXTRA_OEMAKE += "\ 94 'DESTDIR=${D}' \ 95 'prefix=${prefix}' \ 96 'bindir=${bindir}' \ 97 'sharedir=${datadir}' \ 98 'sysconfdir=${sysconfdir}' \ 99 'perfexecdir=${libexecdir}/perf-core' \ 100 'ETC_PERFCONFIG=${@os.path.relpath(sysconfdir, prefix)}' \ 101 'sharedir=${@os.path.relpath(datadir, prefix)}' \ 102 'mandir=${@os.path.relpath(mandir, prefix)}' \ 103 'infodir=${@os.path.relpath(infodir, prefix)}' \ 104 ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'PYTHON=python3 PYTHON_CONFIG=python3-config', '', d)} \ 105" 106 107# During do_configure, we might run a 'make clean'. That often breaks 108# when done in parallel, so disable parallelism for do_configure. Note 109# that it has to be done this way rather than by passing -j1, since 110# perf's build system by default ignores any -j argument, but does 111# honour a JOBS variable. 112EXTRA_OEMAKE:append:task-configure = " JOBS=1" 113 114PERF_SRC ?= "Makefile \ 115 tools/arch \ 116 tools/build \ 117 tools/include \ 118 tools/lib \ 119 tools/Makefile \ 120 tools/perf \ 121 tools/scripts \ 122 scripts/ \ 123 arch/${ARCH}/Makefile \ 124" 125 126PERF_EXTRA_LDFLAGS = "" 127 128# MIPS N32/N64 129PERF_EXTRA_LDFLAGS:mipsarchn32eb = "-m elf32btsmipn32" 130PERF_EXTRA_LDFLAGS:mipsarchn32el = "-m elf32ltsmipn32" 131PERF_EXTRA_LDFLAGS:mipsarchn64eb = "-m elf64btsmip" 132PERF_EXTRA_LDFLAGS:mipsarchn64el = "-m elf64ltsmip" 133 134do_compile() { 135 # Linux kernel build system is expected to do the right thing 136 unset CFLAGS 137 oe_runmake all 138} 139 140do_install() { 141 # Linux kernel build system is expected to do the right thing 142 unset CFLAGS 143 oe_runmake install 144 # we are checking for this make target to be compatible with older perf versions 145 if ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'true', 'false', d)} && grep -q install-python_ext ${S}/tools/perf/Makefile*; then 146 oe_runmake DESTDIR=${D} install-python_ext 147 if [ -e ${D}${libdir}/python*/site-packages/perf-*/SOURCES.txt ]; then 148 sed -i -e 's#${WORKDIR}##g' ${D}${libdir}/python*/site-packages/perf-*/SOURCES.txt 149 fi 150 fi 151} 152 153do_configure[prefuncs] += "copy_perf_source_from_kernel" 154python copy_perf_source_from_kernel() { 155 sources = (d.getVar("PERF_SRC") or "").split() 156 src_dir = d.getVar("STAGING_KERNEL_DIR") 157 dest_dir = d.getVar("S") 158 bb.utils.mkdirhier(dest_dir) 159 bb.utils.prunedir(dest_dir) 160 for s in sources: 161 src = oe.path.join(src_dir, s) 162 dest = oe.path.join(dest_dir, s) 163 if not os.path.exists(src): 164 bb.fatal("Path does not exist: %s. Maybe PERF_SRC does not match the kernel version." % src) 165 if os.path.isdir(src): 166 oe.path.copyhardlinktree(src, dest) 167 else: 168 src_path = os.path.dirname(s) 169 os.makedirs(os.path.join(dest_dir,src_path),exist_ok=True) 170 bb.utils.copyfile(src, dest) 171} 172 173do_configure:prepend () { 174 # If building a multlib based perf, the incorrect library path will be 175 # detected by perf, since it triggers via: ifeq ($(ARCH),x86_64). In a 32 bit 176 # build, with a 64 bit multilib, the arch won't match and the detection of a 177 # 64 bit build (and library) are not exected. To ensure that libraries are 178 # installed to the correct location, we can use the weak assignment in the 179 # config/Makefile. 180 # 181 # Also need to relocate .config-detected to $(OUTPUT)/config-detected 182 # for kernel sources that do not already do this 183 # as two builds (e.g. perf and lib32-perf from mutlilib can conflict 184 # with each other if its in the shared source directory 185 # 186 if [ -e "${S}/tools/perf/config/Makefile" ]; then 187 perfconfig="${S}/tools/perf/config/Makefile" 188 fi 189 if [ -e "${S}/tools/perf/Makefile.config" ]; then 190 perfconfig="${S}/tools/perf/Makefile.config" 191 fi 192 if [ -n "${perfconfig}" ]; then 193 # Match $(prefix)/$(lib) and $(prefix)/lib 194 sed -i -e 's,^libdir = \($(prefix)/.*lib\),libdir ?= \1,' \ 195 -e 's,^perfexecdir = \(.*\),perfexecdir ?= \1,' \ 196 -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \ 197 ${perfconfig} 198 fi 199 # The man pages installation is "$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)" 200 # in ${S}/tools/perf/Documentation/Makefile, if the mandir set to '?=', it 201 # will use the relative path 'share/man', in the way it will resulting in 202 # incorrect installation for man pages. 203 if [ -e "${S}/tools/perf/Documentation/Makefile" ]; then 204 sed -i 's,^mandir?=,mandir:=,' ${S}/tools/perf/Documentation/Makefile 205 fi 206 if [ -e "${S}/tools/perf/Makefile.perf" ]; then 207 sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \ 208 ${S}/tools/perf/Makefile.perf 209 sed -i -e "s,prefix='\$(DESTDIR_SQ)/usr'$,prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(PYTHON_SITEPACKAGES_DIR)' --root='\$(DESTDIR)',g" \ 210 ${S}/tools/perf/Makefile.perf 211 # backport https://github.com/torvalds/linux/commit/e4ffd066ff440a57097e9140fa9e16ceef905de8 212 sed -i -e 's,\($(Q)$(SHELL) .$(arch_errno_tbl).\) $(CC) $(arch_errno_hdr_dir),\1 $(firstword $(CC)) $(arch_errno_hdr_dir),g' \ 213 ${S}/tools/perf/Makefile.perf 214 fi 215 sed -i -e "s,--root='/\$(DESTDIR_SQ)',--prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \ 216 ${S}/tools/perf/Makefile* 217 218 if [ -e "${S}/tools/build/Makefile.build" ]; then 219 sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \ 220 ${S}/tools/build/Makefile.build 221 fi 222 223 # start reproducibility substitutions 224 if [ -e "${S}/tools/perf/Makefile.config" ]; then 225 # The following line in the Makefle: 226 # override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON_AUTO)) 227 # "PYTHON" / "PYTHON_AUTO" have the full path as part of the variable. We've 228 # ensure that the environment is setup and we do not need the full path to be 229 # captured, since the symbol gets built into the executable, making it not 230 # reproducible. 231 sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(PYTHON_AUTO)),$(notdir $(call get-executable-or-default\,PYTHON\,$(PYTHON_AUTO))),g' \ 232 ${S}/tools/perf/Makefile.config 233 # The same line is in older releases, but looking explicitly for Python 2 234 sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(PYTHON2)),$(notdir $(call get-executable-or-default\,PYTHON\,$(PYTHON2))),g' \ 235 ${S}/tools/perf/Makefile.config 236 237 # likewise with this substitution. Kernels with commit 18f2967418d031a39 238 # [perf tools: Use Python devtools for version autodetection rather than runtime] 239 # need this substitution for reproducibility. 240 sed -i -e 's,$(call get-executable-or-default\,PYTHON\,$(subst -config\,\,$(PYTHON_AUTO))),$(notdir $(call get-executable-or-default\,PYTHON\,$(subst -config\,\,$(PYTHON_AUTO)))),g' \ 241 ${S}/tools/perf/Makefile.config 242 243 # The following line: 244 # srcdir_SQ = $(patsubst %tools/perf,tools/perf,$(subst ','\'',$(srcdir))), 245 # Captures the full src path of perf, which of course makes it not 246 # reproducible. We really only need the relative location 'tools/perf', so we 247 # change the Makefile line to remove everything before 'tools/perf' 248 sed -i -e "s%srcdir_SQ = \$(subst ','\\\'',\$(srcdir))%srcdir_SQ = \$(patsubst \%tools/perf,tools/perf,\$(subst ','\\\'',\$(srcdir)))%g" \ 249 ${S}/tools/perf/Makefile.config 250 # Avoid hardcoded path to python-native 251 sed -i -e 's#\(PYTHON_WORD := \)$(call shell-wordify,$(PYTHON))#\1 python3#g' \ 252 ${S}/tools/perf/Makefile.config 253 fi 254 if [ -e "${S}/tools/perf/tests/Build" ]; then 255 # OUTPUT is the full path, we have python on the path so we remove it from the 256 # definition. This is captured in the perf binary, so breaks reproducibility 257 sed -i -e 's,PYTHONPATH="BUILD_STR($(OUTPUT)python)",PYTHONPATH="BUILD_STR(python)",g' \ 258 ${S}/tools/perf/tests/Build 259 fi 260 if [ -e "${S}/tools/perf/util/Build" ]; then 261 # To avoid bison generating #ifdefs that have captured paths, we make sure 262 # all the calls have YFLAGS, which contains prefix mapping information. 263 sed -i -e 's,$(BISON),$(BISON) $(YFLAGS),g' ${S}/tools/perf/util/Build 264 fi 265 if [ -e "${S}/scripts/Makefile.host" ]; then 266 # To avoid yacc (bison) generating #ifdefs that have captured paths, we make sure 267 # all the calls have YFLAGS, which contains prefix mapping information. 268 sed -i -e 's,$(YACC),$(YACC) $(YFLAGS),g' ${S}/scripts/Makefile.host 269 fi 270 if [ -e "${S}/tools/perf/pmu-events/Build" ]; then 271 target='$(OUTPUT)pmu-events/pmu-events.c $(V)' 272 replacement1='$(OUTPUT)pmu-events/pmu-events.c $(V)\n' 273 replacement2='\t$(srctree)/sort-pmuevents.py $(OUTPUT)pmu-events/pmu-events.c $(OUTPUT)pmu-events/pmu-events.c.new\n' 274 replacement3='\tcp $(OUTPUT)pmu-events/pmu-events.c.new $(OUTPUT)pmu-events/pmu-events.c' 275 sed -i -e "s,$target,$replacement1$replacement2$replacement3,g" \ 276 "${S}/tools/perf/pmu-events/Build" 277 fi 278 # end reproducibility substitutions 279 280 # We need to ensure the --sysroot option in CC is preserved 281 if [ -e "${S}/tools/perf/Makefile.perf" ]; then 282 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/perf/Makefile.perf 283 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/perf/Makefile.perf 284 sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/perf/Makefile.perf 285 fi 286 if [ -e "${S}/tools/lib/api/Makefile" ]; then 287 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/api/Makefile 288 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/api/Makefile 289 sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/lib/api/Makefile 290 fi 291 if [ -e "${S}/tools/lib/subcmd/Makefile" ]; then 292 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/subcmd/Makefile 293 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/subcmd/Makefile 294 fi 295 if [ -e "${S}/tools/perf/config/feature-checks/Makefile" ]; then 296 sed -i 's,CC := $(CROSS_COMPILE)gcc -MD,CC += -MD,' ${S}/tools/perf/config/feature-checks/Makefile 297 fi 298 if [ -e "${S}/tools/build/Makefile.feature" ]; then 299 sed -i 's,CFLAGS=,CC="\$(CC)" CFLAGS=,' ${S}/tools/build/Makefile.feature 300 fi 301 302 # 3.17-rc1+ has a include issue for arm/powerpc. Temporarily sed in the appropriate include 303 if [ -e "${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c" ]; then 304 sed -i 's,#include "util/callchain.h",#include "util/callchain.h"\n#include "util/debug.h",' ${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c 305 fi 306 if [ -e "${S}/tools/perf/arch/arm/util/unwind-libunwind.c" ] && [ -e "${S}/tools/perf/arch/arm/tests/dwarf-unwind.c" ]; then 307 sed -i 's,#include "tests/tests.h",#include "tests/tests.h"\n#include "util/debug.h",' ${S}/tools/perf/arch/arm/tests/dwarf-unwind.c 308 sed -i 's,#include "perf_regs.h",#include "perf_regs.h"\n#include "util/debug.h",' ${S}/tools/perf/arch/arm/util/unwind-libunwind.c 309 fi 310 311 # use /usr/bin/env instead of version specific python 312 for s in `find ${S}/tools/perf/ -name '*.py'` `find ${S}/scripts/ -name 'bpf_helpers_doc.py'`; do 313 sed -i -e "s,#!.*python.*,#!${USRBINPATH}/env python3," ${s} 314 done 315 316 # unistd.h can be out of sync between libc-headers and the captured version in the perf source 317 # so we copy it from the sysroot unistd.h to the perf unistd.h 318 install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/tools/include/uapi/asm-generic/unistd.h 319 install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/include/uapi/asm-generic/unistd.h 320 321 # the fetcher is inhibited by the 'inherit kernelsrc', so we do a quick check and 322 # copy for a helper script we need 323 for p in $(echo ${FILESPATH} | tr ':' '\n'); do 324 if [ -e $p/sort-pmuevents.py ]; then 325 cp $p/sort-pmuevents.py ${S} 326 fi 327 done 328} 329 330python do_package:prepend() { 331 d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0]) 332} 333 334PACKAGE_ARCH = "${MACHINE_ARCH}" 335 336 337PACKAGES =+ "${PN}-archive ${PN}-tests ${PN}-perl ${PN}-python" 338 339RDEPENDS:${PN} += "elfutils bash" 340RDEPENDS:${PN}-archive =+ "bash" 341RDEPENDS:${PN}-python =+ "bash python3 python3-modules ${@bb.utils.contains('PACKAGECONFIG', 'audit', 'audit-python', '', d)}" 342RDEPENDS:${PN}-perl =+ "bash perl perl-modules" 343RDEPENDS:${PN}-tests =+ "python3 bash" 344 345RSUGGESTS_SCRIPTING = "${@bb.utils.contains('PACKAGECONFIG', 'scripting', '${PN}-perl ${PN}-python', '',d)}" 346RSUGGESTS:${PN} += "${PN}-archive ${PN}-tests ${RSUGGESTS_SCRIPTING}" 347 348FILES_SOLIBSDEV = "" 349FILES:${PN} += "${libexecdir}/perf-core ${exec_prefix}/libexec/perf-core ${libdir}/traceevent ${libdir}/libperf-jvmti.so" 350FILES:${PN}-archive = "${libdir}/perf/perf-core/perf-archive" 351FILES:${PN}-tests = "${libdir}/perf/perf-core/tests ${libexecdir}/perf-core/tests" 352FILES:${PN}-python = " \ 353 ${PYTHON_SITEPACKAGES_DIR} \ 354 ${libexecdir}/perf-core/scripts/python \ 355 " 356FILES:${PN}-perl = "${libexecdir}/perf-core/scripts/perl" 357 358 359INHIBIT_PACKAGE_DEBUG_SPLIT="1" 360DEBUG_OPTIMIZATION:append = " -Wno-error=maybe-uninitialized" 361