GCOV简易使用
2015-11-01 14:49
507 查看
在工作中如果涉及到代码的覆盖率,那么gcov是很好的选择,同时可以配合lcov和gcov。下面就对这个星期使用的gcov做个小小的总结
You can use gcov as a profiling tool to help discover where your optimization efforts will best affect your code. You can also use gcov along with the other profiling tool, gprof, to assess which parts of your code use the greatest amount of computing time.
When using gcov, you must first compile your program with two special GCC options: ‘-fprofile-arcs -ftest-coverage’.
This tells the compiler to generate additional information needed by gcov (basically a flow graph of the program) and also includes additional code in the object files for generating the extra profiling information needed by gcov. These additional files are placed in the directory where the object file is located.
编译时加上-fprofile-arcs -ftest-coverage选项,这样编译后结果会生成***.gcno文件。之后,运行生成的可执行文件,会生成***.gcda文件。最后通过gcov命令,会生成***.c.gcov(可执行程序执行过程中调用的所有文件,会生成相应的gcov),其中包括覆盖率的详细信息。
The .gcno notes file is generated when the source file is compiled with the GCC -ftest-coverage option. It contains information to reconstruct the basic block graphs and assign source line numbers to blocks.
The .gcda count data file is generated when a program containing object files built with the GCC -fprofile-arcs option is executed. A separate .gcda file is created for each object file compiled with this option. It contains arc transition counts, value profile counts, and some summary information.
通过test.c.gcov就可以查看详细的命中率情况了
GCOV概述
gcov is a test coverage program. Use it in concert with GCC to analyze your programs to help create more efficient, faster running code and to discover untested parts of your program.You can use gcov as a profiling tool to help discover where your optimization efforts will best affect your code. You can also use gcov along with the other profiling tool, gprof, to assess which parts of your code use the greatest amount of computing time.
GCOV使用
编译When using gcov, you must first compile your program with two special GCC options: ‘-fprofile-arcs -ftest-coverage’.
This tells the compiler to generate additional information needed by gcov (basically a flow graph of the program) and also includes additional code in the object files for generating the extra profiling information needed by gcov. These additional files are placed in the directory where the object file is located.
编译时加上-fprofile-arcs -ftest-coverage选项,这样编译后结果会生成***.gcno文件。之后,运行生成的可执行文件,会生成***.gcda文件。最后通过gcov命令,会生成***.c.gcov(可执行程序执行过程中调用的所有文件,会生成相应的gcov),其中包括覆盖率的详细信息。
The .gcno notes file is generated when the source file is compiled with the GCC -ftest-coverage option. It contains information to reconstruct the basic block graphs and assign source line numbers to blocks.
The .gcda count data file is generated when a program containing object files built with the GCC -fprofile-arcs option is executed. A separate .gcda file is created for each object file compiled with this option. It contains arc transition counts, value profile counts, and some summary information.
tingshuai@yantingshuaideMacBook-Air ~/project/gcov-test$ gcc -fprofile-arcs -ftest-coverage test.c tingshuaideMacBook-Air ~/project/gcov-test$ ls test test.c test.gcno tingshuai@yantingshuaideMacBook-Air ~/project/gcov-test$ ./test tingshuaideMacBook-Air ~/project/gcov-test$ ls test test.c test.gcda test.gcno tingshuai@yantingshuaideMacBook-Air ~/project/gcov-test$ gcov test.c File 'test.c' Lines executed:77.78% of 9 test.c:creating 'test.c.gcov' tingshuai@yantingshuaideMacBook-Air ~/project/gcov-t 4000 est$ cat test.c.gcov -: 0:Source:test.c -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include<stdio.h> -: 2: -: 3:int main(int argc, char *argv[]) -: 4:{ 1: 5: int i = 0; 202: 6: for (i = 0; i < 100; i++) { 100: 7: printf("add i atomic"); 100: 8: } -: 9: 1: 10: if (i > 200) { #####: 11: printf("i is bigger than 200"); #####: 12: } else { 1: 13: printf("is is less then 200"); -: 14: } 1: 15: return 0; -: 16:}
通过test.c.gcov就可以查看详细的命中率情况了
相关文章推荐
- Linux socket 初步
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- 基于 Linux 集群环境上 GPFS 的问题诊断
- 谁是桌面王者?Win PK Linux三大镇山之宝
- vivi下重新调整分区