简体   繁体   English

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

[英]unable to accumulate time using gprof - the gnu profiler

I am running cygwin on windows and using latest version of gprof for profiling my code. 我在Windows上运行cygwin,并使用最新版本的gprof来分析我的代码。 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 . 我的问题是平面配置文件对我的代码中的每个函数都显示了零秒,我什至尝试循环这些函数(尝试了for循环一百万次),但gprof无法随时积累。请帮助。 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. 如果您的总体目标是发现并消除性能问题,则可以考虑这样做。

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. 我怀疑这将表明实际上100%的CPU时间都花在了查找和字符串比较上,而几乎有0%的时间用于代码。 That's what happens when only the program counter is sampled. 当仅对程序计数器进行采样时,就会发生这种情况。

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. 如果对调用堆栈进行采样,则会看到调用find和string-compare的代码行将以等于它们所负责的时间的频率显示在堆栈上。

That's the glory of gprof . 那就是gprof的荣耀。

PS You could also figure this out by single-stepping the code at the disassembly level. PS您也可以通过在反汇编级别单步执行代码来解决此问题。

I'm having that problem from time to time. 我不时遇到这个问题。 Esp. Esp。 in heavily threaded code. 在重线程代码中。

You can use valgrind with the --callgrind option (tool) which will allow you to at least have a more detailed view of how much time per function call. 您可以将valgrind与--callgrind选项(工具)一起使用,这将使您至少更详细地了解每个函数调用的时间。 There's a kde tool as well to visualize the output (and eswp. callgraph) better called kcachegrind. 还有一个kde工具,可以更好地可视化输出(以及eswp.callgraph),称为kcachegrind。 Don't know if you can install that on cygwin though. 但是不知道是否可以在cygwin上安装它。

What version of gprof are you using? 您使用的是哪个版本的gprof? Some old versions have this exact bug. 一些旧版本具有此确切的错误。

Run gprof --version and tell us the results. 运行gprof --version并告诉我们结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM