perf.bb 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 python"
  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. # libunwind is not yet ported for some architectures
  26. PACKAGECONFIG_remove_arc = "libunwind"
  27. PACKAGECONFIG_remove_riscv64 = "libunwind"
  28. DEPENDS = " \
  29. virtual/${MLPREFIX}libc \
  30. ${MLPREFIX}elfutils \
  31. ${MLPREFIX}binutils \
  32. bison-native flex-native xz \
  33. "
  34. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  35. PROVIDES = "virtual/perf"
  36. inherit linux-kernel-base kernel-arch manpages
  37. # needed for building the tools/perf Python bindings
  38. inherit ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'pythonnative', '', d)}
  39. inherit python-dir
  40. export PYTHON_SITEPACKAGES_DIR
  41. #kernel 3.1+ supports WERROR to disable warnings as errors
  42. export WERROR = "0"
  43. do_populate_lic[depends] += "virtual/kernel:do_patch"
  44. # needed for building the tools/perf Perl binding
  45. include ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'perf-perl.inc', '', d)}
  46. inherit kernelsrc
  47. S = "${WORKDIR}/${BP}"
  48. SPDX_S = "${S}/tools/perf"
  49. # The LDFLAGS is required or some old kernels fails due missing
  50. # symbols and this is preferred than requiring patches to every old
  51. # supported kernel.
  52. LDFLAGS="-ldl -lutil"
  53. EXTRA_OEMAKE = '\
  54. -C ${S}/tools/perf \
  55. O=${B} \
  56. CROSS_COMPILE=${TARGET_PREFIX} \
  57. ARCH=${ARCH} \
  58. CC="${CC}" \
  59. AR="${AR}" \
  60. LD="${LD}" \
  61. EXTRA_CFLAGS="-ldw" \
  62. EXTRA_LDFLAGS="${PERF_EXTRA_LDFLAGS}" \
  63. perfexecdir=${libexecdir} \
  64. NO_GTK2=1 \
  65. ${PACKAGECONFIG_CONFARGS} \
  66. TMPDIR="${B}" \
  67. '
  68. EXTRA_OEMAKE += "\
  69. 'DESTDIR=${D}' \
  70. 'prefix=${prefix}' \
  71. 'bindir=${bindir}' \
  72. 'sharedir=${datadir}' \
  73. 'sysconfdir=${sysconfdir}' \
  74. 'perfexecdir=${libexecdir}/perf-core' \
  75. 'ETC_PERFCONFIG=${@os.path.relpath(sysconfdir, prefix)}' \
  76. 'sharedir=${@os.path.relpath(datadir, prefix)}' \
  77. 'mandir=${@os.path.relpath(mandir, prefix)}' \
  78. 'infodir=${@os.path.relpath(infodir, prefix)}' \
  79. "
  80. # During do_configure, we might run a 'make clean'. That often breaks
  81. # when done in parallel, so disable parallelism for do_configure. Note
  82. # that it has to be done this way rather than by passing -j1, since
  83. # perf's build system by default ignores any -j argument, but does
  84. # honour a JOBS variable.
  85. EXTRA_OEMAKE_append_task-configure = " JOBS=1"
  86. PERF_SRC ?= "Makefile \
  87. include \
  88. tools/arch \
  89. tools/build \
  90. tools/include \
  91. tools/lib \
  92. tools/Makefile \
  93. tools/perf \
  94. tools/scripts \
  95. "
  96. PERF_EXTRA_LDFLAGS = ""
  97. # MIPS N32
  98. PERF_EXTRA_LDFLAGS_mipsarchn32eb = "-m elf32btsmipn32"
  99. PERF_EXTRA_LDFLAGS_mipsarchn32el = "-m elf32ltsmipn32"
  100. do_compile() {
  101. # Linux kernel build system is expected to do the right thing
  102. unset CFLAGS
  103. oe_runmake all
  104. }
  105. do_install() {
  106. # Linux kernel build system is expected to do the right thing
  107. unset CFLAGS
  108. oe_runmake install
  109. # we are checking for this make target to be compatible with older perf versions
  110. if ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'true', 'false', d)} && grep -q install-python_ext ${S}/tools/perf/Makefile*; then
  111. oe_runmake DESTDIR=${D} install-python_ext
  112. fi
  113. }
  114. do_configure[prefuncs] += "copy_perf_source_from_kernel"
  115. python copy_perf_source_from_kernel() {
  116. sources = (d.getVar("PERF_SRC") or "").split()
  117. src_dir = d.getVar("STAGING_KERNEL_DIR")
  118. dest_dir = d.getVar("S")
  119. bb.utils.mkdirhier(dest_dir)
  120. for s in sources:
  121. src = oe.path.join(src_dir, s)
  122. dest = oe.path.join(dest_dir, s)
  123. if not os.path.exists(src):
  124. bb.fatal("Path does not exist: %s. Maybe PERF_SRC does not match the kernel version." % src)
  125. if os.path.isdir(src):
  126. oe.path.copyhardlinktree(src, dest)
  127. else:
  128. bb.utils.copyfile(src, dest)
  129. }
  130. do_configure_prepend () {
  131. # If building a multlib based perf, the incorrect library path will be
  132. # detected by perf, since it triggers via: ifeq ($(ARCH),x86_64). In a 32 bit
  133. # build, with a 64 bit multilib, the arch won't match and the detection of a
  134. # 64 bit build (and library) are not exected. To ensure that libraries are
  135. # installed to the correct location, we can use the weak assignment in the
  136. # config/Makefile.
  137. #
  138. # Also need to relocate .config-detected to $(OUTPUT)/config-detected
  139. # for kernel sources that do not already do this
  140. # as two builds (e.g. perf and lib32-perf from mutlilib can conflict
  141. # with each other if its in the shared source directory
  142. #
  143. if [ -e "${S}/tools/perf/config/Makefile" ]; then
  144. perfconfig="${S}/tools/perf/config/Makefile"
  145. fi
  146. if [ -e "${S}/tools/perf/Makefile.config" ]; then
  147. perfconfig="${S}/tools/perf/Makefile.config"
  148. fi
  149. if [ -n "${perfconfig}" ]; then
  150. # Match $(prefix)/$(lib) and $(prefix)/lib
  151. sed -i -e 's,^libdir = \($(prefix)/.*lib\),libdir ?= \1,' \
  152. -e 's,^perfexecdir = \(.*\),perfexecdir ?= \1,' \
  153. -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
  154. ${perfconfig}
  155. fi
  156. # The man pages installation is "$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)"
  157. # in ${S}/tools/perf/Documentation/Makefile, if the mandir set to '?=', it
  158. # will use the relative path 'share/man', in the way it will resulting in
  159. # incorrect installation for man pages.
  160. if [ -e "${S}/tools/perf/Documentation/Makefile" ]; then
  161. sed -i 's,^mandir?=,mandir:=,' ${S}/tools/perf/Documentation/Makefile
  162. fi
  163. if [ -e "${S}/tools/perf/Makefile.perf" ]; then
  164. sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
  165. ${S}/tools/perf/Makefile.perf
  166. sed -i -e "s,prefix='\$(DESTDIR_SQ)/usr'$,prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
  167. ${S}/tools/perf/Makefile.perf
  168. fi
  169. sed -i -e "s,--root='/\$(DESTDIR_SQ)',--prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
  170. ${S}/tools/perf/Makefile*
  171. if [ -e "${S}/tools/build/Makefile.build" ]; then
  172. sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
  173. ${S}/tools/build/Makefile.build
  174. fi
  175. # We need to ensure the --sysroot option in CC is preserved
  176. if [ -e "${S}/tools/perf/Makefile.perf" ]; then
  177. sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/perf/Makefile.perf
  178. sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/perf/Makefile.perf
  179. sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/perf/Makefile.perf
  180. fi
  181. if [ -e "${S}/tools/lib/api/Makefile" ]; then
  182. sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/api/Makefile
  183. sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/api/Makefile
  184. sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/lib/api/Makefile
  185. fi
  186. if [ -e "${S}/tools/lib/subcmd/Makefile" ]; then
  187. sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/subcmd/Makefile
  188. sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/subcmd/Makefile
  189. fi
  190. if [ -e "${S}/tools/perf/config/feature-checks/Makefile" ]; then
  191. sed -i 's,CC := $(CROSS_COMPILE)gcc -MD,CC += -MD,' ${S}/tools/perf/config/feature-checks/Makefile
  192. fi
  193. if [ -e "${S}/tools/build/Makefile.feature" ]; then
  194. sed -i 's,CFLAGS=,CC="\$(CC)" CFLAGS=,' ${S}/tools/build/Makefile.feature
  195. fi
  196. # 3.17-rc1+ has a include issue for arm/powerpc. Temporarily sed in the appropriate include
  197. if [ -e "${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c" ]; then
  198. 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
  199. fi
  200. if [ -e "${S}/tools/perf/arch/arm/util/unwind-libunwind.c" ] && [ -e "${S}/tools/perf/arch/arm/tests/dwarf-unwind.c" ]; then
  201. 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
  202. 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
  203. fi
  204. # use /usr/bin/env instead of version specific python
  205. for s in `find ${S}/tools/perf/scripts/python/ -name '*.py'`; do
  206. sed -i 's,/usr/bin/python2,/usr/bin/env python,' "${s}"
  207. done
  208. }
  209. python do_package_prepend() {
  210. d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
  211. }
  212. PACKAGE_ARCH = "${MACHINE_ARCH}"
  213. PACKAGES =+ "${PN}-archive ${PN}-tests ${PN}-perl ${PN}-python"
  214. RDEPENDS_${PN} += "elfutils bash"
  215. RDEPENDS_${PN}-archive =+ "bash"
  216. RDEPENDS_${PN}-python =+ "bash python python-modules ${@bb.utils.contains('PACKAGECONFIG', 'audit', 'audit-python', '', d)}"
  217. RDEPENDS_${PN}-perl =+ "bash perl perl-modules"
  218. RDEPENDS_${PN}-tests =+ "python"
  219. RSUGGESTS_SCRIPTING = "${@bb.utils.contains('PACKAGECONFIG', 'scripting', '${PN}-perl ${PN}-python', '',d)}"
  220. RSUGGESTS_${PN} += "${PN}-archive ${PN}-tests ${RSUGGESTS_SCRIPTING}"
  221. FILES_${PN} += "${libexecdir}/perf-core ${exec_prefix}/libexec/perf-core ${libdir}/traceevent"
  222. FILES_${PN}-archive = "${libdir}/perf/perf-core/perf-archive"
  223. FILES_${PN}-tests = "${libdir}/perf/perf-core/tests ${libexecdir}/perf-core/tests"
  224. FILES_${PN}-python = " \
  225. ${PYTHON_SITEPACKAGES_DIR} \
  226. ${libexecdir}/perf-core/scripts/python \
  227. "
  228. FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl"
  229. INHIBIT_PACKAGE_DEBUG_SPLIT="1"