I'm currently profiling a C++ application on Solaris using collect
and analyser
, but I only see the number of seconds spent in each functions.
How can I see the number of time each function was called ?
Is there any options I should add to the command line to enable counters? or should I use a different tool ?
The collect
command doesn't work that way - it samples the running executable to get the call stack data it collects.
You need to compile with -xpg
and use prof
or gprof
on the output data file produced.
Something like this dtrace script would also collect function call counts:
countfuncs.d:
pid$target:::entry
{
@[ probefunc ] = count();
}
Then run that:
dtrace -s countfuncs.d -c your_program ...
In my experience, counting the number of times a function is called doesn't really matter - it's how much time (CPU or wall-clock) is spent in any function that matters. If a function takes up 90% of your execution time, that's where you spend your effort optimizing performance, whether the function was called once or billions of times. If a function takes up 0.001% of execution time, you don't bother with it no matter how many times it gets called.