blob: 5f0ba7c180446a6792ee1fee13cfdbc3003523e1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "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."
Joel Stanleye252c312017-12-14 15:11:12 +10308HOMEPAGE = "https://perf.wiki.kernel.org/index.php/Main_Page"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
10LICENSE = "GPLv2"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
12PR = "r9"
13
Joel Stanleye252c312017-12-14 15:11:12 +103014PACKAGECONFIG ??= "scripting tui libunwind"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015PACKAGECONFIG[dwarf] = ",NO_DWARF=1"
Brad Bishop79641f22019-09-10 07:20:22 -040016PACKAGECONFIG[scripting] = ",NO_LIBPERL=1 NO_LIBPYTHON=1,perl python3"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017# 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
Joel Stanleye252c312017-12-14 15:11:12 +103020PACKAGECONFIG[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"
Brad Bishop316dfdd2018-06-25 12:45:53 -040025# libaudit support would need scripting to be enabled
26PACKAGECONFIG[audit] = ",NO_LIBAUDIT=1,audit"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027PACKAGECONFIG[manpages] = ",,xmlto-native asciidoc-native"
Brad Bishop64c979e2019-11-04 13:55:29 -050028PACKAGECONFIG[cap] = ",,libcap"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029
30# libunwind is not yet ported for some architectures
31PACKAGECONFIG_remove_arc = "libunwind"
32PACKAGECONFIG_remove_riscv64 = "libunwind"
Brad Bishop316dfdd2018-06-25 12:45:53 -040033
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034DEPENDS = " \
35 virtual/${MLPREFIX}libc \
36 ${MLPREFIX}elfutils \
37 ${MLPREFIX}binutils \
Brad Bishop316dfdd2018-06-25 12:45:53 -040038 bison-native flex-native xz \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039"
40
41do_configure[depends] += "virtual/kernel:do_shared_workdir"
42
43PROVIDES = "virtual/perf"
44
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080045inherit linux-kernel-base kernel-arch manpages
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47# needed for building the tools/perf Python bindings
Brad Bishop79641f22019-09-10 07:20:22 -040048inherit ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'python3native', '', d)}
49inherit python3-dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050export PYTHON_SITEPACKAGES_DIR
51
52#kernel 3.1+ supports WERROR to disable warnings as errors
53export WERROR = "0"
54
55do_populate_lic[depends] += "virtual/kernel:do_patch"
56
57# needed for building the tools/perf Perl binding
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058include ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'perf-perl.inc', '', d)}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059
60inherit kernelsrc
61
Brad Bishop316dfdd2018-06-25 12:45:53 -040062S = "${WORKDIR}/${BP}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063SPDX_S = "${S}/tools/perf"
64
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065# The LDFLAGS is required or some old kernels fails due missing
66# symbols and this is preferred than requiring patches to every old
67# supported kernel.
68LDFLAGS="-ldl -lutil"
69
70EXTRA_OEMAKE = '\
71 -C ${S}/tools/perf \
72 O=${B} \
73 CROSS_COMPILE=${TARGET_PREFIX} \
74 ARCH=${ARCH} \
75 CC="${CC}" \
76 AR="${AR}" \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 LD="${LD}" \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 EXTRA_CFLAGS="-ldw" \
Joel Stanleye252c312017-12-14 15:11:12 +103079 EXTRA_LDFLAGS="${PERF_EXTRA_LDFLAGS}" \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 perfexecdir=${libexecdir} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080081 NO_GTK2=1 \
Joel Stanleye252c312017-12-14 15:11:12 +103082 ${PACKAGECONFIG_CONFARGS} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080083 TMPDIR="${B}" \
Brad Bishop19323692019-04-05 15:28:33 -040084 LIBUNWIND_DIR=${STAGING_EXECPREFIXDIR} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085'
86
87EXTRA_OEMAKE += "\
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088 'DESTDIR=${D}' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 'prefix=${prefix}' \
90 'bindir=${bindir}' \
91 'sharedir=${datadir}' \
92 'sysconfdir=${sysconfdir}' \
93 'perfexecdir=${libexecdir}/perf-core' \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094 'ETC_PERFCONFIG=${@os.path.relpath(sysconfdir, prefix)}' \
95 'sharedir=${@os.path.relpath(datadir, prefix)}' \
96 'mandir=${@os.path.relpath(mandir, prefix)}' \
97 'infodir=${@os.path.relpath(infodir, prefix)}' \
Brad Bishop79641f22019-09-10 07:20:22 -040098 ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'PYTHON=python3 PYTHON_CONFIG=python3-config', '', d)} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050099"
100
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700101# During do_configure, we might run a 'make clean'. That often breaks
102# when done in parallel, so disable parallelism for do_configure. Note
103# that it has to be done this way rather than by passing -j1, since
104# perf's build system by default ignores any -j argument, but does
105# honour a JOBS variable.
106EXTRA_OEMAKE_append_task-configure = " JOBS=1"
107
Brad Bishop316dfdd2018-06-25 12:45:53 -0400108PERF_SRC ?= "Makefile \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400109 tools/arch \
110 tools/build \
111 tools/include \
112 tools/lib \
113 tools/Makefile \
114 tools/perf \
115 tools/scripts \
Brad Bishop64c979e2019-11-04 13:55:29 -0500116 scripts/ \
117 arch/${ARCH}/Makefile \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400118"
119
Joel Stanleye252c312017-12-14 15:11:12 +1030120PERF_EXTRA_LDFLAGS = ""
121
122# MIPS N32
123PERF_EXTRA_LDFLAGS_mipsarchn32eb = "-m elf32btsmipn32"
124PERF_EXTRA_LDFLAGS_mipsarchn32el = "-m elf32ltsmipn32"
125
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126do_compile() {
127 # Linux kernel build system is expected to do the right thing
128 unset CFLAGS
129 oe_runmake all
130}
131
132do_install() {
133 # Linux kernel build system is expected to do the right thing
134 unset CFLAGS
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500135 oe_runmake install
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 # we are checking for this make target to be compatible with older perf versions
Joel Stanleye252c312017-12-14 15:11:12 +1030137 if ${@bb.utils.contains('PACKAGECONFIG', 'scripting', 'true', 'false', d)} && grep -q install-python_ext ${S}/tools/perf/Makefile*; then
Brad Bishop79641f22019-09-10 07:20:22 -0400138 oe_runmake DESTDIR=${D} install-python_ext
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 fi
140}
141
Brad Bishop316dfdd2018-06-25 12:45:53 -0400142do_configure[prefuncs] += "copy_perf_source_from_kernel"
143python copy_perf_source_from_kernel() {
144 sources = (d.getVar("PERF_SRC") or "").split()
145 src_dir = d.getVar("STAGING_KERNEL_DIR")
146 dest_dir = d.getVar("S")
147 bb.utils.mkdirhier(dest_dir)
148 for s in sources:
149 src = oe.path.join(src_dir, s)
150 dest = oe.path.join(dest_dir, s)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800151 if not os.path.exists(src):
152 bb.fatal("Path does not exist: %s. Maybe PERF_SRC does not match the kernel version." % src)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400153 if os.path.isdir(src):
154 oe.path.copyhardlinktree(src, dest)
155 else:
Brad Bishop64c979e2019-11-04 13:55:29 -0500156 src_path = os.path.dirname(s)
157 os.makedirs(os.path.join(dest_dir,src_path),exist_ok=True)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400158 bb.utils.copyfile(src, dest)
159}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160
Brad Bishop316dfdd2018-06-25 12:45:53 -0400161do_configure_prepend () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 # If building a multlib based perf, the incorrect library path will be
163 # detected by perf, since it triggers via: ifeq ($(ARCH),x86_64). In a 32 bit
164 # build, with a 64 bit multilib, the arch won't match and the detection of a
165 # 64 bit build (and library) are not exected. To ensure that libraries are
166 # installed to the correct location, we can use the weak assignment in the
167 # config/Makefile.
168 #
169 # Also need to relocate .config-detected to $(OUTPUT)/config-detected
170 # for kernel sources that do not already do this
171 # as two builds (e.g. perf and lib32-perf from mutlilib can conflict
172 # with each other if its in the shared source directory
173 #
174 if [ -e "${S}/tools/perf/config/Makefile" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600175 perfconfig="${S}/tools/perf/config/Makefile"
176 fi
177 if [ -e "${S}/tools/perf/Makefile.config" ]; then
178 perfconfig="${S}/tools/perf/Makefile.config"
179 fi
180 if [ -n "${perfconfig}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181 # Match $(prefix)/$(lib) and $(prefix)/lib
182 sed -i -e 's,^libdir = \($(prefix)/.*lib\),libdir ?= \1,' \
183 -e 's,^perfexecdir = \(.*\),perfexecdir ?= \1,' \
184 -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600185 ${perfconfig}
186 fi
187 # The man pages installation is "$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)"
188 # in ${S}/tools/perf/Documentation/Makefile, if the mandir set to '?=', it
189 # will use the relative path 'share/man', in the way it will resulting in
190 # incorrect installation for man pages.
191 if [ -e "${S}/tools/perf/Documentation/Makefile" ]; then
192 sed -i 's,^mandir?=,mandir:=,' ${S}/tools/perf/Documentation/Makefile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193 fi
194 if [ -e "${S}/tools/perf/Makefile.perf" ]; then
195 sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
196 ${S}/tools/perf/Makefile.perf
197 sed -i -e "s,prefix='\$(DESTDIR_SQ)/usr'$,prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
198 ${S}/tools/perf/Makefile.perf
199 fi
200 sed -i -e "s,--root='/\$(DESTDIR_SQ)',--prefix='\$(DESTDIR_SQ)/usr' --install-lib='\$(DESTDIR)\$(PYTHON_SITEPACKAGES_DIR)',g" \
Patrick Williamsd7e96312015-09-22 08:09:05 -0500201 ${S}/tools/perf/Makefile*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202
203 if [ -e "${S}/tools/build/Makefile.build" ]; then
204 sed -i -e 's,\ .config-detected, $(OUTPUT)/config-detected,g' \
205 ${S}/tools/build/Makefile.build
206 fi
207
208 # We need to ensure the --sysroot option in CC is preserved
209 if [ -e "${S}/tools/perf/Makefile.perf" ]; then
210 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/perf/Makefile.perf
211 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/perf/Makefile.perf
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600212 sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/perf/Makefile.perf
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500213 fi
214 if [ -e "${S}/tools/lib/api/Makefile" ]; then
215 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/api/Makefile
216 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/api/Makefile
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600217 sed -i 's,LD = $(CROSS_COMPILE)ld,#LD,' ${S}/tools/lib/api/Makefile
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500219 if [ -e "${S}/tools/lib/subcmd/Makefile" ]; then
220 sed -i 's,CC = $(CROSS_COMPILE)gcc,#CC,' ${S}/tools/lib/subcmd/Makefile
221 sed -i 's,AR = $(CROSS_COMPILE)ar,#AR,' ${S}/tools/lib/subcmd/Makefile
222 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223 if [ -e "${S}/tools/perf/config/feature-checks/Makefile" ]; then
224 sed -i 's,CC := $(CROSS_COMPILE)gcc -MD,CC += -MD,' ${S}/tools/perf/config/feature-checks/Makefile
225 fi
226 if [ -e "${S}/tools/build/Makefile.feature" ]; then
227 sed -i 's,CFLAGS=,CC="\$(CC)" CFLAGS=,' ${S}/tools/build/Makefile.feature
228 fi
229
230 # 3.17-rc1+ has a include issue for arm/powerpc. Temporarily sed in the appropriate include
231 if [ -e "${S}/tools/perf/arch/$ARCH/util/skip-callchain-idx.c" ]; then
232 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
233 fi
234 if [ -e "${S}/tools/perf/arch/arm/util/unwind-libunwind.c" ] && [ -e "${S}/tools/perf/arch/arm/tests/dwarf-unwind.c" ]; then
235 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
236 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
237 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500238
239 # use /usr/bin/env instead of version specific python
Brad Bishop79641f22019-09-10 07:20:22 -0400240 for s in `find ${S}/tools/perf/ -name '*.py'`; do
241 sed -i 's,/usr/bin/python,/usr/bin/env python3,' "${s}"
242 sed -i 's,/usr/bin/python2,/usr/bin/env python3,' "${s}"
243 sed -i 's,/usr/bin/env python2,/usr/bin/env python3,' "${s}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500244 done
Brad Bishop19323692019-04-05 15:28:33 -0400245
246 # unistd.h can be out of sync between libc-headers and the captured version in the perf source
247 # so we copy it from the sysroot unistd.h to the perf unistd.h
Brad Bishopc342db32019-05-15 21:57:59 -0400248 install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/tools/include/uapi/asm-generic/unistd.h
Brad Bishop79641f22019-09-10 07:20:22 -0400249 install -D -m0644 ${STAGING_INCDIR}/asm-generic/unistd.h ${S}/include/uapi/asm-generic/unistd.h
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250}
251
252python do_package_prepend() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500253 d.setVar('PKGV', d.getVar("KERNEL_VERSION").split("-")[0])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254}
255
256PACKAGE_ARCH = "${MACHINE_ARCH}"
257
258
259PACKAGES =+ "${PN}-archive ${PN}-tests ${PN}-perl ${PN}-python"
260
261RDEPENDS_${PN} += "elfutils bash"
262RDEPENDS_${PN}-archive =+ "bash"
Brad Bishop79641f22019-09-10 07:20:22 -0400263RDEPENDS_${PN}-python =+ "bash python3 python3-modules ${@bb.utils.contains('PACKAGECONFIG', 'audit', 'audit-python3', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264RDEPENDS_${PN}-perl =+ "bash perl perl-modules"
Brad Bishop79641f22019-09-10 07:20:22 -0400265RDEPENDS_${PN}-tests =+ "python3"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
Joel Stanleye252c312017-12-14 15:11:12 +1030267RSUGGESTS_SCRIPTING = "${@bb.utils.contains('PACKAGECONFIG', 'scripting', '${PN}-perl ${PN}-python', '',d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500268RSUGGESTS_${PN} += "${PN}-archive ${PN}-tests ${RSUGGESTS_SCRIPTING}"
269
Brad Bishop19323692019-04-05 15:28:33 -0400270FILES_SOLIBSDEV = ""
271FILES_${PN} += "${libexecdir}/perf-core ${exec_prefix}/libexec/perf-core ${libdir}/traceevent ${libdir}/libperf-jvmti.so"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272FILES_${PN}-archive = "${libdir}/perf/perf-core/perf-archive"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500273FILES_${PN}-tests = "${libdir}/perf/perf-core/tests ${libexecdir}/perf-core/tests"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400274FILES_${PN}-python = " \
275 ${PYTHON_SITEPACKAGES_DIR} \
276 ${libexecdir}/perf-core/scripts/python \
277 "
278FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500279
280
281INHIBIT_PACKAGE_DEBUG_SPLIT="1"
Brad Bishopc342db32019-05-15 21:57:59 -0400282DEBUG_OPTIMIZATION_append = " -Wno-error=maybe-uninitialized"