Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.59 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from sqlalchemy.interfaces import ConnectionProxy
  2. import time
  3.  
  4. import logging
  5. log = logging.getLogger(__name__)
  6.  
  7. class TimerProxy(ConnectionProxy):
  8.     def cursor_execute(self, execute, cursor, statement, parameters, context, executemany):
  9.         now = time.time()
  10.         try:
  11.             return execute(cursor, statement, parameters, context)
  12.         finally:
  13.             total = time.time() - now
  14.             log.debug("Query: %s" % statement)
  15.             log.debug("Total Time: %f" % total)
  16.  
  17. config/environment.py:
  18.  
  19. engine = engine_from_config(config, 'sqlalchemy.', proxy=TimerProxy())