linux环境下 C++性能测试工具 gprof + kprof + gprof2dot
1.gprof
很有名了,google下很多教程
g++ -pg -g -o test test.cc
./test //会生成gmon.out
gprof ./test > prof.log
看一下对于我前面提到的huffman编码压缩+解码解压缩全部过程的一个程序
对于生成的prof.log ,wow, 很有用处的但是看起来有点累,不是吗:)

Code
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
32.51 1.71 1.71 13127166 0.00 0.00 glzip::HuffTree<unsigned char, glzip::decode_hufftree>::decode_byte(unsigned char, glzip::Buffer&, glzip::HuffNode<unsigned char>*&, int)
18.73 2.69 0.98 105017328 0.00 0.00 glzip::Buffer::write_bit(int)
16.63 3.57 0.88 24292128 0.00 0.00 glzip::Buffer::write_string(std::string const&)
7.22 3.95 0.38 61711820 0.00 0.00 glzip::Buffer::read_byte(unsigned char&)
5.80 4.25 0.30 37419691 0.00 0.00 glzip::Buffer::write_byte(unsigned char)
5.51 4.54 0.29 1 0.29 2.48 glzip::Encoder<unsigned char>::do_encode_file(glzip::char_tag)
5.13 4.82 0.27 105017721 0.00 0.00 glzip::HuffNode<unsigned char>::is_leaf()
3.04 4.97 0.16 1 0.16 0.31 glzip::Encoder<unsigned char>::do_caculate_frequency(glzip::char_tag)
2.47 5.11 0.13 1 0.13 2.42 glzip::HuffTree<unsigned char, glzip::decode_hufftree>::decode_file()
1.14 5.17 0.06 24292227 0.00 0.00 std::vector<std::string, std::allocator<std::string> >::operator[](unsigned int)
0.95 5.21 0.05 1 0.05 0.05 glzip::HuffTree<unsigned char, glzip::encode_hufftree>::do_serialize_tree(glzip::HuffNode<unsigned char>*, glzip::Buffer&)
0.29 5.23 0.01 24292133 0.00 0.00 glzip::HuffTreeBase<unsigned char>::root() const
0.29 5.25 0.01 574 0.00 0.00 glzip::Buffer::flush_buf()
0.19 5.25 0.01 6 0.00 0.00 glzip::Buffer::~Buffer()
0.10 5.26 0.01 unsigned int const& std::min<unsigned int>(unsigned int const&, unsigned int const&)
0.00 5.26 0.00 12901 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::_Deque_iterator(std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**> const&)
0.00 5.26 0.00 6065 0.00 0.00 std::__deque_buf_size(unsigned int)
0.00 5.26 0.00 6056 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::_S_buffer_size()
0.00 5.26 0.00 5656 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::operator*() const
0.00 5.26 0.00 5656 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::operator+=(int)
0.00 5.26 0.00 4871 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::operator+(int) const
0.00 5.26 0.00 3126 0.00 0.00 glzip::HuffNode<unsigned char>::weight() const
0.00 5.26 0.00 1465 0.00 0.00 glzip::HuffTree<unsigned char, glzip::encode_hufftree>::HuffNodePtrGreater::operator()(glzip::HuffNode<unsigned char> const*, glzip::HuffNode<unsigned char> const*)
0.00 5.26 0.00 946 0.00 0.00 glzip::Buffer::fill_buf()
0.00 5.26 0.00 785 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::operator-(int) const
0.00 5.26 0.00 785 0.00 0.00 std::_Deque_iterator<glzip::HuffNode<unsigned char>*, glzip::HuffNode<unsigned char>*&, glzip::HuffNode<unsigned char>**>::operator-=(int)
0.00 5.26 0.00 590 0.00 0.00 glzip::HuffNode<unsigned char>::left() const
0.00 5.26 0.00 590 0.00 0.00 glzip::HuffNode<unsigned char>::right() const
0.00 5.26 0.00 453 0.00 0.00 operator new(unsigned int, void*)
.
2.Kprof
sudo apt-get install kprof
kprof -f ./test //注意已经按照前面的用gprof生成 gmont.out 了。
将gprof , GUI化了,更加友好,还是很方便的,它也利用而来graphviz绘制了运行时流程图,但是对于大的程序,
似乎效果不太好,流程图感觉完全乱掉了,而且对于大程序,kprof运行的有点慢,在我的破机器上跑半天才出来。
总的来说它的object profile还是很方便有用的。
object profile 示意图
![]()
graph view 示意图,这个仅作参考吧,同样是用graphviz怎么和gprof2dot差距这么大呢?:)对比下下面gprof2dot的生成图吧!
![]()
3.gprof2dot.py
这个脚本太TMD的牛X了,速度快效果好,怪不得底下评论一片叫好,这就是life_saving的工具啊!
首先就是运行时的程序流程图,网上有很多工具有些就是利用gprof的,有很多文章介绍,都不用看了,就用这个吧。
然后很直观的看出每个步骤的占用时间百分比,函数调用次数,颜色能直观的表示出瓶颈所在。
gprof2dot安装看这里吧
http://www.51testing.com/?uid-13997-action-viewspace-itemid-79952
gprof ./test | gprof2dot.py | xdot
恩 去下载那个xdot.py吧 看dot文件,太方便了,不需要先生成图像了。
直接看效果图吧!
1.整体图
清晰多了吧,上面那么多冗余的东西。
![]()
2.局部图
![]()
![]()
和我的程序执行过程完全对应,清晰明了,太赞了!
每个方框内部显示函数名称,函数整体包括内部子函数占用时间%比,函数自身,不包括内部子函数占用时间%比,函数执行次数。
边表示父函数调用该子函数占用的时间%比,调用次数。
之所以清晰是因为,gprof2dot默认是部分函数调用图,对性能影响不大的函数调用都不显示,例如上图中没有出现类的构造,析构函数,
如果想要显示全部的函数调用,可以 gprof2dot -n0 -e0 ,默认是n0.5即影响小于5%的函数就不显示了。
当然这样图片会很乱,因为显示内容很多,可以 gprof2dot -n0 -e0 -s #-s表示不显示诸如模板,函数入口参数等等,使得
函数名称显示更加精简。
恩,如果用户能决定只输出某个函数及其关联函数的显示信息图就更好了,例如上面有两个
独立的过程compress()和decompress()如果用户能够决定只是显示compress()就好了,
不过考虑到模板之类的稍微有点麻烦,但是应该也是能实现的!
4. google 还有一个开源的能测试工具
以后尝试一下
http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools
linux环境下 C++性能测试工具 gprof + kprof + gprof2dot的更多相关文章
- Linux环境下apache性能测试工具ab使用详解
网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环.只有让服务器处在高压情况下,才能真正体现出软件.硬件等各种设置不当所暴露出的问题. 性能测试工具目前最常见的有以下几种:ab.http_lo ...
- linux环境下安装tcping工具测试访问超时
wget https://sources.voidlinux.eu/tcping-1.3.5/tcping-1.3.5.tar.gz tar zxvf tcping-1.3.5.tar.gz cd t ...
- Linux环境下使用logrotate工具实现nginx日志切割
一. 前提背景及需求 nginx运行日志默认保存在nginx安装目录下的 /usr/local/nginx/logs 文件夹, 包含access.log和error.log两个文件. (1) acce ...
- Linux 环境下安装rlwrap工具
rlwrap项目是一个“readline包装器”,它使用GNU readline库来编辑任何其他命令的键 盘输入.通过rlwrap可以进行命令的上下切换,类似历史命令. 1.下载rlwrap rpm ...
- [原]Fedora Linux环境下的应用工具总结
一.办公类软件 1.Office办公:WPS 二.网络通信类软件 1.浏览器:Chrome 2.远程桌面:rdesktop(适用于Windows系列) 三.操作系统设置与优化 1.3D桌面管理:Com ...
- 高级工具gprof、gprof2dot.py、dot
可以研究程序性能.函数调用堆栈等,而且能用图标查看. linux环境下 C++性能测试工具 gprof + kprof + gprof2dot - 阁子 - 博客园 gprof.gprof2dot.p ...
- linux环境下的GUN make学习笔记(一)
第一章:概述 1.1:make概述 在linux环境下使用make工具能够比较容易的构建一个属于自己的工程,整个工程的编译只需要一个命令就可以完成编译.连接以至于最后的执行.不过我们需要投入一些时间去 ...
- linux环境下学习使用pro*c/c++工具
1.proc是oracle用来预编译嵌入SQL语句的c程序. 2.如何使用proc工具 在Linux环境下,首先确保gcc编译器正常使用,安装oracle数据库或者客户端,一般就会默认安装pro*c/ ...
- Linux环境下搭建禅道管理工具-包含软件资源
Linux环境下搭建禅道管理工具 1:百度云盘下载: 禅道--链接: https://pan.baidu.com/s/1Stu7nOZVIPO5TnpJWjWtiQ 提取码:dnik CentOs操 ...
随机推荐
- 一道百度的java面试题的几种解法
考试结束,班级平均分只拿到了年级第二,班主任于是问道:大家都知道世界第一高峰珠穆朗玛峰,有人知道世界第二高峰是什么吗?正当班主任要继续发话,只听到角落默默想起来一个声音:”乔戈里峰” 前言 文章出自: ...
- 使用 Angular 和 RxJS 实现的无限滚动加载
无限滚动加载应该是怎样的? 无限滚动加载列表在用户将页面滚动到指定位置后会异步加载数据.这是避免寻主动加载(每次都需要用户去点击)的好方法,而且它能真正保持应用的性能.同时它还是降低带宽和增强用户体验 ...
- 从源码看 Promise 概念与实现
Promise 是 JS 异步编程中的重要概念,它较好地解决了异步任务中回调嵌套的问题.在没有引入新的语言机制的前提下,这是如何实现的呢?上手 Promise 时常见若干晦涩的 API 与概念,它们又 ...
- iOS开源项目周报0223
由OpenDigg 出品的iOS开源项目周报第九期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等.panelkit ...
- Knockout.js Style绑定
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- WCF WCF的宿主
一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类契约的定 ...
- springboot在阿里CentOS 7后台永久运行
查看Java进程可以使用 ps -ef|grep java 首次后台永久启动,会把日志输出到新建的log.file文件 nohup java -jar demo-0.0.1-SNAPSHOT.jar ...
- bnu 10805 矩形神码的 平面向量的运行
矩形神码的 Time Limit: 1000ms Memory Limit: 65536KB Special Judge 64-bit integer IO format: %lld J ...
- Web安全相关(五):SQL注入(SQL Injection)
简介 SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据 ...
- Oracle数据库基本操作 (六) —— 数据的导出与导入
一.cmd 下登录oracle数据库下的指定用户 方式一:命令行明文连接登录 打开cmd,输入:sqlplus/nolog 输入:conn username/passworld@数据库实例名 方式二: ...