Add Middleware to trace memory usage

environments/review-front-1108-r6wo61/deployments/6780
Georg Krause 2021-04-08 15:03:42 +02:00
rodzic 6d42c8337f
commit c4664de41f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: FD479B9A4D48E632
3 zmienionych plików z 20 dodań i 0 usunięć

Wyświetl plik

@ -13,6 +13,7 @@ BROWSABLE_API_ENABLED=True
FORWARDED_PROTO=http
LDAP_ENABLED=False
FUNKWHALE_SPA_HTML_ROOT=http://nginx/front/
PYTHONTRACEMALLOC=1
# Uncomment this if you're using traefik/https
# FORCE_HTTPS_URLS=True

Wyświetl plik

@ -104,4 +104,5 @@ if env.bool("WEAK_PASSWORDS", default=False):
MIDDLEWARE = (
"funkwhale_api.common.middleware.DevHttpsMiddleware",
"funkwhale_api.common.middleware.ProfilerMiddleware",
"funkwhale_api.common.middleware.PymallocMiddleware",
) + MIDDLEWARE

Wyświetl plik

@ -14,6 +14,7 @@ from django.middleware import csrf
from django.contrib import auth
from django import urls
from rest_framework import views
import tracemalloc
from funkwhale_api.federation import utils as federation_utils
@ -405,3 +406,20 @@ class ProfilerMiddleware:
response = http.HttpResponse("<pre>%s</pre>" % stream.getvalue())
return response
class PymallocMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if tracemalloc.is_tracing():
snapshot = tracemalloc.take_snapshot()
stats = snapshot.statistics("lineno")
print("Memory trace")
for stat in stats[:25]:
print(stat)
return self.get_response(request)