小言_互联网的博客

【Linux】一步一步学Linux——gcov命令(257)

510人阅读  评论(0)

00. 目录

01. 命令概述

gcov命令是一款测试程序的代码覆盖率的工具。

02. 命令格式

用法:gcov [选项]... SOURCE|OBJ...

03. 常用选项

显示代码覆盖信息。

  -h, --help                      打印此帮助并退出
  -v, --version                    打印版本号并退出
  -a, --all-blocks                显示每个基本块的信息
  -b, --branch-probabilities      输出包含分支概率
  -c, --branch-counts             给出跳转的分支数,而不是百分比
  -n, --no-output                 不创建输出文件
  -l, --long-file-names           为包含进来的源文件使用长输出文件名
  -f, --function-summaries        输出每个函数的小结信息
  -o, --object-directory DIR|FILE 在 DIR 中搜索目标文件,或搜索名为 FILE 的目标文件
  -s, --source-prefix DIR         Source prefix to elide
  -r, --relative-only             Only show data for relative sources
  -p, --preserve-paths            保留所有路径名
  -u, --unconditional-branches    同时显示无条件跳转数
  -d, --display-progress          显示进度信息

04. 参考示例

4.1 显示代码覆盖信息

[deng@localhost 1gcc] gcc -fprofile-arcs -ftest-coverage test.c
[deng@localhost 1gcc] ls
test      test.c     test.gcno
[deng@localhost 1gcc]./test
[deng@localhost 1gcc] ls
test      test.c    test.gcda test.gcno
[deng@localhost 1gcc] gcov test.c
File 'test.c'
Lines executed:77.78% of 9
test.c:creating 'test.c.gcov'
[deng@localhost 1gcc] 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:}

05. 附录

参考:【Linux】一步一步学Linux系列教程汇总


转载:https://blog.csdn.net/dengjin20104042056/article/details/101222790
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场