#NEWLINE# def _profile( prof_id , func ) : #NEWLINE# #INDENT# '\n  Wrap a call with a profiler\n  ' #NEWLINE# import pstats #NEWLINE# try : #NEWLINE# #INDENT# import cProfile as profile #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# import profile #NEWLINE# #UNINDENT# PROF_DAT = ( '/tmp/desktop-profile-%s.dat' % ( prof_id , ) ) #NEWLINE# prof = profile . Profile ( ) #NEWLINE# try : #NEWLINE# #INDENT# prof . runcall ( func ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if os . path . exists ( PROF_DAT ) : #NEWLINE# #INDENT# os . remove ( PROF_DAT ) #NEWLINE# #UNINDENT# prof . dump_stats ( PROF_DAT ) #NEWLINE# pstats . Stats ( PROF_DAT ) . sort_stats ( 'time' ) . print_stats ( 50 ) #NEWLINE# ( ( print >> sys . stderr ) , ( 'Complete profile data in %s' % ( prof_id , ) ) )