在 gunicorn 上 运行 时如何使用 python 的 cProfile 来分析 django 应用程序

How can I use python's cProfile to profile a django app while running on gunicorn

如何在 运行 上使用 python cProfile 在 gunicorn 上分析 Django 应用程序。

我可以在开发模式下分析: python -m cProfile -o sample.profile manage.py runserver

但是在使用 gunicorn 的生产服务器中 运行 我该怎么办?

你可以 运行 使用 gunicorn 这样。

$ DJANGO_SETTINGS_MODULE=myapp.settings python -m cProfile -o output_file ../env/bin/gunicorn --workers=8 --bind 127.0.0.1:8000 myapp.wsgi:application