timerproxy.py
18 lines
| 691 B
| text/x-python
|
PythonLexer
Marcin Kuzminski
|
r49 | from sqlalchemy.interfaces import ConnectionProxy | ||
import time | ||||
import logging | ||||
r90 | log = logging.getLogger('timerproxy') | |||
Marcin Kuzminski
|
r49 | |||
class TimerProxy(ConnectionProxy): | ||||
def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): | ||||
now = time.time() | ||||
try: | ||||
log.info(">>>>> STARTING QUERY >>>>>") | ||||
return execute(cursor, statement, parameters, context) | ||||
finally: | ||||
total = time.time() - now | ||||
r90 | try: | |||
log.info("Query: %s" % statement % parameters) | ||||
except TypeError: | ||||
log.info("Query: %s %s" % (statement, parameters)) | ||||
Marcin Kuzminski
|
r49 | log.info("<<<<< TOTAL TIME: %f <<<<<" % total) | ||