gperftools分析cpu使用情况
来源:互联网 发布:吉林11选5遗漏数据 编辑:程序博客网 时间:2024/05/18 15:08
gperftools是Google提供的一套工具,其中的一个功能是CPU profiler,用于分析函数的执行时间,安装见参考链接,下面是一个简单的使用实例;
一 .代码
test_profiler.cpp
1 #include<iostream> 2 #include<google/profiler.h> 3 using namespace std; 4 5 void testfunc() 6 { 7 int sum = 0; 8 for(int i =0; i < 700000000; ++i) 9 { 10 sum +=i; 11 } 12 std::cout<<"sum:"<<sum<<endl; 13 14 } 15 int main() 16 { 17 ProfilerStart("first.prof"); 18 std::cout<<"hello profiler"<<endl; 19 testfunc(); 20 21 int s = 0; 22 23 for(int i = 0; i < 300000000; ++i) 24 { 25 s +=i; 26 } 27 28 std::cout<<"int main s:"<<s<<endl; 29 30 ProfilerStop(); 31 return 0; 32 }~
二 .编译
Makefile
all:test_profiler.cpp 2 g++ -o test_profile test_profile.cpp -lprofiler -lunwind
三.运行程序
./test_profiler hello profilersum:-1659114368int main s:-302797184PROFILE: interrupts/evictions/bytes = 255/23/1440
三.查看分析结果
pprof –text ./test_profiler test_profiler.prof
Using local file ./test_profiler.Using local file test_profiler.prof.Removing killpg from all stack traces.Total: 255 samples 179 70.2% 70.2% 179 70.2% testfunc 76 29.8% 100.0% 255 100.0% main 0 0.0% 100.0% 255 100.0% __libc_start_main
也可以以图片方式查看
pprof –pdf ./test_profiler test_profiler.prof > output.pdf
参考:
关于gperftools
http://www.cnblogs.com/caosiyang/archive/2013/01/25/2876244.html
google perftools分析程序性能
http://www.cnblogs.com/caosiyang/archive/2013/01/25/2876244.html
安装perftools
http://www.2cto.com/os/201209/155686.html
0 0
- gperftools分析cpu使用情况
- 使用android studio分析cpu使用情况
- gperftools使用
- gperftools使用
- Python脚本分析CPU使用情况
- Python脚本分析CPU使用情况
- gperftools —— cpu profiler
- Linux查看CPU和内存使用情况结果分析
- 跟踪CpU使用情况
- linux cpu使用情况
- CPU使用情况
- gperftools -- heapcheck 使用
- gperftools heap check使用
- gperftools编译与使用
- gperftools工具的使用
- gperftools的使用
- TCMalloc分析笔记(gperftools-2.4)
- gperftools
- 顺序栈和链栈的初始化插入和删除
- Linux下静态库与动态库的使用
- ESXi5.5如何命令行升级到ESXi6.0
- 断舍离——坚持自己的价值选择
- 利用深度优先搜索算法寻找割点
- gperftools分析cpu使用情况
- 二叉树的创建(前序中序创建二叉树、中序后序创建二叉树)
- javascript组件化
- 冒泡排序2.0
- Android四大组件之Activity
- HDU 4737 A Bit Fun(2013成都网络赛)
- 在ubuntu上安装nodebb
- 数据结构---数组(5)
- VS 中捕获内存泄露