解释类对象的Gcov报告
Interpret Gcov report for class objects
我正在cashier
课上做代码覆盖,我的老师就报告的含义进行了非常简短的教学,我认为这对我的软件工程技能的发展非常重要,因此我需要您对以下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
我得到了以下结果
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)no branches
是什么意思
3)4的含义及其在Calls executed:100.00% of 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) 所有函数名称etc::'_ZN7cashier8settriesEi'几乎与出纳函数名称etc:void settries(int)匹配,我认为它指的是同一个函数,但我的老师不这么认为,谁是对的??
2)Lines executed:100.00% of 3
中的3对函数"_ZN7cashier8settriesEi"意味着什么
结果A:
- 程序启动后执行了18行代码(与出纳.cpp相关)
- 您的代码没有任何条件
- 从4个仪器中执行4行(与出纳有关。h)
- std::string的一些行成为覆盖范围的一部分。您应该从覆盖率报告中排除std::string(gcov-e)
结果B:
- 是
- 从3个仪器中执行了3行
p.S。如果你对gcov感兴趣,你可以安装lcov——它是gcov报表上的gui表示。
像_ZN7cashier8settriesEi
这样的名称是损坏的名称,在这种情况下,它们肯定指的是像cashier::settries()
这样的函数。
Lines executed
只是源文件中在程序运行期间经过的行数。您应该查看详细的结果(参见示例),以检查哪些是实际的可执行和执行行。
No branches
意味着代码中没有像if
语句那样的决策点。
Calls executed
是该文件中的函数对该文件的函数的调用。
void cashier::setID(string value)
{
this->ID = value; // call to string::operator=()
}
void cashier::setPassword(string value)
{
this->Password = value; // call to string::operator=()
}
string cashier::getID()
{
return this->ID; // call to copy-constructor of string
}
string cashier::getPassword()
{
return this->Password; // call to copy-constructor of string
}
这四个方法正在调用std::string
的方法,尽管它不是显式编写的。(请参阅我对上面代码的评论。)其他三个方法处理基本类型int
的变量,这不需要函数调用。
- Android NDK传感器向事件队列报告奇怪的间隔
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- 使用std::source_location报告错误的最佳实践
- xmake总是报告:错误:无法获取cxx的程序,为什么
- 当用户超过按钮点击限制时报告
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么cudaMemGetInfo报告设备内存总量的变化
- 为什么瓦尔格林德在不释放恶意内存后没有报告任何问题?
- 内存清理程序报告全局对象构造中未初始化值的使用
- QDataStream 读取和写入的字节数比 QFile::length() 报告要多
- 在 Linux 中使用 ioctl() 获取隐藏功能报告时,零字节消失
- Valgrind 在 std::string::swap 中报告 SIGILL
- 使用 CXX 社区插件在 Sonarqube-5.6.6(LTS) 中导入 Gcov 报告
- Gcov 报告返回语句未命中
- 神秘功能出现在我的gcov报告中
- Gcov报告解读
- 解释类对象的Gcov报告
- 为什么gcov报告类内函数定义为不可执行的?
- gcov报告的析构函数中的分支是什么?
- 核心转储和gcov覆盖报告