**
关于有哪些方法perf线上运行的程序
**
https://stackoverflow.com/questions/375913/how-can-i-profile-c-code-running-on-linux
https://zhuanlan.zhihu.com/p/71437161
如果使用的是 perf:
- 下载kernel代码
make -C <kernel source root directory>/tools/perf
- 找一个最接近的版本安装:
sudo apt-get install linux-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package linux-tools is a virtual package provided by:
linux-tools-oem-osp1 5.0.0.1028.32
...
linux-tools-virtual 4.15.0.70.72
linux-tools-oracle-lts-18.04 4.15.0.1029.34
linux-tools-oracle-edge 5.0.0.1007.6
linux-tools-oracle 4.15.0.1029.34
linux-tools-lowlatency-hwe-18.04 5.0.0.36.94
linux-tools-generic 4.15.0.70.72
...
You should explicitly select one to install.
然后安装一个通用的:
sudo apt-get install linux-tools-generic
cd /usr/lib/linux-tools/linux-tools-4.15.0-70/ # 默认安装在 /usr/lib/linux-toos/xxx 下面
sudo ./perf ...
sudo ./perf top # 类似 top 的动态显示方式
# Sampling CPU stacks at 99 Hertz (-F 99), for the entire system (-a, for all CPUs), with stack traces (-g, for call graphs), for 30 seconds:
sudo ./perf record -F 99 -a -g -- sleep 30
# Sample CPU stack traces for the PID, using dwarf (dbg info, or use `-g` == `--call-graph fp`, i.e frame pointer) to unwind stacks, at 99 Hertz, for 20 seconds:
sudo ./perf record -F 99 --call-graph dwarf -p <PID> sleep 20 # 这个比较清晰
# Sample on-CPU user instructions precisely (using PEBS), for 10 seconds:
perf record -e cycles:up -a -- sleep 10
# Show perf.data as a text report, with data coalesced and percentages:
sudo ./perf report --stdio -i ./perf.data # -g folded or --show-total-period,
sudo ./perf record -e syscalls:sys_enter_* -p <PID> # 统计系统所有调用
- http://www.brendangregg.com/perf.html
- https://perf.wiki.kernel.org/index.php/Tutorial
- https://baptiste-wicht.com/posts/2011/07/profile-applications-linux-perf-tools.html
A good example to perf c++ user function:
http://notes.secretsauce.net/notes/2019/12/16_c-probes-with-perf.html