<s> import os <EOL> import datetime <EOL> PROFILE_LOG_BASE = '<STR_LIT>' <EOL> def profile_func ( filename ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . isabs ( filename ) : <EOL> filename = os . path . join ( PROFILE_LOG_BASE , filename ) <EOL> def proffunc ( f ) : <EOL> def profiled_func ( * args , ** kwargs ) : <EOL> import cProfile <EOL> import logging <EOL> ( base , ext ) = os . path . splitext ( filename ) <EOL> base = base + "<STR_LIT:->" + datetime . datetime . now ( ) . strftime ( "<STR_LIT>" ) <EOL> final_log_file = base + ext <EOL> logging . info ( '<STR_LIT>' % ( f . __name__ ) ) <EOL> try : <EOL> profiler = cProfile . Profile ( ) <EOL> retval = profiler . runcall ( f , * args , ** kwargs ) <EOL> profiler . getstats ( ) <EOL> profiler . dump_stats ( final_log_file ) <EOL> except IOError : <EOL> logging . exception ( "<STR_LIT>" % { "<STR_LIT:filename>" : final_log_file } ) <EOL> return retval <EOL> return profiled_func <EOL> return proffunc </s>
