Revision 1 as of 2009-11-13 12:45:28

Clear message

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:

kcachegrind output.log

Unable to edit the page? See the FrontPage for instructions.