From d0c424c0c6a26ad9ea190319ad5d1e5872d63f6c Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Thu, 19 May 2011 19:15:37 +0200 Subject: Display execution time after query --- debug_toolbar/management/commands/debugsqlshell.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py index eaeafd4..e323401 100644 --- a/debug_toolbar/management/commands/debugsqlshell.py +++ b/debug_toolbar/management/commands/debugsqlshell.py @@ -1,5 +1,6 @@ import os from optparse import make_option +from datetime import datetime from django.core.management.base import NoArgsCommand from django.db.backends import util @@ -8,12 +9,16 @@ from debug_toolbar.utils import sqlparse class PrintQueryWrapper(util.CursorDebugWrapper): def execute(self, sql, params=()): + starttime = datetime.today() try: return self.cursor.execute(sql, params) finally: raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params) + execution_time = datetime.today() - starttime print sqlparse.format(raw_sql, reindent=True) print + print 'Execution time: %fs' % execution_time.total_seconds() + print util.CursorDebugWrapper = PrintQueryWrapper -- cgit v1.2.3 From e6a1fcb0a21161ecb4f3393a2cfd3cc591c83543 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sun, 25 Sep 2011 22:12:17 +0200 Subject: Changed datetime.today to datetime.now --- debug_toolbar/management/commands/debugsqlshell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py index e323401..6bb16de 100644 --- a/debug_toolbar/management/commands/debugsqlshell.py +++ b/debug_toolbar/management/commands/debugsqlshell.py @@ -9,12 +9,12 @@ from debug_toolbar.utils import sqlparse class PrintQueryWrapper(util.CursorDebugWrapper): def execute(self, sql, params=()): - starttime = datetime.today() + starttime = datetime.now() try: return self.cursor.execute(sql, params) finally: raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params) - execution_time = datetime.today() - starttime + execution_time = datetime.now() - starttime print sqlparse.format(raw_sql, reindent=True) print print 'Execution time: %fs' % execution_time.total_seconds() -- cgit v1.2.3