gpt4 book ai didi

c++ - Gcov报告解读

转载 作者:行者123 更新时间:2023-11-28 07:09:39 25 4
gpt4 key购买 nike

我在收银员课上做代码覆盖,我的老师对报告的含义进行了非常简短的教学,我觉得这对我的软件工程技能的发展非常重要。因此,我需要您对以下 gcov 报告的解释提出建议。如果有任何有助于我理解 gcov 的链接或文章,我将不胜感激。

头文件

#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 */

执行文件

#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

gcov -b cashier.gnco

我得到了如下结果A

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

我输入以下命令

gcov -f cashier.gnco

我得到了如下结果B

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. 没有分支是什么意思?

  3. 4 是什么意思,它在 Calls executed:100.00% of 4 中有什么意义?为什么我的类中有 7 个函数,却有 4 个函数调用?

  4. 整个段落是什么意思?

    File '/usr/include/c++/4.4/bits/basic_string.h'
    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

我对结果 B 的问题

  1. 所有函数名称等:_ZN7cashier8settlesEi。几乎匹配收银员函数名称等:void settries(int)。我认为它指的是相同的功能,但我的老师却不这么认为。哪个是正确的?

  2. 函数 _ZN7cashier8settriesEiLines executed:100.00% of 3 中的 3 是什么意思?

最佳答案

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

  • gcov -b 查找分支。您的代码没有分支(没有 if 语句,没有循环),因此在这里使用 -b 选项有点没有意义。

  • gcov -f 给出每个函数的摘要。它省略了分支概率。

关于数字,有时 gcov 将左大括号和右大括号计为可执行语句,有时则不然。后面有点疼。查看 cashier.cpp.gcov 文件以查看哪些行被计算在内,哪些行没有。

关于诸如 _ZN7cashier8settriesEi 之类的名称:这是 cashier::settries(int) 的损坏名称。通过 c++filt 传递这些名称。

关于/usr/include/c++/4.4/bits/basic_string.h,忽略那些文件。它们不是您的,但会出现在 gcov 输出中。

关于c++ - Gcov报告解读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21212832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com