I am currently profiling my code, which is C99 compliant, with gprof. My program is defined recursively. I am compiling using gcc with the -pg flag with some warnings enabled, and no optimisation flags. Then I am running the code followed by the command:
gprof ./myProgram > outputFile.txt
I am very confused as to what the output is telling me, though. It is saying that I am spending a lot of time in a function that I know for a fact I do not spend a lot of time in. The function in question has a loop inside and performs a task a set number of times. This is a tiny task, though, and by increasing the number of times the task is completed from, say, 5 to 100 I get no visible change in the total amount of time taken for my program to execute. However, gprof is telling me that I have spent almost 50% of the execution time in this function.
I have no idea what the issue is here. Has anyone encountered something like this before? Can I resolve this myself? I am using a CentOS distribution of Linux. I have tried to install OProfile as a different profiler, but don't have write access to /usr/local, so the make install fails, so not sure if this is only an issue with gprof
Here are the relevant parts of the output file. The weird output is for the function nl_jacobi_to_converge
:
From the flat profile I have
% cumulative self self total
time seconds seconds calls s/call s/call name
49.02 7.50 7.50 1562 0.00 0.01 calculate_resid_numeric_jac_diags_tc41
16.41 10.01 2.51 323878716 0.00 0.00 c
14.97 12.30 2.29 323878716 0.00 0.00 b
6.01 13.22 0.92 89 0.01 0.02 calculate_resid_tc41
5.69 14.09 0.87 10967082 0.00 0.00 rhs_function
1.11 14.26 0.17 1562 0.00 0.00 single_nl_jacobi
...
0.00 15.30 0.00 11 0.00 0.76 nl_jacobi_to_converge
And from the granularity I have
index % time self children called name
0.00 8.32 11/11 nl_multigrid [3]
[5] 54.4 0.00 8.32 11 nl_jacobi_to_converge [5]
5.28 2.92 1100/1562 calculate_resid_numeric_jac_diags_tc41 [4]
0.12 0.00 1100/1562 single_nl_jacobi [17]