Created
July 31, 2020 15:06
-
-
Save koolay/7150a019fbe842e9e43ce672714ef36f to your computer and use it in GitHub Desktop.
profling gunicorn app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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