In order to profile your executable, compile and link the code with -g and -pg options. Note that you have to use these flags for linking as well.
Once you create an executable file, just run it as you normally would. It will create a gmon.out file. Then run 'gprof
If your executable file forks a new process that you want to profile as well; or your executable file is an MPI program, you soon will realize that you only get one gmon.out file when you run your program. gmon.out that is produced by the final process overwrites the old one. You must use an environment variable called GMON_OUT_PREFIX for a get around. Set it to 'gmon.out-'`/bin/uname -n`. For bash, add this line to your .bashrc file:
export GMON_OUT_PREFIX='gmon.out-'`/bin/uname -n`
This way, every process will create its own gmon.out version, i.e. a file that starts with gmon.out followed by the machine name and pid (process id).
What if you want to profile a shared library? Again, compile and link the shared library with -g and -pg options. Then, set LD_PROFILE environment variable to the name of the shared library you want to profile. Finally, run the executable which uses this shared library. Upon completion, a file named
I also read that you can use LD_PROFILE_OUTPUT to specify a directory other then /var/tmp, but I haven't used this myself.
You might ask how one can profile multiple shared libraries. I really don't know an easy answer.
P.S. The information provided above is valid for gnu tools. I haven't tried any of the information above on any other tool.
No comments:
Post a Comment