Profiling with cProfile
Cement apps can be profiled with cProfile very easily, however there are some considerations as it may not work "out of the box" as expected. This doc comes as the output of the following issue on Github:
The following assumes that your Cement project was created from the developer tools; cement generate project
. This is not necessary, however the use of myapp.main
assumes the Cement App, and main()
function live here. Modify to suit.
For your actual app, replace myapp
with your Python package name for your app.
References:
Profiling Commands
In order to profile specific commands within our app, we need to save cProfile to an output file. For basic example, we can run myapp --help
with cProfile with the following, which will save our profile to the file prof.dat
:
The output file should probably named appropriately based on what you are profiling. For example, if I need to profile command1
I will save that to it's own profile output file.
Inspecting a Profile
Now that we have our commands profiled, we can inspect that same as any other program. Here we are opening up the prof.dat
with pstats
:
You might want to sort by "cumulative time" (cumtime
) and then review the stats:
Last updated