I\'m debugging an C application and I\'d like to know how much time it spends in a particular function.
I could change the source code and add some more code to do the m
I have a helper function in my ~/.gdbinit:
define timeme
set $last=clock()
n
set $timing=clock() - $last
if $timing>$arg0
printf "***long***\n"
end
printf "%d cycles, %f seconds\n", $timing, (float)$timing / 1000000
end
You may need to adjust the 1000000 depending on what your implementation of CLOCKS_PER_SEC is on your platform.
Usage is trivial; run the helper which will execute the next step and give timing information:
Breakpoint 2, install_new_payload_from_meta (snmp_meta=0x7eee81c0, pkt=0x0, entry=0x7d4f4e58) at /home/sgillibr/savvi-dc-snmp/recipies.c:187
(gdb) timeme 100000
***long***
580000 cycles, 0.580000 seconds
(gdb)
Obviously resolution may not be enough for some needs, although it does prove very useful.