Sometimes code that you want to optimize is deep inside your application and you only want to focus callgrind on that snippet. There are two steps here. The first is to include the callgrind header file, which contains a few macros to enable programmatic start/stop of valgrind instrumentation.
#include <valgrind/callgrind.h>
/* Stuff */
CALLGRIND_START_INSTRUMENTATION;
do_something();
CALLGRIND_STOP_INSTRUMENTATION;
/* More Stuff */
The next step involves calling valgrind with instrumentation turned off by default.
$ valgrind --tool=callgrind --instr-atstart=no bin/my_exec
When you close your executable, you should have a callgrind.out with just the
results of the do_something() method, so you can focus your optimization
efforts there.