无法使用 gprof(gnu 分析器)累积时间

2024-01-03

我在 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 上安装它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 gprof(gnu 分析器)累积时间 的相关文章

随机推荐