Would the time counted in gprof include what is sp

2019-04-17 14:57发布

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?

标签: gprof
1条回答
Melony?
2楼-- · 2019-04-17 15:33

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.

查看更多
登录 后发表回答