Linux Perf对进程进程CPU和内存分析

14 篇文章 2 订阅

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

Linux探测工具BCC(可观测性)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值