perf.bb 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. SUMMARY = "Performance analysis tools for Linux"
  2. DESCRIPTION = "Performance counters for Linux are a new kernel-based \
  3. subsystem that provide a framework for all things \
  4. performance analysis. It covers hardware level \
  5. (CPU/PMU, Performance Monitoring Unit) features \
  6. and software features (software counters, tracepoints) \
  7. as well."
  8. HOMEPAGE = "https://perf.wiki.kernel.org/index.php/Main_Page"
  9. LICENSE = "GPLv2"
  10. PR = "r9"
  11. PACKAGECONFIG ??= "scripting tui libunwind"
  12. PACKAGECONFIG[dwarf] = ",NO_DWARF=1"
  13. PACKAGECONFIG[scripting] = ",NO_LIBPERL=1 NO_LIBPYTHON=1,perl python3"
  14. # gui support was added with kernel 3.6.35
  15. # since 3.10 libnewt was replaced by slang
  16. # to cover a wide range of kernel we add both dependencies
  17. PACKAGECONFIG[tui] = ",NO_NEWT=1,libnewt slang"
  18. PACKAGECONFIG[libunwind] = ",NO_LIBUNWIND=1 NO_LIBDW_DWARF_UNWIND=1,libunwind"
  19. PACKAGECONFIG[libnuma] = ",NO_LIBNUMA=1"
  20. PACKAGECONFIG[systemtap] = ",NO_SDT=1,systemtap"
  21. PACKAGECONFIG[jvmti] = ",NO_JVMTI=1"
  22. # libaudit support would need scripting to be enabled
  23. PACKAGECONFIG[audit] = ",NO_LIBAUDIT=1,audit"
  24. PACKAGECONFIG[manpages] = ",,xmlto-native asciidoc-native"
  25. PACKAGECONFIG[cap] = ",,libcap"
  26. # Arm CoreSight
  27. PACKAGECONFIG[coresight] = "CORESIGHT=1,,opencsd"
  28. # libunwind is not yet ported for some architectures
  29. PACKAGECONFIG_remove_arc = "libunwind"
  30. PACKAGECONFIG_remove_riscv64 = "libunwind"
  31. DEPENDS = " \
  32. virtual/${MLPREFIX}libc \
  33. ${MLPREFIX}elfutils \
  34. ${MLPREFIX}binutils \
  35. bison-native flex-native xz \
  36. "
  37. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  38. PROVIDES = "virtual/perf"
  39. inherit linux-kernel-base kernel-arch manpages
  40. # needed for building the tools/perf Python bindings
  41. inherit ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'python3native', '', d)}
  42. inherit python3-dir
  43. export PYTHON_SITEPACKAGES_DIR
  44. #kernel 3.1+ supports WERROR to disable warnings as errors
  45. export WERROR = "0"
  46. do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
  47. # needed for building the tools/perf Perl binding
  48. include ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'perf-perl.inc', '', d)}
  49. inherit kernelsrc
  50. S = "${WORKDIR}/${BP}"
  51. SPDX_S = "${S}/tools/perf"
  52. # The LDFLAGS is required or some old kernels fails due missing
  53. # symbols and this is preferred than requiring patches to every old
  54. # supported kernel.
  55. LDFLAGS="-ldl -lutil"
  56. EXTRA_OEMAKE = '\
  57. V=1 \
  58. -C ${S}/tools/perf \
  59. O=${B} \
  60. CROSS_COMPILE=${TARGET_PREFIX} \
  61. ARCH=${ARCH} \
  62. CC="${CC}" \
  63. CCLD="${CC}" \
  64. LDSHARED="${CC} -shared" \
  65. AR="${AR}" \
  66. LD="${LD}" \
  67. EXTRA_CFLAGS="-ldw" \
  68. EXTRA_LDFLAGS="${PERF_EXTRA_LDFLAGS}" \
  69. perfexecdir=${libexecdir} \
  70. NO_GTK2=1 \
  71. ${PACKAGECONFIG_CONFARGS} \
  72. TMPDIR="${B}" \
  73. LIBUNWIND_DIR=${STAGING_EXECPREFIXDIR} \
  74. '
  75. EXTRA_OEMAKE += "\
  76. 'DESTDIR=${D}' \
  77. 'prefix=${prefix}' \
  78. 'bindir=${bindir}' \
  79. 'sharedir=${datadir}' \
  80. 'sysconfdir=${sysconfdir}' \
  81. 'perfexecdir=${libexecdir}/perf-core' \
  82. 'ETC_PERFCONFIG=${@os.path.relpath(sysconfdir, prefix)}' \
  83. 'sharedir=${@os.path.relpath(datadir, prefix)}' \
  84. 'mandir=${@os.path.relpath(mandir, prefix)}' \
  85. 'infodir=${@os.path.relpath(infodir, prefix)}' \
  86. ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'PYTHON=python3 PYTHON_CONFIG=python3-config', '', d)} \
  87. "
  88. # During do_configure, we might run a 'make clean'. That often breaks
  89. # when done in parallel, so disable parallelism for do_configure. Note
  90. # that it has to be done this way rather than by passing -j1, since
  91. # perf's build system by default ignores any -j argument, but does
  92. # honour a JOBS variable.
  93. EXTRA_OEMAKE_append_task-configure = " JOBS=1"
  94. PERF_SRC ?= "Makefile \
  95. tools/arch \
  96. tools/build \
  97. tools/include \
  98. tools/lib \
  99. tools/Makefile \
  100. tools/perf \
  101. tools/scripts \
  102. scripts/ \
  103. arch/${ARCH}/Makefile \
  104. "
  105. PERF_EXTRA_LDFLAGS = ""
  106. # MIPS N32
  107. PERF_EXTRA_LDFLAGS_mipsarchn32eb = "-m elf32btsmipn32"
  108. PERF_EXTRA_LDFLAGS_mipsarchn32el = "-m elf32ltsmipn32"
  109. do_compile() {
  110. # Linux kernel build system is expected to do the right thing
  111. unset CFLAGS
  112. oe_runmake all
  113. }
  114. do_install() {
  115. # Linux kernel build system is expected to do the right thing
  116. unset CFLAGS
  117. oe_runmake install
  118. # we are checking for this make target to be compatible with older perf versions
  119. if ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'true', 'false', d)} && grep -q install-python_ext ${S}/tools/perf/Makefile*; then
  120. oe_runmake DESTDIR=${D} install-python_ext
  121. fi
  122. }
  123. do_configure[prefuncs] += "copy_perf_source_from_kernel"
  124. python copy_perf_source_from_kernel() {
  125. sources = (d.getVar("PERF_SRC") or "").split()
  126. src_dir = d.getVar("STAGING_KERNEL_DIR")
  127. dest_dir = d.getVar("S")
  128. bb.utils.mkdirhier(dest_dir)
  129. bb.utils.prunedir(dest_dir)
  130. for s in sources:
  131. src = oe.path.join(src_dir, s)
  132. dest = oe.path.join(dest_dir, s)
  133. if not os.path.exists(src):
  134. bb.fatal("Path does not exist: %s. Maybe PERF_SRC does not match the kernel version." % src)
  135. if os.path.isdir(src):
  136. oe.path.copyhardlinktree(src, dest)
  137. else:
  138. src_path = os.path.dirname(s)
  139. os.makedirs(os.path.join(dest_dir,src_path),exist_ok=True)
  140. bb.utils.copyfile(src, dest)
  141. }
  142. do_configure_prepend () {
  143. # If building a multlib based perf, the incorrect library path will be
  144. # detected by perf, since it triggers via: ifeq ($(ARCH),x86_64). In a 32 bit
  145. # build, with a 64 bit multilib, the arch won't match and the detection of a
  146. # 64 bit build (and library) are not exected. To ensure that libraries are
  147. # installed to the correct location, we can use the weak assignment in the
  148. # config/Makefile.
  149. #
  150. # Also need to relocate .config-detected to $(OUTPUT)/config-detected
  151. # for kernel sources that do not already do this
  152. # as two builds (e.g. perf and lib32-perf from mutlilib can conflict
  153. # with each other if its in the shared source directory
  154. #
  155. if [ -e "${S}/tools/perf/config/Makefile" ]; then
  156. perfconfig="${S}/tools/perf/config/Makefile"
  157. fi
  158. if [ -e "${S}/tools/perf/Makefile.config" ]; then
  159. perfconfig="${S}/tools/perf/Makefile.config"
  160. fi
  161. if [ -n "${perfconfig}" ]; then
  162. # Match $(prefix)/$(lib) and $(prefix)/lib
  163. sed -i -e 's,^libdir = \($(prefix)/.*lib\),libdir ?= \1,' \
  164. -e 's,^perfexecdir = \(.*\),perfexecdir ?= \1,' \
  165. -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
  166. ${perfconfig}
  167. fi
  168. # The man pages installation is "$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)"
  169. # in ${S}/tools/perf/Documentation/Makefile, if the mandir set to '?=', it
  170. # will use the relative path 'share/man', in the way it will resulting in
  171. # incorrect installation for man pages.
  172. if [ -e "${S}/tools/perf/Documentation/Makefile" ]; then
  173. sed -i 's,^mandir?=,mandir:=,' ${S}/tools/perf/Documentation/Makefile
  174. fi
  175. if [ -e "${S}/tools/perf/Makefile.perf" ]; then
  176. sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
  177. ${S}/tools/perf/Makefile.perf
  178. sed -i -e "s,prefix='\$(DESTDIR_SQ)/usr'$,prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
  179. ${S}/tools/perf/Makefile.perf
  180. # backport https://github.com/torvalds/linux/commit/e4ffd066ff440a57097e9140fa9e16ceef905de8
  181. sed -i -e 's,\($(Q)$(SHELL) .$(arch_errno_tbl).\) $(CC) $(arch_errno_hdr_dir),\1 $(firstword $(CC)) $(arch_errno_hdr_dir),g' \
  182. ${S}/tools/perf/Makefile.perf
  183. fi
  184. sed -i -e "s,--root='/\$(DESTDIR_SQ)',--prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
  185. ${S}/tools/perf/Makefile*
  186. if [ -e "${S}/tools/build/Makefile.build" ]; then
  187. sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
  188. ${S}/tools/build/Makefile.build
  189. fi
  190. # We need to ensure the --sysroot option in CC is preserved
  191. if [ -e "${S}/tools/perf/Makefile.perf" ]; then
  192. sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/perf/Makefile.perf
  193. sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/perf/Makefile.perf
  194. sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/perf/Makefile.perf
  195. fi
  196. if [ -e "${S}/tools/lib/api/Makefile" ]; then
  197. sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/api/Makefile
  198. sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/api/Makefile
  199. sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/lib/api/Makefile
  200. fi
  201. if [ -e "${S}/tools/lib/subcmd/Makefile" ]; then
  202. sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/subcmd/Makefile
  203. sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/subcmd/Makefile
  204. fi
  205. if [ -e "${S}/tools/perf/config/feature-checks/Makefile" ]; then
  206. sed -i 's,CC := $(CROSS_COMPILE)gcc -MD,CC += -MD,' ${S}/tools/perf/config/feature-checks/Makefile
  207. fi
  208. if [ -e "${S}/tools/build/Makefile.feature" ]; then
  209. sed -i 's,CFLAGS=,CC="\$(CC)" CFLAGS=,' ${S}/tools/build/Makefile.feature
  210. fi
  211. # 3.17-rc1+ has a include issue for arm/powerpc. Temporarily sed in the appropriate include
  212. if [ -e "${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c" ]; then
  213. 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
  214. fi
  215. if [ -e "${S}/tools/perf/arch/arm/util/unwind-libunwind.c" ] && [ -e "${S}/tools/perf/arch/arm/tests/dwarf-unwind.c" ]; then
  216. 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
  217. 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
  218. fi
  219. # use /usr/bin/env instead of version specific python
  220. for s in `find ${S}/tools/perf/ -name '*.py'` `find ${S}/scripts/ -name 'bpf_helpers_doc.py'`; do
  221. sed -i -e "s,#!.*python.*,#!${USRBINPATH}/env python3," ${s}
  222. done
  223. # unistd.h can be out of sync between libc-headers and the captured version in the perf source
  224. # so we copy it from the sysroot unistd.h to the perf unistd.h
  225. install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/tools/include/uapi/asm-generic/unistd.h
  226. install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/include/uapi/asm-generic/unistd.h
  227. }
  228. python do_package_prepend() {
  229. d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
  230. }
  231. PACKAGE_ARCH = "${MACHINE_ARCH}"
  232. PACKAGES =+ "${PN}-archive ${PN}-tests ${PN}-perl ${PN}-python"
  233. RDEPENDS_${PN} += "elfutils bash"
  234. RDEPENDS_${PN}-archive =+ "bash"
  235. RDEPENDS_${PN}-python =+ "bash python3 python3-modules ${@bb.utils.contains('PACKAGECONFIG', 'audit', 'audit-python3', '', d)}"
  236. RDEPENDS_${PN}-perl =+ "bash perl perl-modules"
  237. RDEPENDS_${PN}-tests =+ "python3"
  238. RSUGGESTS_SCRIPTING = "${@bb.utils.contains('PACKAGECONFIG', 'scripting', '${PN}-perl ${PN}-python', '',d)}"
  239. RSUGGESTS_${PN} += "${PN}-archive ${PN}-tests ${RSUGGESTS_SCRIPTING}"
  240. FILES_SOLIBSDEV = ""
  241. FILES_${PN} += "${libexecdir}/perf-core ${exec_prefix}/libexec/perf-core ${libdir}/traceevent ${libdir}/libperf-jvmti.so"
  242. FILES_${PN}-archive = "${libdir}/perf/perf-core/perf-archive"
  243. FILES_${PN}-tests = "${libdir}/perf/perf-core/tests ${libexecdir}/perf-core/tests"
  244. FILES_${PN}-python = " \
  245. ${PYTHON_SITEPACKAGES_DIR} \
  246. ${libexecdir}/perf-core/scripts/python \
  247. "
  248. FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl"
  249. INHIBIT_PACKAGE_DEBUG_SPLIT="1"
  250. DEBUG_OPTIMIZATION_append = " -Wno-error=maybe-uninitialized"