I have a python project where I execute the app as a module using the -m
flag. So something like:
python -m apps.validate -i input.mp4
Now, I want to profile it using the command line. So the inline examples suggest invoking cProfile itself a module. However, I cannot do something like:
python -m cProfile apps.validate -i input.mp4
However, this results in the error "No such file or directory". I cannot just go to the apps
directory and launch validate.py
due to relative imports.
Is there a way to profile a module on the command line?
cProfile
online documentation that says a-m
option was added tocProfile
in that version. This is in addition to the Python interpreter's own-m
option, This means that something likepython -m cProfile -m apps.validate -i input.mp4
ought to work (if you're using Python 3.7+). – Hermaphroditeprofile
(andcProfile
) and see how support for the new-m
option was added. It might even be possible to use that version of it with an earlier version of the Python interpreter (depending on what other changes were made). – Hermaphrodite