This is a query profiler for Django applications, for helping developers answer the question "My Django code/page/API is slow, How do I find out why?"
Below are some of the features of the profiler:
This is the repo for the chrome plugin
This works with any version of django >= 2.0, and running on python >= 3.6
This image shows how the chrome plugin would display profiled data, once it is configured & installed
See this file in the PR to see how to use the context manager, and how easy it is to find performance issues :-)
The output of Django query profiler is same for the command line or the chrome plugin. In fact, chrome plugin displays the output set by the middleware - which is just a plain wrapper around context manager.
The simplest way to getting started is to install the django query profiler from pip, and get the chrome plugin from chrome web store.
pip install django-query-profiler
Download from chrome webstore
This is covered in detail in the installation section in the docs
This configuration is when we want to use the profiler along with the chrome plugin. If we want to just use it on the command line, the configuration is much more simpler (two lines of change to settings.py file) - that is covered in the docs
from django_query_profiler.settings import * INSTALLED_APPS = ( ... 'django_query_profiler', ... ) MIDDLEWARE = ( ... # Request and all middleware that come after our middleware, would be profiled 'django_query_profiler.client.middleware.QueryProfilerMiddleware', ... ) DATABASES = ( ... # Adding django_query_profiler as a prefix to your ENGINE setting # Assuming old ENGINE was "django.db.backends.sqlite3", this would be the new one "ENGINE": "django_query_profiler.django.db.backends.sqlite3", )
# Add this line to existing urls.py path('django_query_profiler/', include('django_query_profiler.client.urls'))
See this PR on how to configure this in your application, and how the plugin is going to look like after your configuration
This is covered in detail in the configuration instructions section in the docs
This is also covered in detail in the documentation at how the profiler works section in the docs, along with how the code is organized.
The docs also contain references to various links which helped us to lear about internals of Django, and to various projects which helped us to learn on how to add hooks when Django executes a query
We have two levels of profiler, and each of them have a different overhead. The two levels are:
On an average, QUERY_SIGNATURE level adds an overhead of 1 millisecond per 7 queries, and QUERY_SIGNATURE adds an overhead of 1 millisecond per 25 queries.
It is simple to change the profiler level for all the requests, or can be configured per request. This is covered in the choosing profiler level section of the docs
We have tried to make the profiler customizable by providing hooks at various points. Some of the use cases are covered here in the customizing the defaults section in docs.
We plan to add more hooks for customizing the profiler as we gather more feedback from real world use cases.
The django query profiler is released under the BSD license, like Django itself.
If you like it, please consider contributing! The docs cover everything from how to setup locally, to how the code is organized to running tests.
Full documentation is available at readthedocs