Ajout d'un outil de profiling
This commit is contained in:
parent
5a2dea6989
commit
ed7944aaa9
33
src/scripts/profiling.py
Normal file
33
src/scripts/profiling.py
Normal file
@ -0,0 +1,33 @@
|
||||
from django.test import RequestFactory
|
||||
import django.urls
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.http import HttpRequest
|
||||
import cProfile
|
||||
|
||||
# inspiré de https://enix.io/fr/blog/django-performance-profiler/
|
||||
|
||||
# La fameuse requête, séparée en URI et Query String.
|
||||
uri = "/"
|
||||
qstring = "?tags=🎵 concert"
|
||||
|
||||
# On construit un objet "request" ..."
|
||||
request_factory = RequestFactory()
|
||||
request = request_factory.get(uri + qstring)
|
||||
request.user = AnonymousUser
|
||||
|
||||
# Puis on fait appel au routeur de Django pour trouver
|
||||
# la vue censée traiter la requête ...
|
||||
resolvermatch = django.urls.resolve(uri)
|
||||
|
||||
resolvermatch.func(request, *resolvermatch.args, **resolvermatch.kwargs)
|
||||
|
||||
cProfile.runctx(
|
||||
"for i in range(10): resolvermatch.func(request, *resolvermatch.args, **resolvermatch.kwargs)",
|
||||
None,
|
||||
locals(),
|
||||
sort="tottime",
|
||||
filename='logs'
|
||||
)
|
||||
|
||||
# puis visualiser avec
|
||||
# snakeviz src/logs
|
Loading…
Reference in New Issue
Block a user