Profiling Python Programs

The 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 -o output.log args

Obviously, in the above, 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


PythonSpeed/Profiling (last edited 2010-01-29 22:41:19 by PaulBoddie)

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