Add Middleware to trace memory usage
This commit is contained in:
parent
6d42c8337f
commit
c4664de41f
1
.env.dev
1
.env.dev
|
@ -13,6 +13,7 @@ BROWSABLE_API_ENABLED=True
|
||||||
FORWARDED_PROTO=http
|
FORWARDED_PROTO=http
|
||||||
LDAP_ENABLED=False
|
LDAP_ENABLED=False
|
||||||
FUNKWHALE_SPA_HTML_ROOT=http://nginx/front/
|
FUNKWHALE_SPA_HTML_ROOT=http://nginx/front/
|
||||||
|
PYTHONTRACEMALLOC=1
|
||||||
|
|
||||||
# Uncomment this if you're using traefik/https
|
# Uncomment this if you're using traefik/https
|
||||||
# FORCE_HTTPS_URLS=True
|
# FORCE_HTTPS_URLS=True
|
||||||
|
|
|
@ -104,4 +104,5 @@ if env.bool("WEAK_PASSWORDS", default=False):
|
||||||
MIDDLEWARE = (
|
MIDDLEWARE = (
|
||||||
"funkwhale_api.common.middleware.DevHttpsMiddleware",
|
"funkwhale_api.common.middleware.DevHttpsMiddleware",
|
||||||
"funkwhale_api.common.middleware.ProfilerMiddleware",
|
"funkwhale_api.common.middleware.ProfilerMiddleware",
|
||||||
|
"funkwhale_api.common.middleware.PymallocMiddleware",
|
||||||
) + MIDDLEWARE
|
) + MIDDLEWARE
|
||||||
|
|
|
@ -14,6 +14,7 @@ from django.middleware import csrf
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django import urls
|
from django import urls
|
||||||
from rest_framework import views
|
from rest_framework import views
|
||||||
|
import tracemalloc
|
||||||
|
|
||||||
from funkwhale_api.federation import utils as federation_utils
|
from funkwhale_api.federation import utils as federation_utils
|
||||||
|
|
||||||
|
@ -405,3 +406,20 @@ class ProfilerMiddleware:
|
||||||
response = http.HttpResponse("<pre>%s</pre>" % stream.getvalue())
|
response = http.HttpResponse("<pre>%s</pre>" % stream.getvalue())
|
||||||
|
|
||||||
return response
|
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)
|
||||||
|
|
Loading…
Reference in New Issue