Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mélanie Chauvel
funkwhale
Commits
5623b6d8
Verified
Commit
5623b6d8
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Added profiling middleware (enable locally by adding ?prof param to url)
parent
cd07b196
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/config/settings/local.py
+21
-2
21 additions, 2 deletions
api/config/settings/local.py
api/funkwhale_api/common/middleware.py
+51
-0
51 additions, 0 deletions
api/funkwhale_api/common/middleware.py
with
72 additions
and
2 deletions
api/config/settings/local.py
+
21
−
2
View file @
5623b6d8
...
...
@@ -38,10 +38,26 @@ EMAIL_PORT = 1025
DEBUG_TOOLBAR_CONFIG
=
{
"
DISABLE_PANELS
"
:
[
"
debug_toolbar.panels.redirects.RedirectsPanel
"
],
"
SHOW_TEMPLATE_CONTEXT
"
:
True
,
"
SHOW_TOOLBAR_CALLBACK
"
:
lambda
request
:
True
,
"
SHOW_TOOLBAR_CALLBACK
"
:
lambda
request
:
"
debug
"
in
request
.
GET
,
"
JQUERY_URL
"
:
"
/staticfiles/admin/js/vendor/jquery/jquery.js
"
,
}
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.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',
# 'debug_toolbar.panels.profiling.ProfilingPanel',
]
# django-extensions
# ------------------------------------------------------------------------------
# INSTALLED_APPS += ('django_extensions', )
...
...
@@ -69,4 +85,7 @@ if env.bool("WEAK_PASSWORDS", default=False):
# Faster during tests
PASSWORD_HASHERS
=
(
"
django.contrib.auth.hashers.MD5PasswordHasher
"
,)
MIDDLEWARE
=
(
"
funkwhale_api.common.middleware.DevHttpsMiddleware
"
,)
+
MIDDLEWARE
MIDDLEWARE
=
(
"
funkwhale_api.common.middleware.DevHttpsMiddleware
"
,
"
funkwhale_api.common.middleware.ProfilerMiddleware
"
,
)
+
MIDDLEWARE
This diff is collapsed.
Click to expand it.
api/funkwhale_api/common/middleware.py
+
51
−
0
View file @
5623b6d8
import
html
import
io
import
requests
import
time
import
xml.sax.saxutils
...
...
@@ -242,3 +243,53 @@ class ThrottleStatusMiddleware:
response
[
"
X-RateLimit-ResetSeconds
"
]
=
str
(
remaining
)
return
response
class
ProfilerMiddleware
:
"""
from https://github.com/omarish/django-cprofile-middleware/blob/master/django_cprofile_middleware/middleware.py
Simple profile middleware to profile django views. To run it, add ?prof to
the URL like this:
http://localhost:8000/view/?prof
Optionally pass the following to modify the output:
?sort => Sort the output by a given metric. Default is time.
See
http://docs.python.org/2/library/profile.html#pstats.Stats.sort_stats
for all sort options.
?count => The number of rows to display. Default is 100.
?download => Download profile file suitable for visualization. For example
in snakeviz or RunSnakeRun
This is adapted from an example found here:
http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation.
"""
def
__init__
(
self
,
get_response
):
self
.
get_response
=
get_response
def
__call__
(
self
,
request
):
if
"
prof
"
not
in
request
.
GET
:
return
self
.
get_response
(
request
)
import
profile
import
pstats
profiler
=
profile
.
Profile
()
response
=
profiler
.
runcall
(
self
.
get_response
,
request
)
profiler
.
create_stats
()
if
"
prof-download
"
in
request
.
GET
:
import
marshal
output
=
marshal
.
dumps
(
profiler
.
stats
)
response
=
http
.
HttpResponse
(
output
,
content_type
=
"
application/octet-stream
"
)
response
[
"
Content-Disposition
"
]
=
"
attachment; filename=view.prof
"
response
[
"
Content-Length
"
]
=
len
(
output
)
stream
=
io
.
StringIO
()
stats
=
pstats
.
Stats
(
profiler
,
stream
=
stream
)
stats
.
sort_stats
(
request
.
GET
.
get
(
"
prof-sort
"
,
"
cumtime
"
))
stats
.
print_stats
(
int
(
request
.
GET
.
get
(
"
count
"
,
100
)))
response
=
http
.
HttpResponse
(
"
<pre>%s</pre>
"
%
stream
.
getvalue
())
return
response
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment