最近在摆弄算法的的优化,需要剖分一下算法的瓶颈,就找了一些代码剖分工具,其中

gprofileer-tools是很不错的工具,gperftools时google开源的一款C++性能分析分析工具,github项目地址如下:

   https://github.com/gperftools/gperftools

  一 下载和安装:

  1.git clone:

2 . 安装:

   根目录下执行:sh autogen.sh

 然后执行:./configure

最后:make all && sudo make install

安装成功。

   如果没有安装libunwind会出现如,configure执行后报警告:   

configure: WARNING: No frame pointers and no libunwind. Using experimental backtrace capturing via libgcc. Expect crashy cpu profiler.

   解决方法:

使用命令apt-get install libunwind8-dev安装libunwind即可。

  3 最后使用ldconfig更新一下库文件即可。

  二 使用和实例:

  1 使用gprofiler-tools需要在的代码中添加如下几段代码:

   A头文件:

    #include <gperftools/profiler.h>

   B 起止函数:

    修改程序的源代码使得要profiler的代码段包含在ProfilerStart("name");ProfilerStop();

   C链接文件添加需要链接的宏:

    lprofiler //cpu性能

    -ltcmalloc  //heap资源

  2 实例:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <gperftools/profiler.h>
#include <unistd.h> void consumeSomeCPUTime1(int input){
int i = ;
input++;
while(i++ < ){
i--; i++; i--; i++;
}
}; void consumeSomeCPUTime2(int input){
input++;
consumeSomeCPUTime1(input);
int i = ;
while(i++ < ){
i--; i++; i--; i++;
}
}; int stupidComputing(int a, int b){
int i = ;
while( i++ < ){
consumeSomeCPUTime1(i);
}
int j = ;
while(j++ < ){
consumeSomeCPUTime2(j);
}
return a+b;
}; int smartComputing(int a, int b){
return a+b;
}; int main()
{
int i = ;
printf("reached the start point of performance bottle neck\n");
sleep();
ProfilerStart("CPUProfile");
while( i++ < ){
printf("Stupid computing return : %d\n",stupidComputing(i, i+));
printf("Smart computing return %d\n",smartComputing(i+, i+));
}
printf("should teminate profiling now.\n");
ProfilerStop();
sleep(); return ;
}

  编译运行:

gcc -g test.c -o prog -lprofiler

  

export CPUPROFILE=info.prof

  执行:

pprof -text prog info.prof

  结果:

Using local file prog.
Using local file info.prof.
Total: samples
75.4% 75.4% 75.4% consumeSomeCPUTime1
24.6% 100.0% 50.0% consumeSomeCPUTime2
0.0% 100.0% 100.0% __libc_start_main
0.0% 100.0% 100.0% _start
0.0% 100.0% 100.0% main
0.0% 100.0% 100.0% stupidComputing

 

报错一:

Google perftool cannot read file “libprofiler.so.0”

解决方法:

sudo /sbin/ldconfig

错误二:

Using local file prog.
Use of uninitialized value $host in substitution (s///) at /usr/local/bin/pprof line 3366.
Use of uninitialized value $hostport in concatenation (.) or string at /usr/local/bin/pprof line 3368.
Use of uninitialized value $prefix in concatenation (.) or string at /usr/local/bin/pprof line 3368.
Use of uninitialized value $host in substitution (s///) at /usr/local/bin/pprof line 3366.

解决方法:

env CPUPROFILE=/tmp/mybin.prof /home/gprofiler-tools/prog

参考资料:

1 https://www.kancloud.cn/subin/blog/619133

2 https://github.com/gperftools/gperftools

3 https://stackoverflow.com/questions/1581494/google-perftool-cannot-read-file-libprofiler-so-0

4    https://www.ibm.com/developerworks/cn/linux/l-cn-googleperf/index.html

5   https://stackoverflow.com/questions/24086867/cant-analyse-the-output-the-profile-file-of-gperftools-profiler

linux下应用程序性能剖分神器gprofiler-tools-安装和使用的更多相关文章

  1. VMware,win7与linux centos6.4文件互传,linux下挂载windows共享文件夹,vmware tools安装方法

    本方法是以win7,VMware9.0.1 ,centos6.4为基础实验的. 对于linux的初级使用阶段,都会Windows中使用linux虚拟机VMWare或者其它的.在Windows与linu ...

  2. linux下关于程序性能和系统性能的工具、方法

    观察性能/状态的方法:top free netstat /pro/目录下的信息 其中/pro/meminfo下的信息相当丰富 ------------------------------------- ...

  3. linux下c程序调用reboot函数实现直接重启【转】

    转自:http://www.blog.chinaunix.net/uid-20564848-id-73878.html linux下c程序调用reboot函数实现直接重启 当然你也可以直接调用syst ...

  4. Linux下C程序的编辑,编译和运行以及调试

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

  5. 位图文件(BMP)格式以及Linux下C程序实现(转)

    源:位图文件(BMP)格式以及Linux下C程序实现 说到图片,位图(Bitmap)当然是最简单的,它是Windows显示图片的基本格式,其文件扩展名为*.BMP.由于没有经过任何的压缩,故BMP图 ...

  6. Linux下C程序内存泄露检测

    在linux下些C语言程序,最大的问题就是没有一个好的编程IDE,当然想kdevelop等工具都相当的强大,但我还是习惯使用kdevelop工具,由于没有一个习惯的编程IDE,内存检测也就成了在lin ...

  7. Linux下C程序的内存映像

    2.Linux下C程序的内存映像 2.1. 代码段.只读数据段(1)对应着程序中的代码(函数),代码段在Linux中又叫文本段(.text)(2)只读数据段就是在程序运行期间只能读不能写的数据,con ...

  8. Red Gate系列之五 .NET Reflector 7.6.1.824 Edition .NET程序反编译神器(附插件安装教程2012-10-13更新) 完全破解+使用教程

    原文:Red Gate系列之五 .NET Reflector 7.6.1.824 Edition .NET程序反编译神器(附插件安装教程2012-10-13更新) 完全破解+使用教程 Red Gate ...

  9. Linux下的暴力密码在线破解工具Hydra安装及其组件安装-使用

    Linux下的暴力密码在线破解工具Hydra安装及其组件安装-使用 hydra可以破解: http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Cisco a ...

随机推荐

  1. Spring注解方式配置Redis

    @Configuration public class RedisConfiguraion { @Bean public JedisConnectionFactory redisConnectionF ...

  2. Git 分支合并:合并某次提交

    有时只想合并其它分支到某次提交,而不是所有提交. 一 切换到当前分支 首先,在做一次可能有冲突的合并前尽可能保证工作目录是干净的. 如果你有正在做的工作,要么提交到一个临时分支要么储藏它. 这使你可以 ...

  3. python note 04 list的应用及元组

    1,昨日内容 ascii:字母,数字,特殊字符:1个字节,8位 Unicode:16位 两个字节 升级 32 位 四个字节 utf-8:最少一个字节 8位表示. 英文字母 8位 1个字节 欧洲16位, ...

  4. pythonj基础(六)函数初识

    一.什么是函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可以 ...

  5. Django contenttypes 应用

    Django contenttypes 应用 什么是Django ContentTypes? Django ContentTypes是由Django框架提供的一个核心功能,它对当前项目中所有基于Dja ...

  6. R 语言安装

    在linux下,对于手动安装的软件,当时间长了,我们就会忘记安装这个软件的细节.这就不利于以后软件的卸载工作了.而yum则会帮我们记住相关安装细节,当软件被卸载的时候,没用的文件也会一并被删除.因此, ...

  7. Linux驱动之异步通知的应用

    前面的按键驱动方式都是应用程序通过主动查询的方式获得按键值的: 1.查询方式 2.中断方式 3.poll机制 下面介绍第四种按键驱动的方式 4.异步通知:它可以做到应用程序不用随时去查询按键的状态,而 ...

  8. java项目中VO和DTO以及Entity,各自是在什么情况下应用

    1.entity里的每一个字段,与数据库相对应, 2.dto里的每一个字段,是和你前台页面相对应, 3.VO,这是用来转换从entity到dto,或者从dto到entity的中间的东西.   举个例子 ...

  9. JS-基础动画心得

    写在前面的话:这两种动画方式主要在于对其中算法的理解,理解其中的向上和向下取整很关键.还有一个我犯的毛病,写样式的时候忘记给轮播图ul定位,导致效果出不来,所以有bug时记得排除下css 常用的三种动 ...

  10. HDU 3667.Transportation 最小费用流

    Transportation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...