<s> import hotshot <EOL> import os <EOL> import time <EOL> from django . conf import settings <EOL> from django . db import connection <EOL> try : <EOL> PROFILE_LOG_BASE = settings . PROFILE_LOG_BASE <EOL> except : <EOL> PROFILE_LOG_BASE = "<STR_LIT>" <EOL> def profile ( log_file ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . isabs ( log_file ) : <EOL> log_file = os . path . join ( PROFILE_LOG_BASE , log_file ) <EOL> def _outer ( f ) : <EOL> def _inner ( * args , ** kwargs ) : <EOL> ( base , ext ) = os . path . splitext ( log_file ) <EOL> base = base + "<STR_LIT:->" + time . strftime ( "<STR_LIT>" , time . gmtime ( ) ) <EOL> final_log_file = base + ext <EOL> prof = hotshot . Profile ( final_log_file ) <EOL> try : <EOL> ret = prof . runcall ( f , * args , ** kwargs ) <EOL> finally : <EOL> prof . close ( ) <EOL> return ret <EOL> return _inner <EOL> return _outer <EOL> def timethis ( fn ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> start = time . time ( ) <EOL> result = fn ( * args , ** kwargs ) <EOL> print fn . __name__ , '<STR_LIT>' , time . time ( ) - start <EOL> return result <EOL> return wrapper <EOL> from pprint import pprint <EOL> def sqlprint ( fn ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> connection . queries = list ( ) <EOL> result = fn ( * args , ** kwargs ) <EOL> print fn . __name__ , '<STR_LIT>' <EOL> pprint ( connection . queries ) <EOL> return result <EOL> return wrapper </s>
