Skip to content

Commit

Permalink
Add debug toolbar config and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyMay committed Nov 21, 2024
1 parent 3a9045f commit 7319c84
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 44 deletions.
2 changes: 2 additions & 0 deletions Dockerfile-django-dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ RUN pip install pip-tools

COPY ./requirements.txt .
RUN pip-sync requirements.txt
# IMPORTANT: Also update version in Dockerfile-grader-dev
RUN pip install django-debug-toolbar==3.5.0

WORKDIR /usr/src/app

Expand Down
1 change: 1 addition & 0 deletions Dockerfile-grader-dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ RUN pip install pip-tools

COPY ./requirements.txt .
RUN pip-sync requirements.txt
RUN pip install django-debug-toolbar==3.5.0

WORKDIR /usr/src/app
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@ In addition to running pycodestyle, pydocstyle, and mypy, this will also check t

Note that validating the API schema requires Node 16 (newer versions may work as well).
You can install Node 16 with [NVM](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating).

# Profiling
You can use django-debug-toolbar to profile API requests.

1. Follow the [dev stack setup tutorial](https://github.com/eecs-autograder/autograder-full-stack/blob/master/docs/development_setup.md) for the [autograder-full-stack repo](https://github.com/eecs-autograder/autograder-full-stack).
2. Populate the database with benchmark data.
Benchmark scripts should be added to autograder-server/benchmarks and should include:
- Instructions on how to run them on the development stack.
- Results from the last time they were run (and specifying what machine).
3. Visit the API URL in your browser with the query parameter `debug=true` appended.
For example: `https://localhost:<port>/api/users/current/?debug=true`
65 changes: 27 additions & 38 deletions autograder/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,33 @@

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# !!! IMPORTANT !!!
# As of 22 April, 2020, django-debug-toolbar 2.2 (required when using Django 3)
# causes a memory leak, which in turn causes MemoryError in tests that create
# subprocesses. If you need to profile something, install the library manually
# and then uncomment the settings below to enable it. Also uncomment the
# "__debug__" url pattern in urls.py.
# Once you are finished profiling, UNINSTALL the library an RE-COMMENT
# the settings.
#
# INSTALLED_APPS += [
# 'debug_toolbar',
# ]
# def show_toolbar_callback(request):
# return DEBUG
# DEBUG_TOOLBAR_CONFIG = {
# 'SHOW_TOOLBAR_CALLBACK': show_toolbar_callback
# }
# DEBUG_TOOLBAR_PANELS = [
# 'debug_toolbar.panels.versions.VersionsPanel',
# 'debug_toolbar.panels.timer.TimerPanel',
# 'debug_toolbar.panels.settings.SettingsPanel',
# 'debug_toolbar.panels.headers.HeadersPanel',
# 'debug_toolbar.panels.request.RequestPanel',
# 'debug_toolbar.panels.sql.SQLPanel',
# 'debug_toolbar.panels.profiling.ProfilingPanel',
# # 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
# # 'debug_toolbar.panels.templates.TemplatesPanel',
# 'debug_toolbar.panels.cache.CachePanel',
# 'debug_toolbar.panels.signals.SignalsPanel',
# 'debug_toolbar.panels.logging.LoggingPanel',
# 'debug_toolbar.panels.redirects.RedirectsPanel',
# ]
# MIDDLEWARE += (
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
# 'autograder.non_html_debug_toolbar_middleware.NonHtmlDebugToolbarMiddleware',
# )
#
# /IMPORTANT
INSTALLED_APPS += [
'debug_toolbar',
]
def show_toolbar_callback(request):
return DEBUG
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar_callback
}
DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.profiling.ProfilingPanel',
# 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
# 'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
]
MIDDLEWARE += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
'autograder.non_html_debug_toolbar_middleware.NonHtmlDebugToolbarMiddleware',
)

REST_FRAMEWORK.update({
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
Expand Down
9 changes: 4 additions & 5 deletions autograder/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
url(r'^static/(?P<path>.*)$', views.serve),
]

# See note in autograder/settings/development.py
# import debug_toolbar
# urlpatterns = [
# url(r'^__debug__/', include(debug_toolbar.urls)),
# ] + urlpatterns
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ celery==4.4.7
# via -r requirements.in
decorator==4.4.2
# via ipython
django==3.2.2
django==3.2.25
# via
# -r requirements.in
# django-redis
Expand Down

0 comments on commit 7319c84

Please sign in to comment.