From a3492e14765e3f898efc26913a8e8c4445a837b4 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Mon, 6 Oct 2008 13:53:14 -0700 Subject: Adding query profiling for MySQL. Thanks to Simon Willison for the suggestion. There's a big TODO on this one, which is to not display or attempt to execute the profiling SQL calls if this isn't MySQL and if MySQL isn't >= version 5.0.37. For now it's a nice playground of the profiler if you have MySQL v5.0.37 or higher. --- debug_toolbar/views.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'debug_toolbar/views.py') diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index 4b666e1..8af879f 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -81,3 +81,38 @@ def sql_explain(request): 'headers': headers, } return render_to_response('debug_toolbar/panels/sql_explain.html', context) + +def sql_profile(request): + """ + Returns the output of running the SQL and getting the profiling statistics. + + Expected GET variables: + sql: urlencoded sql with positional arguments + params: JSON encoded parameter values + time: time for SQL to execute passed in from toolbar just for redisplay + hash: the hash of (secret + sql + params) for tamper checking + """ + from debug_toolbar.panels.sql import reformat_sql + sql = request.GET.get('sql', '') + params = request.GET.get('params', '') + hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest() + if hash != request.GET.get('hash', ''): + return HttpResponse('