user3092216
user3092216

Reputation: 63

c++ - profiling to get an overview of the called functions

I want to profile my program not for performance reason but to see the logic of the program. If function A calls B then C and D it would be something like:

A  -> B
   -> C -> E
        -> F
   -> D

Presently I use valgrind/callgrind. It is very usefull but does not respond precisely to my demand. We don't see all the different callstacks and we don't see in which order the functions are called. For instance if we have also F->G (but not in the context the stack A->C->F), we won't make this distinction, we only see the callers/callees. I am in the Unix environment. Thanks for your help,

Christophe

Upvotes: 2

Views: 278

Answers (1)

Mike Dunlavey
Mike Dunlavey

Reputation: 40689

I don't know of a good tool for this, other than stepping the code in a debugger. If you are using a good IDE like Visual Studio, there are probably function buttons for stepping over (F10), into (F11), and out (shift-F11) of function calls. If you are using a debugger like GDB, the commands are n, s, and fin.

You may find that this takes way more time than you have patience for. In that case, what I do is continue it (F5 in VS, c in GDB) and then pause it (Pause in VS, Ctl-C in GDB) and display the call stack to see where it is and why it is there. I do that several times. If I want to, I can step forward from that point for a while. That gives me a good idea of how the program is spending most of its time, and why.

I don't know of any other tool that will convey that kind of information, in a compiled language like C++. Interpreted languages may have a trace facility that traces all function calls, but as I said before, the volume may be overwhelming.

A profiler like gprof may be able to give you a call graph, which you might be able to combine with stepping to give you the time sequence. Be aware that it won't include any I/O, sleeps, or other system waits, but it might still be useful.

Upvotes: 1

Related Questions