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

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系列教程汇总

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值