Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I profile every request ? #649

Open
evktw-06 opened this issue Mar 10, 2023 · 1 comment
Open

Can I profile every request ? #649

evktw-06 opened this issue Mar 10, 2023 · 1 comment

Comments

@evktw-06
Copy link

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 ?

@HarithJ
Copy link

HarithJ commented Mar 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants