Here is a whitepaper about the detection of bugs and bottlenecks in C/C++ source codes under Linux. The whitepaper will show you how to use Valgrind and gprof.
Valgrind is a set of debugging and profiling tools including Memcheck (memory error detector), Cachegrind (a cache and branch-prediction profiler), Callgrind (a call-graph generating cache and branch prediction profiler) Helgrind and DRD/ (thread error detectors), Massif (a heap profiler).
gprof is the GNU profiler (see here for more details) and it provides the same kind of information than Callgrind, but faster.
You can download the whitepaper here (left-click to grab the file):