Java Off-cpu 采集指南
in with 0 comment

Java Off-cpu 采集指南

in with 0 comment

bpf安装指南

  1. 安装开发环境
  2. 下载源码包编译bcc-tools
yum install -y elfutils-libelf-devel cmake3 biso flex ncureses-devel
yum install -y luajit luajit-devel
yum install groupinstall -y "Development tools"
yum install -y centos-release-scl
yum config-manager --enable rhel-server-rhscl-7-rpms
yum install -y devtoolset-7 llvm-toolset-7.0 llvm-toolset-7.0-llvm-devel llvm-toolset-7.0-llvm-static llvm-toolset-7.0-clang-devel
source scl_source enable devtoolset-7 llvm-toolset-7.0

bcc 0.25以上请按照llvm9
本次我们使用0.24

wget https://ghproxy.com/https://github.com/iovisor/bcc/releases/download/v0.24.0/bcc-src-with-submodule.tar.gz
tar -zxvf bcc-src-with-submodule.tar.gz
mkdir bcc/build && cd bcc/build
cmake3 .. -DCMAKE_INSTALL_PREFIX=/usr
make -j
sudo make install

安装完成后bcc-tools 在/usr/share/bcc/tools/ 下边 python3 xxx 执行即可

bpftrace 安装

wget https://github.com/iovisor/bpftrace/archive/refs/tags/v0.12.1.zip
unzip bpftrace-0.12.1.zip
cd bpftrace-0.12.1 
mkdir build
cd build 
cmake -DUSE_SYSTEM_BPF_BCC=1 -DCMAKE_BUILD_TYPE=release
make -j128
make install 
./test/bpftrace_test

启动libperfmap.so

以kafak为例子在启动参数中添加

wget https://ghproxy.com/https://github.com/parca-dev/perf-map-agent/releases/download/v0.0.1/libperfmap.so
export KAFKA_OPTS="-XX:+PreserveFramePointer -agentpath:/root/offcpu/libperfmap.so"

抓取offcpu

指定进程和抓取时间
python3 /usr/share/bcc/tools/offcputime -df -p 5249 120 > out.stacks

生成火焰图

git clone https://ghproxy.com/https://github.com/brendangregg/FlameGraph
./FlameGraph/flamegraph.pl --color=io --title="Off-CPU Time Flame Graph" --countname=us < out.stacks > out.svg
Responses