1

I am looking for a performance profiler in order to analyze my Python programs.

Requirements:

  • works on Windows (Windows 10 at least, Windows 7 would be nice).
  • can be commercial.
  • at least support sampling (statistical approach).
  • ideally support instrumentation (modification of code).
  • support for Python 2 and 3. If your tool supports only one version, please mention that, so I can look for another tool for the other version.
  • UI for dealing with all the data.
  • hierarchical display of where the time is spent.
  • focus ("zoom") into a method and rescale it to 100%.

If you know Jetbrains dotTrace for .NET code, then that's roughly what I'm looking for. If you don't know it, here's a small screenshot:

Screenhost of dotTrace in action

I have tried:

  • looking at this question, but it asks "where the interpreter spends the most time". I don't want information about the interpreter, I want information about my code. Also, my question is limited to Windows.

I don't want

  • timeit or similar things that I need to insert into my code manually.
  • live-trace is going into the right direction. I'm looking for something with more GUI.
2

I would suggest starting with pythons own cProfile module:

  1. No need to change your code in any way when profiling a program
  2. Comes with Python (so Free)!
  3. Works on Windows, (and most other platforms).
  4. Python 2 & 3

To profile your python program:

python -m cProfile -o output_file_name YouProgram.py

then put your program through its paces, (obviously you can add any required parameters at the end of the above line). This saves the profile information to the specified filename.

You can then examine the statistics using the pstats module - this lets you examine the statistics in a python session. Alternatively you can use SnakeViz to view it in a browser or RunSnakeRun profile viewer GUI to view it more comfortably - the latter runs on python 3.x but should display profiles from python 2 runs with no problem.

RunSnakeRun

  • That looks good. I'll try it when I'm back in the company on Monday. – Thomas Weller Aug 24 '18 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.