# Profiling Django views with Scooby profiler

DevFeed: [Profiling Django views with Scooby profiler](<https://devfeed.tech/articles/profiling-django-views-with-scooby-profiler-20012.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2018/09/20/profiling-django-views-with-scooby/>)

Published: 2018-09-20T00:00:00Z

Content type: article

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [Django](<https://devfeed.tech/topics/django.md>), [debug](<https://devfeed.tech/topics/debug.md>), [Chrome extension](<https://devfeed.tech/topics/chrome-extension.md>), [Redis](<https://devfeed.tech/topics/redis.md>), [Ajax](<https://devfeed.tech/topics/ajax.md>), [npm](<https://devfeed.tech/topics/npm.md>), [Python](<https://devfeed.tech/topics/python.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [HTTP](<https://devfeed.tech/topics/http.md>)

Tags: [backend](<https://devfeed.tech/tags/backend.md>), [chrome](<https://devfeed.tech/tags/chrome.md>), [chrome-extension](<https://devfeed.tech/tags/chrome-extension.md>), [debug](<https://devfeed.tech/tags/debug.md>), [django](<https://devfeed.tech/tags/django.md>), [front-end](<https://devfeed.tech/tags/front-end.md>), [http](<https://devfeed.tech/tags/http.md>), [npm](<https://devfeed.tech/tags/npm.md>), [profiling](<https://devfeed.tech/tags/profiling.md>), [python](<https://devfeed.tech/tags/python.md>), [redis](<https://devfeed.tech/tags/redis.md>), [web](<https://devfeed.tech/tags/web.md>)

## AI overview

This article introduces Scooby, a Django and Python profiling package designed to inspect SQL and other plugin statistics for AJAX requests. It stores profiling data temporarily in Redis and exposes the results through a Chrome extension, avoiding the performance costs of injecting statistics into rendered HTML.

## Source excerpt

Earlier in 2016, I came up with the idea of creating a Python module which could provide functionality of profiling functions w.r.t. SQL queries and tell exactly at what lines of function, the queries were happening. I called that package Goofy and created it with the engineering of Python AST manipulation. You can read the post on it here later. It helped us profiling views serving AJAX requests but it had some limitations too. E.g. we couldn't see the whole callstack trace of the queries and couldn't analyze the queries. In an internal hackathon @HackerEarth which happened in Nov 2017, I revisited this problem and tried to come up with a profiler, through which we could see the stats on front-end and which should be much lightweight and would work with AJAX requests. I named this package Scooby. Idea We have been using the package django-debug-toolbar, but it wasn't enough because it didn't have the functionality of profiling AJAX requests. And because of the size of our codebase, it had made serving web pages slower in develop mode because it injects the stats in HTML by rendering and rendering takes time. So we needed an alternative. The idea while creating the Scooby package was to have a similar type of package as of django-debug-toolbar but instead of rendering the stats to HTML, we can dump the stats data to some backend store e.g. Redis where it will reside temporarily. And show the stats on front-end using a chrome extension. Implementation We had to create a Python/Django package for backend and a npm package for front-end which would build the chrome-extension. We took the decision of using ReactJS as rendering framework for the chrome-extension. In backend, we just had to create and put a new middleware which will do the job of collecting profiled stats for different plugins (E.g. SQL, Memcache etc.) and put the stats to Redis against some UUID as key. We would put that key as value of a custom header (X-Scooby) in HTTP response, so that chrome-extensio