I don't use Python any more and have never profiled it, but there seems to be good options:
https://docs.python.org/2/library/profile.html
There are reasons to do what you're doing, e.g. Stack Exchange have a mini-profiler to watch production, but to identify problems in a development environment, profilers are usually quicker/easier once you've learnt to use them. It also helps you identify problems you didn't even know about.
- The slowdown is difficult to predict and somewhat unstable; never compare timings from runs with/without cProfile
- It's a deterministic, wall-clock profiler
- pyprof2calltree & kcachegrind.
- Loading a profile file = arbitrary code execution. Don't ever load a profile file you did not generate yourself.
[edit] Anyone reading this: Do not discard cProfile like I did. It just let me shave 900 ms off the startup time of my file manager (mentioned in a child comment). Wow!
[1]: https://fman.io
This was on the front page today, but flagged as a dupe, also an interesting read as it explains about flame graphs too:
It's on PyPI as well:
The code is a grand 42 lines. But once you've had to do it a few times it becomes so tedious to code up from scratch that it's much nicer to have a ready-made solution.[1]: https://github.com/mherrmann/timer-cm