Profiling Python Programs
The lsprofcalltree.py script (referenced in comments on this blog entry) provides output which can then be used by KCachegrind to visualize the most time-consuming functions in a program, presented using tree map, call graph and list views.
The script can be used to run a program as follows:
python lsprofcalltree.py -o output.log yourprogram.py args
Obviously, in the above, yourprogram.py is the program being profiled and args are the desired arguments to be supplied to the program, if any. If the -o option is omitted, a default output file will be chosen based on the name of the profiled program; here, output.log is the file which will contain the profiling results.
Visualising the Output
Once the program has terminated, the results of the profiling activity saved in the output file can be visualised using KCachegrind as follows: