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

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