GNU Profiling
来源:互联网 发布:python 书籍 知乎 编辑:程序博客网 时间:2024/05/15 09:28
Profiling 允许你知道你的程序在哪里消耗的时间,函数之间的调用。一般适用于较大型的项目或者程序。程序的运行会影响profile data里面的结果。
1.Compiling a Program for Profiling
先打开profiling程序
如果你用cc这类命令编译程序,需要加上-pg选项,下面是例子:
cc -g -c myprog.c utils.c -pgcc -o myprog myprog.o utils.o -pg
假如你是直接运行链接器(ld)而不是通过编译器,例如cc,你需要特别指定profiling启动文件gcrt0.o作为首先输入的文件而不是通常的启动文件crt0.o。为了获得标准库函数的相关启动信息,可以通过选项-lc_p来代替lc,从而使用库libc_p.a。
例如:
ld -o myprog /lib/gcrt0.o myprog.o utils.o -lc_p
假如你只是使用-pg编译了部分模块,你也可以得到部分数据。
如果你需要一行一行的进行profiling,你需要使用-g选项,指导编译器添加debug 标志。
2.Executing the Program
正常运行程序即可,但是注意因为要收集数据,所以相比正常来说会运行的稍慢。
在程序退出之前,你的profiling数据会被写入文件gmon.out,如果已有同名文件,内容会被覆盖,暂时没有办法修改要写入的文件名,但是可以修改已有的明文gmon.out的文件的文件名。为了收集到数据,你必须正常退出,如果使用low-level的函数 _exit将无法收集到信息。
gmon.out是存在你的current working directory里面的,如果你调用了chdir,gmon.out会存在你最后chdir的目录里,如果你没有相关的写入权限,那就无法写入,你会得到错误提示。
3.gprof Command Summary
在你有了gmon.out文件之后,你可以运行gprof分析相关信息。gprof会输出一个flat profile,你可以把他的输出通过’>’输入到文件中,例如:
gprof options [executable-file [profile-data-files...]] [> outfile]
最简单的输出格式为(file information, execution count, and function and file ordering)
- GNU Profiling
- GNU Profiling
- GPROF Tutorial – How to use Linux GNU GCC Profiling Tool
- dynamic profiling
- GPU Profiling
- Java Profiling
- MySQL Profiling
- go profiling
- code profiling
- Performance & Profiling
- profiling tools
- GNU
- GNU
- GNU
- GNU
- GNU
- GNU
- GNU
- 聊下 git 多账户问题
- 循环
- Java8新特性——StreamAPI(一)
- 如何把Https网站中的安全证书导入到java中的cacerts证书库?
- UVa 10205
- GNU Profiling
- Smart Toast & Snackbar:简化调用,并提高性能和用户体验!
- Java8新特性——StreamAPI(二)
- 几个面试可能遇到的题目
- 合唱团
- 让Android WiFi支持中文
- 循环第八题
- 已知二叉树前序、后序遍历如何求中序
- fatal error: hdf5.h: No such file or directory