I am using Google CPU Profiling tool.
http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html
On the documentation it is given
Analyzing Text Output
Text mode has lines of output that look like this:
14 2.1% 17.2% 58 8.7% std::_Rb_tree::find
Here is how to interpret the columns:
- Number of profiling samples in this
function - Percentage of profiling
samples in this function - Percentage
of profiling samples in the functions
printed so far - Number of profiling
samples in this function and its
callees - Percentage of profiling
samples in this function and its
callees - Function name
But I am not able to understand which columns tell me exact or percentage CPU usages of function ?
How to get CPU uses of a function suing google profile ?
It will have a lot of lines, for example, collect profile:
The program
a.outis the same as here: Kcachegrind/callgrind is inaccurate for dispatcher functions?Then analyze it with pprof
topcommand:So, what is here: the total sample count is 185; and the Frequency is the default (1 sample every 10 ms; or 100 samples per second). Then total runtime is ~ 1.85 second.
First column is the number of samples, which was taken when a.out works in the given function. If we divide it by Frequency, we will get total time estimation of given function, e.g.
do_4runs for ~0.8 secSecond column is the sample count in given function divided by total count, or the percentage of this function in total program run time. So
do_4is the slowest function (41% of total program time) anddo_1is only 11% of program runtime. I think you are interested in this column.Third column is the sum of current and preceding lines; so we can know that 2 slowest functions,
do_4anddo_3totally accounted for 68% of total run time (41%+27%)4rd and 5th columns are like first and second; but these one will account not only samples of the given function itself, but also samples of all functions called from given, both directly and indirectly. You can see, that
mainand all called from it is 100% of total run time (becausemainis the program itself; or root of calltree of program) andlast2with its children is 36.8% of runtime (its children in my program are: half of calls todo_4and half of calls todo_3= 41.1 + 27.6 /2 = 69.7/2 ~= 34% + some time in the function itself)PS: there are some other useful pprof commands, like
callgrindorgvwhich shows graphic representation of call tree with profiling information added.