Can I profile every request ?
evktw-06 opened this issue · comments
evktw-06 commented
Hi !
I installed django-silk to use it for the profiler part.
It works really good using the decorators silk_profile
.
I want to know if there is a simple solution to profile every request automatically.
When I was reading the documentation, I thought that install the middleware and SILKY_PYTHON_PROFILER=True
was enough.
Maybe I missed something ?
Harith Javed Bakhrani commented
You can do so by creating a middleware that will apply the decorator on all views:
from silk.profiling.profiler import silk_profile
class SilkProfileAllViewsMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
return response
def process_view(self, request, view_func, view_args, view_kwargs):
return silk_profile()(view_func)(request, *view_args, **view_kwargs)
Don't forget to insert this middleware in your config file after the silk middleware