1. 安装工具:
perf: sudo apt install linux-tools-common
bcc/eBPF: sudo yum install bcc-tools.x86_64 ==> /usr/share/bcc/tools/
Flame Graph: https://github.com/brendangregg/FlameGraph
2. 查看CPU
通过node_exporter可以抓取机器的基本监控信息
/opt/app/node_exporter/node_exporter --no-collector.bonding --no-collector.bcache --no-collector.btrfs --no-collector.entropy --no-collector.ipvs --no-collector.mdadm --no-collector.nfs --no-collector.nfsd --no-collector.powersupplyclass --no-collector.rapl --no-collector.thermal_zone --no-collector.infiniband --no-collector.pressure --no-collector.edac --no-collector.udp_queues --no-collector.uname --no-collector.hwmon --no-collector.arp --no-collector.textfile --no-collector.softnet --no-collector.schedstat --no-collector.timex --no-collector.vmstat --web.disable-exporter-metrics
查看关键服务的进程
2.1 查看11640的CPU信息,用perf工具抓取该进程在300秒内的样本,频率99Hertz
// 生成perf.data(默认文件名)
sudo perf record -F 99 -p 11640 -g -- sleep 300
perf script -i perf.data > profile.linux-perf.txt
2.2 使用stackcollapse脚本package栈样本到一行
// 代码:https://github.com/brendangregg/FlameGraph
./stackcollapse.pl profile.linux-perf.txt > out.folded
2.3 生成🔥
./flamegraph.pl out.folded > perf.svg
或者在线查看:speedscope
内存分析:
使用centos7.6操作系统安装bcc
本次按照官方文档,使用centos7.6操作系统安装bcc
安装依赖
sudo yum install -y epel-release
sudo yum update -y
sudo yum groupinstall -y "Development tools"
sudo yum install -y elfutils-libelf-devel cmake3 git bison flex ncurses-devel
sudo yum install -y luajit luajit-devel # for Lua support
安装和编译LLVM
curl -LO http://releases.llvm.org/7.0.1/llvm-7.0.1.src.tar.xz
curl -LO http://releases.llvm.org/7.0.1/cfe-7.0.1.src.tar.xz
tar -xf cfe-7.0.1.src.tar.xz
tar -xf llvm-7.0.1.src.tar.xz
mkdir clang-build
mkdir llvm-build
cd llvm-build
cmake3 -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DCMAKE_BUILD_TYPE=Release ../llvm-7.0.1.src
make
sudo make install
cd ../clang-build
cmake3 -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DCMAKE_BUILD_TYPE=Release ../cfe-7.0.1.src
make
sudo make install
cd ..
参考
BCC - Dynamic Tracing Tools for Linux Performance Monitoring, Networking and More