Profiling python flask apps


Python provides a couple standard profilers. They can be used to determine how often and for how long various parts of the program executed, which is particularly useful if you are debugging a flask app. The Werkzeug library provides a middleware that profiles each request with the cProfile module.


app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir="profiles")

Which will produce a file per request in the profiles directory.

There are a few tools around to visualize the profiles. e.g snakeviz.

pip install snakeviz
snakeviz profiles/