profiling icon indicating copy to clipboard operation
profiling copied to clipboard

Profil flask app

Open xlqian opened this issue 8 years ago • 5 comments

Hello, is there anyway that I can profile a flask app with profiling?

xlqian avatar Nov 30 '17 15:11 xlqian

There's nothing special to profile a Flask app if you can run the Web server by a Python file.

# run_server.py
from hello import app
if __name__ == '__main__':
    app.run(port=5000)
$ profiling live run_server.py

If you use flask run command, try -m option and -- delimiter:

$ FLASK_APP=hello.py profiling live -m flask run -- -h 0.0.0.0 -p 5555

sublee avatar Dec 02 '17 18:12 sublee

I was able to run the profiler but the output only shows click and werkzeug steps. Cant really see which endpoint/which model method calls are being the bottleneck.

command I used; profiling --dump=profiler/blah.prf -S -m flask run -- -h 0.0.0.0 -p 5000 --no-reload

sinanm89 avatar Oct 11 '19 18:10 sinanm89

@sinanm89 Would you try flask run with --without-threads?

sublee avatar Oct 11 '19 19:10 sublee

Hah! That worked. I actually have the post methods now. Thanks so much for your hard work and suggestions @sublee , I'd say you can close this issue.

reiterating the working command to profile a flask app for anyone else stumbling around;

$ profiling --dump=blah.prf -S -m flask run -- -h 0.0.0.0 -p 5000 --no-reload --without-threads

sinanm89 avatar Oct 15 '19 15:10 sinanm89

I'm running my app through uwsgi in a docker container, where do I run profiling?

simkessy avatar Apr 05 '20 23:04 simkessy