My C is critical. Some functions are called millions of times, so I would like to know how much time is spent on each function, giving me the following:
Total time: 100s forward(): 20s; align(): 15s; ... others: 1s.
Can a debugger perform such an analysis? I use Eclipse CDT on Ubuntu and use gdb for debugging. Some guy suggested Valgrind , but I did not find a suitable one. I found some questions about C # or php or perl profiling, any suggestions for C? Thanks.
=============================================
Followup: thanks for the help, gprof seems really nice. Here is the manual link: http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html .
Question about the interpretation of the resume:
Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls us/call us/call name 61.29 9.18 9.18 bwa_print_sam_SQ 21.96 12.47 3.29 bwt_sa 4.01 13.07 0.60 bns_coor_pac2real 3.87 13.65 0.58 bwt_match_exact_alt 2.60 14.04 0.39 bwa_read_seq 1.00 14.19 0.15 bwt_match_gap 0.80 14.45 0.12 seq_reverse
If I'm not mistaken, he says that the bwa_print_sam_SQ function takes up 61.29% of the total time. But my program runs for 96.24 seconds, this function should work for about 60 seconds. Why is the โcumulativeโ second column only 9.18? The manual says:
cumulative seconds This is the cumulative total number of seconds the computer spent executing this functions, plus the time spent in all the functions above this one in this table.
And I use the parameter
"gprof -f pe_sai2sam_se_core -f bwa_print_sam_SQ -f seq_reverse ./peta > gprof",
where the pe_sai2sam_se_core function calls bwa_print_sam_SQ in a long time loop. Why does the report say:
index % time self children called name <spontaneous> [1] 61.3 9.18 0.00 bwa_print_sam_SQ [1] ----------------------------------------------- <spontaneous> [8] 0.8 0.12 0.00 seq_reverse [8] -----------------------------------------------
He did not say anything about pe_sai2sam_se_core ... Why?