c++ - 无法使用 gprof 累积时间 - gnu 分析器

标签 c++ cygwin profiler gprof

我在 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/

相关文章:

c++ - 如何使用 C++11 语法对方法指针进行类型定义?

python - 使用 cygwin、dlltool 构建 64 位 libpython27.a

c# - C#/.NET 探查器应该具备哪些功能?

cygwin - 让 gvim 自动翻译 cygwin 路径

java - 内存分析器

apache-flex - Flash Builder 4 分析器 : how to spot what objects are causing a known memory increase?

c++ - 返回一个类型转换引用是否安全?

c++ - 快速像素访问 opencv

c++ - SDL,随机颜色发生器

c++ - 将 .exe 文件嵌入到 C++ 程序中?