I want to use valgrind to do some profiling, since it does not need re-build the program. (the program I want to profile is already build with “-g")
But valgrind(callgrind) is quite slow ... so here's what I to do:
I can do this kind of thing using sun studio on Solaris. (using dbx ). I just want to know is it possible to do the same thing using valgrind(callgrind)?
Thanks
To use Callgrind, you must specify --tool=callgrind on the Valgrind command line or use the supplied script callgrind . Callgrind's cache simulation is based on the Cachegrind tool of the Valgrind package.
Overview. Callgrind is a profiling tool that records the call history among functions in a program's run as a call-graph. By default, the collected data consists of the number of instructions executed, their relationship to source lines, the caller/callee relationship between functions, and the numbers of such calls.
Callgrind records the count of instructions, not the actual time spent in a function. If you have a program where the bottleneck is file I/O, the costs associated with reading and writing files won't show up in the profile, as those are not CPU-intensive tasks.
Ir: The number of instructions executed in total by the selected function after being called by this caller.
You should look at callgrind documentation, and read about callgrind_control.
valgrind --tool=callgrind --instr-atstart=no your_server.x
callgrind_control -i on
callgrind_control -i off
For profiling only some function you can also find useful CALLGRIND_START_INSTRUMENTATION
and CALLGRIND_STOP_INSTRUMENTATION
from <valgrind/callgrind.h>
header and using callgrind's --instr-atstart=no
option as suggested in Doomsday's answer.
You don't say what OS - I'm assuming Linux - in which case you might want to look at oprofile (free) or Zoom (not free, but you can get an evaluation licence), both of which are sampling profilers and can profile existing code without re-compilation. Zoom is much nicer and easier to use (it has a GUI and some nice additional features), but you probably already have oprofile on your system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With