当前位置:网站首页>perf 性能调试
perf 性能调试
2022-07-25 11:55:00 【mightbxg】
perf 是 linux 系统调试工具之一,可以以一定采样频率 (默认 4000Hz) 监测指定进程中函数运行情况,从而分析程序的性能瓶颈,进而针对性优化。
工具安装
perf 并不是 linux 系统默认自带的,需要安装 linux-tools 工具集,比如:
sudo apt install linux-tools-common linux-tools-generic linux-tools-`uname -r`
或者自己从源码编译:
sudo apt install build-essential git flex bison
git clone --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux/tools/perf
make
sudo cp perf /usr/bin
如果你的系统内核自己升级过,那就只能从源码编译,因为 apt 源只有当前系统默认内核的 linux-tools-xxx
perf 使用方法
首先需要把被测试的程序跑起来,并获得其 PID,假设程序名为 my_awesome_app,则获取 PID 的命令为:
MY_PID=$(ps -ef | grep my_awesome_app | grep -v 'grep' | awk '{print $2}')
然后启动 perf 监测:
perf record -F 4000 -g -p $MY_PID -- sleep 80
其中 -F <freq> 指定采样频率,-g 表示记录函数调用栈,-p <PID> 指定被监测的 PID,-- sleep <secs> 指定监测时长,具体请查看 perf record --help
perf 监测后会在当前路径生成 perf.data 文件,执行 perf report -n --stdio 会读取 perf.data 并将结果展示在终端。
火焰图
perf report 分析性能还是很不方便,可以转换成火焰图来查看,工具地址:FlameGraph,具体使用方法仓库里已经写的很清楚了。
参考资料
边栏推荐
- Zuul gateway use
- More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural
- mysql的表分区
- Atomic atomic class
- Pytorch project practice - fashionmnist fashion classification
- 软件测试面试题目:请你列举几个物品的测试方法怎么说?
- 【5】 Page and print settings
- Fiddler抓包APP
- WPF项目入门1-简单登录页面的设计和开发
- scrapy 设置随机的user_agent
猜你喜欢
随机推荐
Pytorch advanced training skills
Azure Devops(十四) 使用Azure的私有Nuget仓库
mysql实现一张表数据插入另一张表
Implementation of recommendation system collaborative filtering in spark
1.1.1 welcome to machine learning
919. Complete binary tree inserter: simple BFS application problem
Zuul gateway use
Eureka使用记录
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure function adds annotation, annotation and annotation information for the combined image, adds image labels fo
Technical management essay
Plus版SBOM:流水线物料清单PBOM
Ansible
Azure Devops (XIV) use azure's private nuget warehouse
Client open download, welcome to try
Feign use
记录一次线上死锁的定位分析
Can't delete the blank page in word? How to operate?
mysql的表分区
Eureka usage record
Basic concepts of NLP 1









