Skip to content
Open
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
19 changes: 10 additions & 9 deletions profiler/templates/profiler/base.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -8,12 +9,12 @@
<meta name="author" content="">

<!-- Le styles -->
<link href="{{ STATIC_URL }}profiler/bootstrap.css" rel="stylesheet">
<link href="{{ STATIC_URL }}profiler/profiler.css" rel="stylesheet">
<link href="{% static 'profiler/bootstrap.css' %}" rel="stylesheet">
<link href="{% static 'profiler/profiler.css' %}" rel="stylesheet">


<script src="{{ STATIC_URL }}profiler/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}profiler/jquery.tablesorter.min.js" type="text/javascript"></script>
<script src="{% static 'profiler/jquery-1.7.2.min.js' %}" type="text/javascript"></script>
<script src="{% static 'profiler/jquery.tablesorter.min.js' %}" type="text/javascript"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>

Expand All @@ -29,10 +30,10 @@
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="{% url "profiler_global_stats" %}">SQL global</a></li>
<li><a href="{% url "profiler_stats_by_view" %}">SQL by view</a></li>
<li><a href="{% url "profiler_python_stats" %}">Python code</a></li>
<li><a href="{% url "profiler_reset" %}?next={{ request.path }}">Reset</a></li>
<li><a href="{% url 'profiler_global_stats' %}">SQL global</a></li>
<li><a href="{% url 'profiler_stats_by_view' %}">SQL by view</a></li>
<li><a href="{% url 'profiler_python_stats' %}">Python code</a></li>
<li><a href="{% url 'profiler_reset' %}?next={{ request.path }}">Reset</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
Expand All @@ -44,7 +45,7 @@
{% endblock %}

</div> <!-- /container -->
<script src="{{ STATIC_URL }}profiler/profiler.js" type="text/javascript"></script>
<script src="{% static 'profiler/profiler.js' %}" type="text/javascript"></script>

</body>
</html>
7 changes: 5 additions & 2 deletions profiler/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django.conf.urls.defaults import *
try:
from django.conf.urls import patterns, url
except ImportError:
from django.conf.urls.defaults import patterns, url


urlpatterns = patterns(
'profiler.views',
Expand All @@ -7,4 +11,3 @@
url(r'^code/$', 'python_stats', name='profiler_python_stats'),
url(r'^reset/$', 'reset', name='profiler_reset'),
)

15 changes: 9 additions & 6 deletions profiler/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from django.core.cache import cache
from django.contrib.auth.decorators import user_passes_test
from django.core.urlresolvers import reverse
from django.utils import simplejson

#from django.utils import simplejson
# See: https://docs.djangoproject.com/en/dev/releases/1.5/#system-version-of-simplejson-no-longer-used
import json

from aggregate.client import get_client

Expand All @@ -23,26 +26,26 @@ def stats_by_view(request):
grouped = {}
for r in stats:
if r['view'] not in grouped:
grouped[r['view']] = {'queries' : [],
grouped[r['view']] = {'queries' : [],
'count' : 0,
'time' : 0,
'average_time' : 0}
grouped[r['view']]['queries'].append(r)
grouped[r['view']]['count'] += r['count']
grouped[r['view']]['time'] += r['time']
r['average_time'] = r['time'] / r['count']
r['average_time'] = r['time'] / r['count']
grouped[r['view']]['average_time'] += r['average_time']

maxtime = 0
for r in stats:
if r['average_time'] > maxtime:
maxtime = r['average_time']
for r in stats:
r['normtime'] = (0.0+r['average_time'])/maxtime

return render_to_response('profiler/by_view.html',
{'queries' : grouped,
'stats' :simplejson.dumps(stats)},
'stats' :json.dumps(stats)},
context_instance=RequestContext(request))

@user_passes_test(lambda u:u.is_superuser)
Expand Down