gprof使用介绍【转】
转自:https://blog.csdn.net/linquidx/article/details/5916701
gprof
1.1 简介
gprof实际上只是一个用于读取profile结果文件的工具。gprof采用混合方法来收集程序的统计信息,他使用检测方法,在编译过程中在函数入口处插入计数器用于收集每个函数的被调用情况和被调用次数;也使用采样方法,在运行时按一定间隔去检查程序计数器并在分析时找出程序计数器对应的函数来统计函数占用的时间。
Gprof具有以下优缺点:
1) 优点:
a) GNU工具,人手一个;
b) 混合方法采集信息。
2) 缺点:
a) 需要编译选项支持:
i. 使用gcc/cc编译和链接时需要加入-pg选项
ii. 使用ld链接时需要用/lib/gcrt0.o代替crt0.o作为第一个input文件
iii. 如果要调试libc库需要使用-lc_p代替-lc参数
b) 调试多线程程序只能统计主线程的信息(所以不能用于kingbase)。
1.2 使用方法
1.2.1 编译程序
使用gcc/cc编译和链接时需要加入-pg选项
使用ld链接时需要用/lib/gcrt0.o代替crt0.o作为第一个input文件
如果要调试libc库需要使用-lc_p代替-lc参数
1.2.2 运行程序生成统计信息
正常运行编译好的程序,程序正常结束后会在当前目录生成统计信息文件gmon.out。
程序必须正常退出(调用exit或从main中返回)才能生成统计信息。
当前目录下如果有另外叫gmon.out的文件,内容将被本次运行生成的统计信息覆盖,多次运行统一程序请将前一次的gmon.out改名。
1.2.3 使用gprof查看统计结果
命令格式:
gprof options [executable-file [profile-data-files...]] [> outfile]
常用参数介绍:
symspec表示需要加入或排除的函数名,和gdb指定断点时的格式相同。
1) 输出相关:
a) -A[symspec]或--annotated-source[=symspec]:进行源码关联,只关联symspec指定的函数,不指定为全部关联。
b) -I dirs或--directory-path=dirs:添加搜索源码的文件夹,修改环境变量GPROF_PATH也可以。
c) -p[symspec]或--flat-profile[=symspec]:默认选项,输出统计信息,只统计symspec指定的函数,不指定为全部统计。
d) -P[symspec]或--no-flat-profile[=symspec]:排除统计symspec指定的函数
e) -q[symspec]或--graph[=symspec]:默认选项,输出函数调用信息,只统计symspec指定的函数,不指定为全部统计。
f) -Q[symspec]或--no-graph[=symspec]:排除统计symspec指定的函数
g) -b或--brief:不输出对各个参数含义的解释;
2) 分析相关:
a) -a或--no-static:定义为static的函数将不显示,函数的被调用次数将被计算在调用它的不是static的函数中;
b) -m num或--min-count=num:不显示被调用次数小于num的函数;
c) -z或--display-unused-functions:显示没有被调用的函数;
1.3 一个例子
编译测试文件:
gcc –g –o test test.c –pg
执行程序:
./test
查看统计信息:
gprof -b -A -p -q test gmon.out > pg
1.4 gprof产生的信息解析
% the percentage of the total running time of the
time program used by this function.
函数使用时间占所有时间的百分比。
cumulative a running sum of the number of seconds accounted
seconds for by this function and those listed above it.
函数和上列函数累计执行的时间。
self the number of seconds accounted for by this
seconds function alone. This is the major sort for this
listing.
函数本身所执行的时间。
calls the number of times this function was invoked, if
this function is profiled, else blank.
函数被调用的次数
self the average number of milliseconds spent in this
ms/call function per call, if this function is profiled,
else blank.
每一次调用花费在函数的时间microseconds。
total the average number of milliseconds spent in this
ms/call function and its descendents per call, if this
function is profiled, else blank.
每一次调用,花费在函数及其衍生函数的平均时间microseconds。
name the name of the function. This is the minor sort
for this listing. The index shows the location of
the function in the gprof listing. If the index is
in parenthesis it shows where it would appear in
the gprof listing if it were to be printed.
函数名
1.4 结论
我们可以使用程序概要分析快速的找到一个程序里面值得优化的地方。
gprof使用介绍【转】的更多相关文章
- gprof使用介绍
gprof 1.1 简介 gprof实际上只是一个用于读取profile结果文件的工具.gprof采用混合方法来收集程序的统计信息,他使用检测方法,在编译过程中在函数入口处插入计数器用于收集 ...
- gprof使用介绍 (gcc -pg) [转]
原文出处: http://blog.csdn.net/unbutun/article/details/6609498 linux服务端编程,性能总是不可避免要思考的问题. 而单机(严格的说是单核)单线 ...
- Linux性能评测工具之一:gprof篇介绍
转:http://blog.csdn.net/stanjiang2010/article/details/5655143 这些天自己试着对项目作一些压力测试和性能优化,也对用过的测试工具作一些总结,并 ...
- 性能分析工具gprof介绍(转载)
性能分析工具gprof介绍Ver:1.0 目录1. GPROF介绍 42. 使用步骤 43. 使用举例 43.1 测试环境 43.2 测试代码 43.3 数据分析 53.3.1 flat profil ...
- gprof的使用介绍
转于:http://blog.chinaunix.net/uid-25194149-id-3215487.html #不知道这是在哪里找的了,感谢各位~ 性能分析工具gprof介绍Ver:1.0 目录 ...
- linux下内存泄露检测工具Valgrind介绍
目前在linux开发一个分析实时路况的应用程序,在联合测试中发现程序存在内存泄露的情况. 这下着急了,马上就要上线了,还好发现了一款Valgrind工具,完美的解决了内存泄露的问题. 推荐大家可以使用 ...
- gcc g++ 参数介绍
C和C++ 编译器是集成的.他们都要用四个步骤中的一个或多个处理输入文件: 预处理 (preprocessing),编译(compilation),汇编(assembly)和连接(linking).源 ...
- C/C++性能测试工具GNU gprof
代码剖析(Code profiling)程序员在优化软件性能时要注意应尽量优化软件中被频繁调用的部分,这样才能对程序进行有效优化.使用真实的数据,精确的分析应用程序在时间上的花费的行为就成为_代码剖析 ...
- 【c++】内存检查工具Valgrind介绍,安装及使用以及内存泄漏的常见原因
转自:https://www.cnblogs.com/LyndonYoung/articles/5320277.html Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,它包 ...
随机推荐
- docker基础之镜像
获取镜像 从 Docker Registry 获取镜像的命令是 docker pull.其命令格式为: docker pull [选项] [Docker Registry地址]<仓库名>: ...
- my live boadband
id_boadband tel: 02511931324 ¥1600 包2年,10MB/S =100Mb,2018.12.1 ~ 2020.12.1 end
- Xshell安装及漏洞详解
1.下载安装包 ... 2.双击安装包,进入安装第一步 3.输入客户信息 4.选择目的位置,可以通过浏览器进行修改安装路径,点击下一步按钮 5.选择程序文件夹,点击下一步按钮 6.等待安装 7.完成安 ...
- centos 6.5 安装jdk1.8
1.源码包准备: 首先到官网下载jdk-8u66-linux-x64.tar.gz, http://www.oracle.com/technetwork/java/javase/downloads/j ...
- 【1】【leetcode-77】 组合
(典型,做过似曾相识但不熟悉,基本知道怎么做但调试了一个多小时各种错) 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合. 示例: 输入: n = 4, k = 2 输出: ...
- java枚举(enum)
1. 创建枚举类型要使用 enum 关键字,隐含了所创建的类型都是 java.lang.Enum (抽象类) 类的子类. enum AccountType { SAVING, FIXED, CURRE ...
- java的TCP和UDP编程
TCP 客户端: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter ...
- SpringBoot系列: Eclipse+Maven环境准备
这个链接比我写得更全面, http://tengj.top/2018/01/01/maven/ =============================20190115补充: maven 的一些插件 ...
- None.js 第二步 REPL(交互式解析器)
简单的表达式 $ node 1 + 4 // 5 5 / 2 // 2.5 3 * 5 // 15 使用变量 $ node x = 5 // 5 var y = 10 // undefined con ...
- idea 创建运行web项目时,报错: Can not issue executeUpdate() for SELECTs解决方案
最近在做一个Web课程设计的时候遇到了如下的问题. java.sql.SQLException: java.lang.RuntimeException: java.sql.SQLException: ...