Here is what I got from the profile data. I can't understand why calls of main is more than once?
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 96 0.00 0.00 fun
0.00 0.00 0.00 33 0.00 0.00 __x86.get_pc_thunk.bx
0.00 0.00 0.00 27 0.00 0.00 main
What is more strange,my code is like that
void foo() {
foo1();
if ( a condition) foo2();
}
% cumulative self self total
time seconds seconds calls us/call us/call name
54.55 0.06 0.06 6115 9.81 9.81 foo1
18.18 0.08 0.02 252520 0.08 0.08 cmp_by_weight
9.09 0.09 0.01 865699 0.01 0.01 foo2
Why could the calls of foo2() is more than that of foo1()?
I have use -pg option when compile. and then use gprof -a exe gmon.out to generate profile from gmon.out.
Calls: is the total number of times the function was called. If the function was never called, or the number of times it was called cannot be determined (probably because the function was not compiled with profiling enabled), the calls field is blank.