我在 Windows 上运行 cygwin 并使用最新版本的 gprof 来分析我的代码。我的问题是,对于我的代码中的每个函数,平面配置文件显示零秒,我什至尝试循环函数(尝试了一个 for 循环一百万)但是 gprof 无法累积任何时间。请帮助。这是我的示例函数之一。
bool is_adjacent(const char* a ,const char* b)
{
for(long long iter=0;iter<=1000000;iter++){
string line1="qwertyuiop";
string line2="asdfghjkl";
string line3="zxcvbnm";
string line4="1234567890";
int pos=line1.find(*a);
if(pos!=string::npos){
if ((line1[pos++]==*b)||((pos!=0)&&(line1[pos--]==*b)))
return true;
else return false;}
pos=line2.find(*a);
if(pos!=string::npos){
if ((line2[pos++]==*b)||((pos!=0)&&(line2[pos--]==*b)))
return true;
else return false;}
pos=line3.find(*a);
if(pos!=string::npos){
if ((line3[pos++]==*b)||((pos!=0)&&(line3[pos--]==*b)))
return true;
else return false;}
pos=line4.find(*a);
if(pos!=string::npos){
if ((line4[pos++]==*b)||((pos!=0)&&(line4[pos--]==*b)))
return true;
else return false;}
}
}
最佳答案
我时常遇到这个问题。特别是在重线程代码中。
您可以将 valgrind 与 --callgrind 选项(工具)一起使用,这将使您至少可以更详细地了解每个函数调用的时间。还有一个 kde 工具可以可视化输出(和 eswp.callgraph)更好地称为 kcachegrind。不知道你是否可以在 cygwin 上安装它。
关于c++ - 无法使用 gprof 累积时间 - gnu 分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1287728/