posted Fri 27 Apr 2012 by Michael Galloy under
HPC
I had to do a lot of line profiling (with the `-l` option to [gprof]) of some Fortran code recently and got tired of tracking through source code to find the lines that where causing problems. The line profiler gives very useful [output][gprof output] that looks like (edited to remove some extra space):
percent cumulative self
time seconds seconds name
18.20 0.02 0.02 main (cuda-blas.cu:94 @ 401502)
9.10 0.03 0.01 main (cuda-blas.cu:93 @ 4014c9)
9.10 0.04 0.01 main (cuda-blas.cu:166 @ 4018c0)
9.10 0.05 0.01 main (cuda-blas.cu:239 @ 401c3d)
9.10 0.06 0.01 main (cuda-blas.cu:243 @ 401c91)
9.10 0.07 0.01 main (cuda-blas.cu:318 @ 402039)
9.10 0.08 0.01 main (cuda-blas.cu:319 @ 402060)
9.10 0.09 0.01 main (cuda-blas.cu:322 @ 4020a1)
9.10 0.10 0.01 main (cuda-blas.cu:321 @ 4020f0)
I wrote an IDL routine that takes the raw profile output along with the source code and creates [HTML output][cuda-blas profile] that color codes the lines with high activity, like the following:

Get the code from my IDL library, available via Subversion:
svn co http://svn.idldev.com/idllib/trunk idllib
The `mg_clineprofile.pro` file is in the `src/profiling` directory. Call `MG_CLINEPROFILE` like:
IDL> mg_clineprofile, 'profile-output.txt', /all_files
The `ALL_FILES` keyword indicates you want output for each file listed in the profile output; you can also specify the files that you want output for via the `FILES` keyword.
The code is currently pretty ugly; expect changes to it coming up.
[gprof]: http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html#SEC1 "gprof description"
[gprof output]: http://michaelgalloy.com/wp-content/uploads/2012/04/cuda-blas.lineprofile.txt "gprof output"
[cuda-blas profile]: http://michaelgalloy.com/wp-content/uploads/2012/04/cuda-blas.cu.html "cuda-blas profile"
[line-profiling]: http://michaelgalloy.com/wp-content/uploads/2012/04/line-profiling.png "Line profiling output"