diff --git a/profiler/urls.py b/profiler/urls.py index 07f3b7f..2c58790 100644 --- a/profiler/urls.py +++ b/profiler/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import url, patterns urlpatterns = patterns( 'profiler.views', @@ -6,5 +6,4 @@ url(r'^by_view/$', 'stats_by_view', name='profiler_stats_by_view'), url(r'^code/$', 'python_stats', name='profiler_python_stats'), url(r'^reset/$', 'reset', name='profiler_reset'), - ) - +) diff --git a/profiler/views.py b/profiler/views.py index 150f3ba..7420d0a 100644 --- a/profiler/views.py +++ b/profiler/views.py @@ -1,10 +1,9 @@ -from django.http import HttpResponse, HttpResponseRedirect +import json +from django.http import HttpResponseRedirect from django.shortcuts import render_to_response from django.template.context import RequestContext -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 aggregate.client import get_client @@ -23,26 +22,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)