0

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?

fefe
  • 3,342
  • 2
  • 23
  • 45

1 Answers1

2

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.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • Thank you very much for your clarification. But unfortunately I'm developing an NDK library. I haven't found a work around yet. – fefe Aug 29 '12 at 15:10
  • @fefe: Isn't there a debugger you can run the code under? If you can interrupt it by Ctrl-C or whatever, that's all you need. – Mike Dunlavey Aug 29 '12 at 16:11
  • I tried that, and I believe it should be useful. But my debugger is having some problem now and cannot follow into (or stop at breakpoint inside) native code now. So the only thing I get is that my library is taking a lot of time, but not exactly where. But this is out of the scope of this question. – fefe Aug 29 '12 at 16:16
  • @fefe: It's not always easy to do. At one time I had to use a hardware in-circuit-emulator, and decipher hex memory. It wasn't easy, but there was no other way, and it did work. – Mike Dunlavey Aug 29 '12 at 19:24
  • How can I do better? The link is dead .. please fix the link. I need to know how I can do better. ;-) – wojciii Jul 03 '14 at 21:54
  • 1
    @wojciii: I edited the answer. It's probably more than you want to read or watch, but I've had to labor up-hill against the tide of opinion on this, which says "measure, measure" and "use a profiler". Those are just lecture-hall and blog-to-blog echoes. There are plenty of people who understand this - I'm just the most outspoken. For really serious performance tuning, the simple manual method is by far the most effective, and those links give the solid reasons why. – Mike Dunlavey Jul 04 '14 at 00:29