From 80dd45632aa21c667e841a1131c74e79d1518881 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 17 Oct 2013 20:48:50 +0200 Subject: Simplify timing implementation. --- debug_toolbar/management/commands/debugsqlshell.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'debug_toolbar/management/commands') diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py index e94e4e2..c5718b8 100644 --- a/debug_toolbar/management/commands/debugsqlshell.py +++ b/debug_toolbar/management/commands/debugsqlshell.py @@ -1,24 +1,23 @@ from __future__ import print_function, unicode_literals -from datetime import datetime +from time import time from django.db.backends import util import sqlparse -from debug_toolbar.utils import ms_from_timedelta - class PrintQueryWrapper(util.CursorDebugWrapper): def execute(self, sql, params=()): - starttime = datetime.now() + start_time = time() try: return self.cursor.execute(sql, params) finally: raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params) - execution_time = ms_from_timedelta(datetime.now() - starttime) + end_time = time() + duration = (end_time - start_time) * 1000 formatted_sql = sqlparse.format(raw_sql, reindent=True) - print('%s [%.2fms]' % (formatted_sql, execution_time)) + print('%s [%.2fms]' % (formatted_sql, duration)) util.CursorDebugWrapper = PrintQueryWrapper -- cgit v1.2.3