编译 jemalloc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # 需要在编译时指定 `--enable-prof` 参数,`--enable-prof-libunwind` 打开 libunwind 堆栈。
mkdir build cd build ../configure --prefix=/usr/local/jemalloc_5.2.1 --enable-debug --enable-prof --enable-log make -j4 sudo make install
# 编译 aarch64 mkdir build_aarch64 cd build_aarch64 ../configure --prefix=/usr/local/jemalloc_5.2.1 --host=aarch64-linux-gnu --target=aarch64-linux-gnu --enable-debug --enable-prof --with-lg-page=16 --enable-prof-libunwind make -j10
--enable-prof-libunwind: 打开 libunwind 堆栈 --with-lg-page=16 设置 page size 为 65536。用于交叉编译
--with-lg-page=<lg-page> 指定系统页面大小,以 2 为基数。此选项仅用于交叉编译 --with-lg-page-size=<lg-page-size>
|
问题:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 一、 交叉编译后,在 arm 上使用出现 <jemalloc>: Unsupported system page size 可能是因为在 x86 上编译的 jemalloc 使用了 x86 特有的页面大小,而在 aarch64 上使用时无法识别. x86 上 getconf PAGE_SIZE. 得到 4096 aarch64 上使用 $ python -c 'import os; print(os.sysconf("SC_PAGE_SIZE"))' 得到 65536 因此,使用 --with-lg-page=16 指定系统页面大小。解决此问题
二、想要增加 libunwind.so 来进行获取堆栈 增加环境变量 export CPPFLAGS="-I/data/App/toolchain/target/out_aarch64/libunwind-1.5.0/include" export LDFLAGS="-L/data/App/toolchain/target/out_aarch64/libunwind-1.5.0/lib -Wl,-rpath=/data/App/toolchain/target/out_aarch64/libunwind-1.5.0/lib"
使用 libunwind.so 1.6.2 版本,会 core 换成 libunwind.so 1.1 版本,不行,不支持 aarch64 换成 libunwind.so 1.5.0 版本,可以。**注意要把生成的 unwind/bin 下的所有 lib 都拷贝到指定环境 ** 现在看起来生成的 heap 文件,使用 jeprof 可以解析出堆栈信息了。但是这些信息并没有被解析成符号 是因为 addr2line 这个二进制没有的缘故,加上即可。现在 jeprof 一些基本选项可以使用
三、对于 jeprof 的一些其他选项,比如 --svg 需要 Graphviz 的 dot 这些工具。交叉编译 Graphviz 然后使用 dot 即可 dot 在使用时,发现使用不正常,lib 文件放的位置不正确,需要调整。
|
最终的 jemalloc(mem_profiler)编译方法
1 2 3 4 5 6 7 8 9 10 11
| export CC=aarch64-linux-gnu-gcc export CXX=aarch64-linux-gnu-g++ export LD=aarch64-linux-gnu-ld export AR=aarch64-linux-gnu-ar export AS=aarch64-linux-gnu-as export RANLIB=aarch64-linux-gnu-ranlib
export CPPFLAGS="-I/data/App/toolchain/target/out_aarch64/libunwind-1.5.0/include" export LDFLAGS="-L/data/App/toolchain/target/out_aarch64/libunwind-1.5.0/lib"
../configure --prefix=/data/App/toolchain/target/out_aarch64/mem_profiler_jemalloc_5.2.1 --build=x86_64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu --enable-debug --enable-prof --with-lg-page=16 --enable-prof-libunwind
|