Verified Commit c4664de4 authored by Georg Krause's avatar Georg Krause
Browse files

Add Middleware to trace memory usage

parent 6d42c833
......@@ -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
......
......@@ -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
......@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment