Skip to content

Commit 8073ec2

Browse files
quadpixelskraj
authored andcommitted
Add recipe for Perfetto
Perfetto (https://perfetto.dev/) is a system profiling, app tracing and trace analysis framework. We started using Perfetto for studying a few performance-related problems for OpenBMC-based systems (both the BMC and the host) and we feel it would be good if Perfetto is included into OpenEmbedded, since embedded systems are usually expected to have predictable performance characteristics, and having a good set of performance analysis tools would make this work easier. Tested: bitbake compile, devtool extract and override Signed-off-by: Sui Chen <[email protected]> Signed-off-by: Khem Raj <[email protected]>
1 parent 9236350 commit 8073ec2

File tree

2 files changed

+222
-0
lines changed

2 files changed

+222
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
From 3b7091243ec03054ca8800b51b85a1c09e7e3075 Mon Sep 17 00:00:00 2001
2+
From: Sui Chen <[email protected]>
3+
Date: Mon, 13 Jun 2022 17:46:49 +0000
4+
Subject: [PATCH] Remove "check_build_deps" build steps
5+
6+
When building with Bitbake, we want Bitbake to manage our dependencies,
7+
so we remove the "check_build_deps" steps from Perfetto.
8+
9+
Also setting "is_cross_compiling" to true, so that the host-side tools
10+
(such as protoc) will always be generated using the native toolchain,
11+
rather than the Bitbake-generated one.
12+
13+
Signed-off-by: Sui Chen <[email protected]>
14+
---
15+
gn/BUILD.gn | 1 -
16+
gn/standalone/BUILD.gn | 12 ++++++------
17+
gn/standalone/BUILDCONFIG.gn | 5 +++--
18+
3 files changed, 9 insertions(+), 9 deletions(-)
19+
20+
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
21+
index 8a7ca72a8..e4a2d39f0 100644
22+
--- a/gn/BUILD.gn
23+
+++ b/gn/BUILD.gn
24+
@@ -111,7 +111,6 @@ group("default_deps") {
25+
deps = [ ":gen_buildflags" ]
26+
if (perfetto_build_standalone) {
27+
public_deps = [
28+
- "//gn/standalone:check_build_deps",
29+
"//gn/standalone/libc++:deps",
30+
"//gn/standalone/sanitizers:deps",
31+
]
32+
diff --git a/gn/standalone/BUILD.gn b/gn/standalone/BUILD.gn
33+
index 582e9b867..9c77ac64c 100644
34+
--- a/gn/standalone/BUILD.gn
35+
+++ b/gn/standalone/BUILD.gn
36+
@@ -441,10 +441,10 @@ config("android_liblog") {
37+
}
38+
39+
# Checks that tools/install-build-deps has been run since it last changed.
40+
-perfetto_check_build_deps("check_build_deps") {
41+
- args = []
42+
-}
43+
+#perfetto_check_build_deps("check_build_deps") {
44+
+# args = []
45+
+#}
46+
47+
-perfetto_check_build_deps("check_build_deps_android") {
48+
- args = [ "--android" ]
49+
-}
50+
+#perfetto_check_build_deps("check_build_deps_android") {
51+
+# args = [ "--android" ]
52+
+#}
53+
diff --git a/gn/standalone/BUILDCONFIG.gn b/gn/standalone/BUILDCONFIG.gn
54+
index 6f32686c1..c041989b0 100644
55+
--- a/gn/standalone/BUILDCONFIG.gn
56+
+++ b/gn/standalone/BUILDCONFIG.gn
57+
@@ -59,8 +59,9 @@ declare_args() {
58+
# the ossfuzz sanitizer overrides this to true. In that config the
59+
# host/target cpu and arch are identical, but we want to build only the
60+
# targets with the sanitizer/fuzzer flags
61+
- is_cross_compiling =
62+
- target_cpu != host_cpu || target_os != host_os || target_triplet != ""
63+
+
64+
+ # for Bitbake build
65+
+ is_cross_compiling = true
66+
}
67+
default_configs = [
68+
"//gn/standalone:debug_symbols",
69+
--
70+
2.37.1
71+
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
LICENSE = "Apache-2.0 & BSD-3-Clause & MIT & Zlib"
2+
3+
LIC_FILES_CHKSUM = "file://LICENSE;md5=f87516e0b698007e9e75a1fe1012b390 \
4+
file://buildtools/libcxx/LICENSE.TXT;md5=55d89dd7eec8d3b4204b680e27da3953 \
5+
file://buildtools/libcxx/utils/google-benchmark/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57 \
6+
file://buildtools/libcxxabi/LICENSE.TXT;md5=7b9334635b542c56868400a46b272b1e \
7+
file://buildtools/libunwind/LICENSE.TXT;md5=f66970035d12f196030658b11725e1a1 \
8+
file://buildtools/protobuf/LICENSE;md5=37b5762e07f0af8c74ce80a8bda4266b \
9+
file://buildtools/zlib/LICENSE;md5=f09575dbfb09420642318b413159496f \
10+
file://debian/copyright;md5=4e08364c82141f181de69d0a2b89d612 \
11+
file://python/LICENSE;md5=c602a632c34ade9c78a976734077bce7"
12+
13+
SRC_URI = "git://github.com/google/perfetto.git;branch=master;protocol=https;name=perfetto \
14+
git://github.com/protocolbuffers/protobuf.git;branch=3.9.x;protocol=https;destsuffix=git/buildtools/protobuf;name=protobuf \
15+
git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git;protocol=https;destsuffix=git/buildtools/libcxx;branch=main;name=libcxx \
16+
git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxxabi.git;protocol=https;destsuffix=git/buildtools/libcxxabi;branch=main;name=libcxxabi \
17+
git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libunwind.git;protocol=https;destsuffix=git/buildtools/libunwind;branch=main;name=libunwind \
18+
git://android.googlesource.com/platform/external/zlib.git;branch=master;protocol=https;destsuffix=git/buildtools/zlib;name=zlib \
19+
https://storage.googleapis.com/perfetto/gn-linux64-1968-0725d782;subdir=git/buildtools/;name=gn \
20+
file://0001-Remove-check_build_deps-build-steps.patch "
21+
22+
SRCREV_perfetto = "5bd3f582c075d0d026c5fe0b5e291d34dee0d976"
23+
SRCREV_protobuf = "6a59a2ad1f61d9696092f79b6d74368b4d7970a3"
24+
SRCREV_libcxx = "d9040c75cfea5928c804ab7c235fed06a63f743a"
25+
SRCREV_libcxxabi = "196ba1aaa8ac285d94f4ea8d9836390a45360533"
26+
SRCREV_libunwind = "d999d54f4bca789543a2eb6c995af2d9b5a1f3ed"
27+
SRCREV_zlib = "5c85a2da4c13eda07f69d81a1579a5afddd35f59"
28+
SRC_URI[gn.sha256sum] = "f706aaa0676e3e22f5fc9ca482295d7caee8535d1869f99efa2358177b64f5cd"
29+
30+
DEPENDS += " ninja-native"
31+
32+
COMPATIBLE_HOST = "(i.86|x86_64|aarch64|arm).*-linux*"
33+
34+
FILES:${PN}:append = " \
35+
${bindir}/tracebox \
36+
"
37+
38+
S = "${WORKDIR}/git"
39+
B = "${WORKDIR}/build"
40+
41+
# Run the GN (Generate Ninja) script, and replace the compiler flags where applicable
42+
do_configure () {
43+
# Configuration needs to be done from the source directory
44+
cd ${S}
45+
# Rename a few build tools if they have not been renamed
46+
cd buildtools
47+
x="gn-linux64-1968-0725d782"
48+
[ -f $x ] && mkdir linux64 && mv $x linux64/gn
49+
chmod +x linux64/gn
50+
cd ..
51+
52+
CC_BIN=`echo $CC | awk '{print $1}'`
53+
CXX_BIN=`echo $CXX | awk '{print $1}'`
54+
STRIP_BIN=`echo $STRIP | awk '{print $1}'`
55+
56+
ARGS="is_debug=false " # Tell gn to use release mode
57+
58+
if [ -z `echo ${TOOLCHAIN} | grep clang` ]; then
59+
ARGS=$ARGS" is_clang=false"
60+
else
61+
ARGS=$ARGS" is_clang=true"
62+
fi
63+
64+
# Architecture parameter accepted by Perfetto
65+
arch=${TARGET_ARCH}
66+
if [ $arch = "i686" ]; then
67+
arch="x86"
68+
elif [ $arch = "x86_64" ]; then
69+
arch="x64"
70+
elif [ $arch = "aarch64" ]; then
71+
arch="arm64"
72+
fi
73+
74+
# For ARM32 with hardware floating point using clang and musl, we need to
75+
# specify -mfloat-abi=hard to make the ABI settings of the linker and the
76+
# compiler match. The linker would use hardware float ABI. The compiler does
77+
# not. As a result we need to force the compiler to do so by adding
78+
# -mfloat-abi=hard to compilation flags.
79+
FLOAT_ABI=""
80+
if [[ "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'true', 'false', d)}" == "true" ]]; then
81+
FLOAT_ABI="-mfloat-abi=hard"
82+
fi
83+
84+
ARGS=$ARGS" target_os=\"linux\""
85+
ARGS=$ARGS" target_cpu=\"$arch\""
86+
ARGS=$ARGS" target_cc=\"$CC_BIN ${FLOAT_ABI}\""
87+
ARGS=$ARGS" target_cxx=\"$CXX_BIN -std=c++11 ${FLOAT_ABI}\""
88+
ARGS=$ARGS" target_strip=\"$STRIP_BIN\"" #
89+
ARGS=$ARGS" target_sysroot=\"${RECIPE_SYSROOT}\""
90+
ARGS=$ARGS" target_linker=\"$CC_BIN ${FLOAT_ABI} ${LDFLAGS}\""
91+
ARGS=$ARGS" target_ar=\"$AR\""
92+
ARGS="'$ARGS'"
93+
cmd="tools/gn gen --args=$ARGS ${B}"
94+
95+
echo $cmd
96+
# Use eval, not just call $cmd, due to escaping of single quotation marks
97+
eval $cmd
98+
99+
cd ${B}
100+
# Eliminate a few incompatible build flags
101+
REPLACES="s/-Wl,--icf=all//g"
102+
REPLACES=$REPLACES";s/-Werror//g"
103+
REPLACES=$REPLACES";s/-mfpu=neon//g"
104+
REPLACES=$REPLACES";s/-fcolor-diagnostics//g"
105+
REPLACES=$REPLACES";s/=format-security//g"
106+
REPLACES=$REPLACES";s/-fdiagnostics-show-template-tree//g"
107+
REPLACES=$REPLACES";s/-D_FORTIFY_SOURCE=2//g"
108+
REPLACES=$REPLACES";s/-fuse-ld=\S*//g"
109+
110+
find . -name "*.ninja" | xargs sed $REPLACES -i
111+
112+
# If using the clang toolchain: use the clang host-side binaries built by Bitbake
113+
if [ "${TOOLCHAIN}" = "clang" ]; then
114+
BB_CLANGXX="${BUILD_CXX} ${BUILD_LDFLAGS} ${FLOAT_ABI}"
115+
BB_CLANG="${BUILD_CC} ${FLOAT_ABI}"
116+
BB_LLVM_OBJCOPY="${RECIPE_SYSROOT_NATIVE}/usr/bin/llvm-objcopy"
117+
118+
HOST_CLANGXX="${STAGING_DIR_NATIVE}/usr/bin/clang++ -stdlib=libc++ -rtlib=libgcc -unwindlib=libgcc ${FLOAT_ABI}"
119+
HOST_CLANG="${STAGING_DIR_NATIVE}/usr/bin/clang ${FLOAT_ABI}"
120+
HOST_LLVM_OBJCOPY="${STAGING_DIR_NATIVE}/usr/bin/llvm-objcopy"
121+
122+
cd gcc_like_host
123+
REPLACES="s:\S*clang++ :$HOST_CLANGXX :g"
124+
REPLACES=$REPLACES";s:\S*clang :$HOST_CLANG :g"
125+
REPLACES=$REPLACES";s:\S*llvm-objcopy :$HOST_LLVM_OBJCOPY :g"
126+
find . -name "*.ninja" | xargs sed "$REPLACES" -i
127+
cd ..
128+
fi
129+
# Done processing the Ninja files
130+
131+
# Workaround for the functions not supported by musl
132+
if [ "${TCLIBC}" = "musl" ]; then
133+
sed -e 's/strtoll_l(__a, \&__p2, __base, _LIBCPP_GET_C_LOCALE)/strtoll(__a, \&__p2, __base)/g' \
134+
-e 's/strtoull_l(__a, \&__p2, __base, _LIBCPP_GET_C_LOCALE)/strtoull(__a, \&__p2, __base)/g' \
135+
${S}/buildtools/libcxx/include/locale -i
136+
fi
137+
}
138+
139+
# Perfetto generates a few different binaries, such as traced and traced_probes and perfetto.
140+
# The "tracebox" is a busybox that combines the 3 above and provides a single stop for trace capture, so we only build "tracebox" here.
141+
do_compile () {
142+
cd ${B}
143+
ninja -C . tracebox
144+
}
145+
146+
do_install () {
147+
BIN_DIR=${D}${bindir}
148+
149+
install -d -m0755 $BIN_DIR
150+
install ${B}/tracebox $BIN_DIR/tracebox
151+
}

0 commit comments

Comments
 (0)