
Untitled
By: a guest on
May 4th, 2012 | syntax:
None | size: 0.59 KB | hits: 9 | expires: Never
from sqlalchemy.interfaces import ConnectionProxy
import time
import logging
log = logging.getLogger(__name__)
class TimerProxy(ConnectionProxy):
def cursor_execute(self, execute, cursor, statement, parameters, context, executemany):
now = time.time()
try:
return execute(cursor, statement, parameters, context)
finally:
total = time.time() - now
log.debug("Query: %s" % statement)
log.debug("Total Time: %f" % total)
config/environment.py:
engine = engine_from_config(config, 'sqlalchemy.', proxy=TimerProxy())