4

I am trying to profile a reasonably sized python project using cprofile.

I am usually invoking my python app as a module something like:

python -m cabon.apps.detector -i input_image.png

Now howo can I use cprofile from the command line. I see that the cProfile itself is invoked as a module with -m and how can this be combined with my python app which is also invoked as a module?

plr108
  • 1,201
  • 11
  • 16
Luca
  • 10,458
  • 24
  • 107
  • 234

1 Answers1

4

The files cProfile and profile can also be invoked as a script to profile another script. For example:

python -m cProfile [-o output_file] [-s sort_order] (-m module | myscript.py)

As mentioned in the documentation, we can specify that a module is being profiled by using additional -m. First for the cProfile and then the actual module:

python -m cProfile -m cabon.apps.detector -i input_image.png
AKS
  • 18,983
  • 3
  • 43
  • 54
  • Ahhhh damn. I had tried this but mistakenly put the `-m` immediately after the `-s` instead of after the parameter. Thanks! – Luca Jul 08 '21 at 16:03