diff --git a/pylons_app/lib/timerproxy.py b/pylons_app/lib/timerproxy.py new file mode 100644 --- /dev/null +++ b/pylons_app/lib/timerproxy.py @@ -0,0 +1,15 @@ +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: + log.info(">>>>> STARTING QUERY >>>>>") + return execute(cursor, statement, parameters, context) + finally: + total = time.time() - now + log.info("Query: %s" % statement % parameters) + log.info("<<<<< TOTAL TIME: %f <<<<<" % total)