Would the time counted in gprof include what is spent in functions that are not profiled?

情到浓时终转凉″ 提交于 2020-01-01 19:52:11

问题


I now have a project which I want do profiling on, but it used another library which I have no control of. Say if there if such a function:

#include <library.h>
void function(...)
{
    // do something
    for (...)
    {
        // ...
        library_function(...);
        // ...
    }
    // do something
}

Let's assume that library_function is from another static library which is not compiled with profiling enabled. Now if gprof tells me running function took 10s including all its children, will this include the time spent in library_function?


回答1:


No, because the way gprof works, it samples the program counter, figures out which function the program counter is in, and increments the self time for that function.

In addition, it counts the number of times any function A calls any function B.

From that, it tries to figure everything else out.

Of course, this only works for functions it knows about.

It's very clever, but you can do better.

ADDED: since somebody in their wisdom decided to delete the above post, here is a brief summary of how you can do better:

Try this instead.
Here's an example of a 44x speedup.
Here's a 730x speedup.
Here's an explanation of the statistics.
Here's an answer to critiques.
Here's an 8-minute video demonstration.



来源:https://stackoverflow.com/questions/12145745/would-the-time-counted-in-gprof-include-what-is-spent-in-functions-that-are-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!