本文介绍了令人困惑的gprof输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据time(),我在使用16.637s的C ++程序上运行gprof,这是我在第一行输出中得到的:

I ran gprof on a C++ program that took 16.637s, according to time(), and I got this for the first line of output:

%   cumulative   self              self     total
time   seconds   seconds    calls   s/call   s/call  name
31.07      0.32     0.32  5498021     0.00     0.00  [whatever]

为什么只用了.32秒就列出了31.07%时间?这是每个通话时间吗? (那不是自我吗?)

Why does it list 31.07% of time if it only took .32 seconds? Is this a per-call time? (Wouldn't that be self s/call?)

这是我第一次使用gprof,请好心:)

This is my first time using gprof, so please be kind :)

通过向下滚动,看来gprof仅认为我的程序需要1.03秒.为什么会这么错呢?

by scrolling down, it appears that gprof only thinks my program takes 1.03 seconds. Why might it be getting it so wrong?

推荐答案

瓶颈在文件I/O中(请参阅).我切换到在缓冲区中读取整个文件,并且极大地加快了速度.

The bottleneck turned out to be in file I/O (see Is std::ifstream significantly slower than FILE?). I switched to reading the entire file in a buffer and it sped up enormously.

这里的问题是,在等待文件I/O时,gprof似乎无法生成准确的配置文件(请参见 http://www.regatta.cs.msu.su/doc/usr/share/man/info/ru_RU/a_doc_lib/cmds/aixcmds2/gprof.htm ).实际上,seekgtellg甚至不在分析列表中,它们是瓶颈!

The problem here was that gprof doesn't appear to generate accurate profiling when waiting for file I/O (see http://www.regatta.cs.msu.su/doc/usr/share/man/info/ru_RU/a_doc_lib/cmds/aixcmds2/gprof.htm). In fact, seekg and tellg were not even on the profiling list, and they were the bottleneck!

这篇关于令人困惑的gprof输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 11:22