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

Add debug toolbar config and documentation #698

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile-django-dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,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`
5 changes: 5 additions & 0 deletions autograder/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,8 @@
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

from autograder.settings.celery_settings import * # noqa


# Indicates that the Django service is running as part of the web development stack
# (specifically the web server rather than the graders or running linters).
IS_DEV_SERVER = os.environ.get('IS_DEV_SERVER', 'false') == 'true'
68 changes: 30 additions & 38 deletions autograder/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,36 @@

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
if IS_DEV_SERVER:
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
11 changes: 5 additions & 6 deletions autograder/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
url(r'^api/', include('autograder.mutant_hints.urls')),
]

if settings.DEBUG:
if settings.IS_DEV_SERVER:
urlpatterns += [
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-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ coreapi==2.3.3
# via djangorestframework-stubs
coreschema==0.0.4
# via coreapi
django==3.2.2
django==3.2.25
# via
# -c requirements.txt
# django-stubs
Expand Down
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
Loading