You can compile your programs with profiling support. for this, you just have to use the compiler switch -pg. The compiler wil insert the necessary stuff for profiling.
When you have done this, you can run your program uder the gnu profiler, gprof, as follows :
gprog yourexeWhere yourexe is the name of your executable.
You may want to capture the outpus of the profiler in a file, since it can be quite a lot, as follows:
gprog yourexe >gprof.out
For more information on the gnu profiler gprof, see its manual.