无法使用gprof - gnu profiler累积时间 [英] unable to accumulate time using gprof - the gnu profiler

查看:264
本文介绍了无法使用gprof - gnu profiler累积时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上运行cygwin并使用最新版本的gprof来分析我的代码。我的问题是,扁平配置文件显示零秒为我的代码中的每个函数,我甚至尝试循环函数(尝试一个for循环一百万),但gprof无法累积任何时间。请帮助。这是我的一个示例函数。

I am running cygwin on windows and using latest version of gprof for profiling my code. My problem is that the flat profile shows zero sec for each of the functions in my code, I even tried to loop the functions(tried a for loop for a million) but gprof is unable to accumulate any time .Please help . Here is one of my sample function.

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;}
  }
} 


推荐答案

如果您的整体目标是找出并移除成效问题,您可以请考虑这一点。

If your overall goal is to find and remove performance problems, you might consider this.

我怀疑这将显示基本上100%的CPU时间是用于查找和字符串比较,为您的代码留下几乎0%。这是当只有程序计数器被采样时会发生什么。

I suspect it will show that essentially 100% of the CPU time is being spent in find and string-compare, leaving almost 0% for your code. That's what happens when only the program counter is sampled.

如果你对调用栈进行抽样,你会看到调用find和string-compare的代码行将是显示在堆栈上的频率等于他们负责的时间。

If you sample the call stack, you will see that the lines of code that invoke find and string-compare will be displayed on the stack with a frequency equal to the time they are responsible for.

这是 gprof

PS您也可以通过在反汇编级别单步执行代码来确定这一点。

P.S. You could also figure this out by single-stepping the code at the disassembly level.

这篇关于无法使用gprof - gnu profiler累积时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆