首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gcov报告解释

Gcov报告解释
EN

Stack Overflow用户
提问于 2014-01-19 02:43:37
回答 1查看 1.2K关注 0票数 0

我正在cashier课堂上做代码报道,我的老师对报告的意义做了非常简短的介绍,我觉得这对我的软件工程技能的发展非常重要。因此,我需要你对以下gcov报告的解释提出建议。我希望任何有助于我理解gcov的链接或文章。

头文件

代码语言:javascript
复制
#ifndef CASHIER_H
#define CASHIER_H
#include <string>
using namespace std;


class cashier 
{
public:

        void setID(string);
    string getID();

    void setPassword(string);
    string getPassword();

    void settries(int);
    int gettries();
        void increase_tries();

private:
    string ID;
    string Password;
    int tries;



};

#endif  /* CASHIER_H */

实现文件

代码语言:javascript
复制
#include "cashier.h"




void cashier::setID(string value)
{
    this->ID = value;
}

void cashier::setPassword(string value)
{

    this->Password = value;

}

string cashier::getID()
{
    return this->ID;
}

string cashier::getPassword()
{
    return this->Password;
}

void cashier::settries(int value)
{
    this->tries=value;
}
int cashier::gettries()
{
    return this->tries;
}
void cashier::increase_tries()
{
    this->tries = this->tries + 1 ;

}

我在命令提示符中键入以下命令,以便在类中使用gcov

代码语言:javascript
复制
gcov -b cashier.gnco

我得到了以下结果

代码语言:javascript
复制
File 'cashier.cpp'
Lines executed:100.00% of 18 //what does the 18 mean 
No branches                  //what does no branches mean
Calls executed:100.00% of 4   // what does 4 mean ??
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h' // Where did this come from ??
Lines executed:0.00% of 2
No branches
Calls executed:0.00% of 1
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov

我输入以下命令

代码语言:javascript
复制
gcov -f cashier.gnco

我得到了以下结果

代码语言:javascript
复制
Function '_ZN7cashier8settriesEi' // does this refer to the function :settries
Lines executed:100.00% of 3       // my teacher doesnt think so but i feel it refer
                                  //to it , who is correct??

Function '_ZN7cashier8gettriesEv'
Lines executed:100.00% of 2

Function '_ZN7cashier14increase_triesEv'
Lines executed:100.00% of 3

Function '_ZN7cashier11getPasswordEv'
Lines executed:100.00% of 2

Function '_ZN7cashier5getIDEv'
Lines executed:100.00% of 2

Function '_ZNSsaSERKSs'
Lines executed:0.00% of 2

Function '_ZN7cashier11setPasswordESs'
Lines executed:100.00% of 3

Function '_ZN7cashier5setIDESs'
Lines executed:100.00% of 3

File 'cashier.cpp'
Lines executed:100.00% of 18
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h'
Lines executed:0.00% of 2
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov'

为结果A问我的问题

  1. 18是什么意思及其在Lines executed:100.00% of 18中的意义
  2. no branches是什么意思?
  3. 4是什么意思?它在Calls executed:100.00% of 4中的意义是什么?当我在类中有7个函数时,为什么有4个函数调用?
  4. 整段是什么意思? 文件‘/usr/include/c++/4.4/bit/basic_string.h.h’行执行的2条分支中的0.00%:1 /usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov的0.00%

为结果B问我的问题

  1. 所有函数名称等:_ZN7cashier8settriesEi。几乎匹配收银员、函数、名称等:void settries(int)。我认为它指的是同样的功能,但我的老师却有不同的感觉。哪个是对的?
  2. 函数Lines executed:100.00% of 3中的3对_ZN7cashier8settriesEi意味着什么?
EN

回答 1

Stack Overflow用户

发布于 2014-01-19 03:48:54

读读手册页。在终端窗口中键入man gcov。还有,谷歌gcov。网上有说明。

  • gcov -b查找分支。您的代码没有分支(没有if语句,没有循环),所以在这里使用-b选项有点毫无意义。
  • gcov -f给出了每个函数的摘要。它省略了分支概率。

至于数字,有时gcov将打开和关闭大括号算作可执行语句,有时则不算,这有点让人头疼。查看cashier.cpp.gcov文件,看看哪些行计数,哪些行没有。

关于诸如_ZN7cashier8settriesEi这样的名称:这是cashier::settries(int)的错误名称。通过c++filt传递这些名字。

对于/usr/include/c++/4.4/bit/basic_string.h.h,忽略这些文件。它们不是您的,但是它们将出现在gcov输出中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21212832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档