Skip to content

Instantly share code, notes, and snippets.

@koolay
Created July 31, 2020 15:06
Show Gist options
  • Save koolay/7150a019fbe842e9e43ce672714ef36f to your computer and use it in GitHub Desktop.
Save koolay/7150a019fbe842e9e43ce672714ef36f to your computer and use it in GitHub Desktop.
profling gunicorn app
# pip3 install pyinstrument
import os
from pyinstrument import Profiler
PROFILER = bool(int(os.environ.get("PROFILING", 1)))
# from pyinstrument.renderers import JSONRenderer
def pre_request(worker, req):
if PROFILER:
worker.profiler = Profiler()
worker.profiler.start()
def post_request(worker, req, *args):
if PROFILER:
worker.profiler.stop()
# print(JSONRenderer().render(session=worker.profiler.last_session))
print(worker.profiler.output_text(unicode=True, color=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment