☰
gprof性能分析
2026/11/2 1:10:12 网站建设 项目流程

针对代码调优,不侵入函数,图表分析,调用链路优化

LINUX:

1.Linux下cmake环境配置

2.git checkout lp/gprof

3.gprof使用手册:GNU gprof

3.启动docker环境,运行:build.sh

4.bin目录运行:./pPerf,运行退出后,当前目录下自动生成gmon.out

5.运行:gprof -b ./pixsoPerf gmon.out>gmon.txt

6.可视化环境配置:https://www.cnblogs.com/oloroso/p/6548189.html,docker下安装只有一次,可以配置到本地或wsl

7.cd gprof2dot && cat ../bin/gmon.txt | python3 gprof2dot.py | dot -Tpdf -o output.pdf

WINDOWS:

1.安装附件verysleepy-0.91.exe,qcachegrind074-32bit-x86.zip

2.启动main.exe,启动verysleepy,左侧选中main进程,点击右下角allProfile开始性能分析

3.点击stop停止

4.点击菜单file-》export as Callgrind

5.启动qcachegrind.exe打开导出文件

附一:

gprof2dot 命令行选项
选项 含义
-o FILE, --output=FILE 指定输出文件,默认是标准输出(也即屏幕),还可以通过重定向来实现该选项
-n PERCENTAGE, --node-thres=PERCENTAGE 运行时间占比小于PERCENTAGE的节点(函数调用)不展示(默认阈值是0.5)
-e PERCENTAGE, --edge-thres=PERCENTAGE 作用和上面类似,对边进行剪枝
-f FORMAT, --format=FORMAT 性能分析日志的来源,支持的来源有:axe, callgrind, hprof, json, oprofile, perf, prof, pstats, sleepy, sysprof, xperf。该脚本支持多种性能分析工具,默认是prof,我们采用的是callgrind分析工具。
–total=TOTALMETHOD 采用哪种方法统计总时间:callratios 或者 callstacks(只对perf分析工具有作用),默认是callratios 。
-c THEME, --colormap=THEME 颜色主题:color, pink, gray, bw,默认是color,效果也最好。
-s, --strip 不显示函数参数、模版参数、常量修饰符等对展示无影响的符号,启用该选项会让生成的图片更直观易懂,一般启用。
-w, --wrap 当函数名过长的时候自动换行,启用会让生成的图片更美观
–show-samples 展示function samples?
-z ROOT, --root=ROOT 只展示ROOT函数及其子孙调用关系,忽略其他调用,当函数调用关系复杂只分析某一部分函数的调用关系时非常有用。
-l LEAF, --leaf=LEAF 只展示某个函数及其父亲调用关系,忽略其他调用。
–skew=THEME_SKEW 调整节点颜色的区分度。值<1区分度更明显,否则更不明显。建议用默认值,或者<1的值。

示例:python3 gprof2dot.py -n0 -e0

附件:

win下搭建gprof2dot环境依赖graphviz:https://gitlab.com/api/v4/projects/4207231/packages/generic/graphviz-releases/5.0.1/windows_10_cmake_Release_graphviz-install-5.0.1-win64.exe

verysleepy.exe GitHub - VerySleepy/verysleepy: Very Sleepy, a sampling CPU profiler for Windows

qcachegrind.zip GitHub - aur-archive/qcachegrind-qt5-git

docker下安装本地库:

apt-get install ./libimagequant0_2.12.2-1.1_amd64.deb
apt-get install ./libimagequant-dev_2.12.2-1.1_amd64.deb

Arch Linux:yay -S intel-vtune-profiler-standalone
vtune -collect hpc-performance /path/to/main

其它工具参考:

谷歌性能分析

GitHub - gperftools/gperftools: Main gperftools repository

https://github.com/google/perfetto

https://github.com/pierricgimmig/orbitprofile

KCachegrind

graphviz kprof

include-what-you-use

WinCacheGrind

git://git.code.sf.net/p/oprofile/oprofile

https://quick-bench.com/q/ED4MLeeJX-gr-VfFZTz09Odzr8A C++代码压测
chrome://tracing/
https://github.com/catapult-project/catapult chrome性能数据分析
https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/edit?pli=1#heading=h.yr4qxyxotyw chrome性能数据格式,可自定义输出到chorme显示

https://www.cnblogs.com/oloroso/p/6548189.html

Intel VTune profiler — Scipion 3.0.0 documentation

GitHub - wolfpld/tracy: Frame profiler

https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler.html


创作不易,小小的支持一下吧!

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询