Skip to content

Commit 05088bc

Browse files
committed
Merge pull request #164 from gwrtheyrn/master
Display execution time with query in debugsqlshell. Thanks gwrtheyrn.
2 parents 5e8cc59 + e6a1fcb commit 05088bc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

debug_toolbar/management/commands/debugsqlshell.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from optparse import make_option
3+
from datetime import datetime
34

45
from django.db.backends import util
56
from django.core.management.commands.shell import Command
@@ -8,11 +9,15 @@
89

910
class PrintQueryWrapper(util.CursorDebugWrapper):
1011
def execute(self, sql, params=()):
12+
starttime = datetime.now()
1113
try:
1214
return self.cursor.execute(sql, params)
1315
finally:
1416
raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
17+
execution_time = datetime.now() - starttime
1518
print sqlparse.format(raw_sql, reindent=True)
1619
print
20+
print 'Execution time: %fs' % execution_time.total_seconds()
21+
print
1722

1823
util.CursorDebugWrapper = PrintQueryWrapper

0 commit comments

Comments
 (0)