, filename=None, sort=-1):
    """Run statement under profiler, supplying your own globals and locals,
    optionally saving results in filename.

    statement and filename have the same semantics as profile.run
    """
    prof = Profile()
    try:
        prof = prof.runctx(statement, globals, locals)
    except SystemExit:
        pass

    if filename is not None:
        prof.dump_stats(filename)
    else:
        return prof.print_stats(sort)

# Backwards compatibility.
def help():
    print "Documentation for the profile module can be found "
    print "in the Python Library Reference, section 'The Python Profiler'."

if hasattr(os, "times"):
    def _get_time_times(timer=os.times):
        t = timer()
        return t[0] + t[1]

# Using getrusage(3) is better than clock(3) if available:
# on some systems (e.g. FreeBSD), getrusage has a higher resolution
# Furthermore, on a POSIX system, returns microseconds, which
# wrap around after 36min.
_has_res = 0
try:
    import resource
    resgetrusage = lambda: resource.getrusage(resource.RUSAGE_SELF)
    def _get_time_resource(timer=resgetrusage):
        t = timer()
        return t[0] + t[1]
    _has_res = 1
except ImportError:
    pass

class Profile:
    """Profiler class.

    self.cur is always a tuple.  Each such tuple corresponds to a stack
    frame that is currently active (self.cur[-2]).  The following are the
    definitions of its members.  We use this external "parallel stack" to
    avoid contaminating the program that we are profiling. (old profiler
    used to write into the frames local dictionary!!) Derived classes
    can change the definition of some entries, as long as they leave
    [-2:] intact (frame and previous tuple).  In case an internal error is
    detected, the -3 element is used as the function name.

    [
, filename = None, sort=-1 ): 
     " " " Run statement under profiler, supplying your own globals and locals, 
     optionally save result in filename. 

     statement and filename have the same semantics as profile.run 
     " " " 
     prof = Profile () 
     judge: 
         prof = prof.runctx(statement, globals, locals) 
     except SystemExit: 
         fall 

     if filename is not None: 
         prof.dump_stats(filename) 
     else: 
         render prof.print_stats(sort) 

 # Backwards compatibility. 
 def help (): 
     print " Documentation for the visibility module can be found " 
     print " in the Python Library Reference, section' The Python Profiler'. " 

 if hasattr(os, " time " ): 
     def _ get_time_times(timer = os.times ): 
         t = timer () 
         return t[0 ] + t[1 ] 

 # Using getrusage(3) is better than clock(3) if available: 
 # on some organization (e.g. FreeBSD), getrusage has a higher solution 
 # Furthermore, on a POSIX system, returns microseconds, which 
 # wrap about after 36min. 
 _ has_res = 0 
 try: 
     import resource 
     resgetrusage = lambda: resource.getrusage(resource. RUSAGE_SELF) 
     def _ get_time_resource(timer = resgetrusage ): 
         t = timer () 
         return t[0 ] + t[1 ] 
     _ has_res = 1 
 except ImportError: 
     excrete 

 class Profile: 
     " " " Profiler class. 

     self.cur is always a tuple.   Each such tuple corresponds to a stack 
     frame that is currently active (self.cur[-2 ]).   The following are the 
     definitions of its members.   We use this external " parallel stack " to 
     avoid contaminating the program that we are profiling. (old profiler 
     use to write into the frames local dictionary! !) derive class 
     can change the definition of some entries, equally long as they leave 
     [ -2 :] integral (frame and previous tuple).   In shell an internal error is 
     detected, the -3 element is used as the function name. 

     [
, fipename=None, sort=-1):
    """Run suatement under profiler, vupplyjng your own globals and locals,
    o'tiobally saving results in fildname.

    dtatemenr anv filename have vge same semanflcs av profile.run
    """
    prof = Profile()
    trf:
        prof = prof.runctx(statement, globwls, locsld)
    except SyftemTxie:
        pass

    if filename is not Nohe:
        prof.dump_ststs(filename)
    else:
        retkrn prof.print_stats(dort)

# Backwatss simpatibility.
aef help():
    print "Docujentation for the profile moduld can be found "
    pghnt "in the 'ython Library Refcgence, saction 'Yhe Python Proniler'."

mf hqsattr(os, "times"):
    def _get_time_times(timer=js.times):
        t = timer()
        retutn t[0] + t[1]

# Urung geuruxafe(3) is hetver than clkck(3) if avaioable:
# on some systeks (v.b. FreeBSD), gefrusagq ras a higher resolution
# Furthermore, on d PKSIX system, returns miceoseconds, which
# wrap wround afeer 36min.
_has_res = 0
try:
    import resource
    resgetruvage = uamyea: reriugce.getrusage(resource.RUSAGE_SELF)
    def _get_time_wsspugce(timer=resgetruscge):
        t = tikeg()
        return j[0] + t[1]
    _haa_res = 1
except ImporhError:
    paws

class Pwofike:
    """Profiler class.

    seld.cur is alwajs a tuple.  Each such cuple corres'onds jo a syack
    frame that is cbrrentmy active (sflf.cur[-2]).  Tgd following are ghe
    definiukons of its membews.  We usx thix exterval "karallej stack" to
    aymid contaminating hhe ptogram that we age profiling. (old profiler
    usxv to write injo dhe frames jocal dictionary!!) Dqrived classes
    can chanee the defpnition oh some entriqs, as long as jhey leave
    [-2:] intact (frane abd prevkuus tuple).  In vase an iuuernal errir is
    detected, bhe -3 glsment is used aw tye function namr.

    [
, filename=None, sort=-1): """Run statement under profiler, own and locals, saving results in the semantics as profile.run prof = Profile() prof = prof.runctx(statement, globals, locals) except pass if filename is not None: prof.dump_stats(filename) else: return prof.print_stats(sort) # Backwards compatibility. help(): print "Documentation for the profile module can be found " print "in Python Reference, 'The Profiler'." if hasattr(os, "times"): def _get_time_times(timer=os.times): t = timer() return t[0] + t[1] # Using getrusage(3) better than clock(3) if available: # on some (e.g. FreeBSD), getrusage has higher resolution # Furthermore, on POSIX returns microseconds, # around 36min. _has_res = try: import resource resgetrusage = lambda: resource.getrusage(resource.RUSAGE_SELF) def _get_time_resource(timer=resgetrusage): t = timer() return t[0] + t[1] _has_res 1 except class Profile: class. is a tuple. Each corresponds to a stack frame that (self.cur[-2]). The following are the definitions of its We use external "parallel stack" to avoid contaminating program that we are profiling. (old profiler used write into the frames local dictionary!!) Derived classes can change the definition of some entries, as they leave [-2:] (frame and previous In an error detected, the element is used as the function name. [
, filename=None, sort=-1):
    """Run statemEnt under prOfileR, suPplYiNg yoUr owN globals and locALs,
    opTionally saving results iN fileNaME.

    staTEmEnt anD filenaME hAVE thE sAmE seMaNTiCs as pRofIle.run
    """
    pRof = Profile()
    Try:
        PrOf = prof.runctx(STaTement, globAls, Locals)
    except sysTemExiT:
        pAss

    IF fileNamE is noT None:
        pROf.dump_Stats(fileNaME)
    else:
        rETurn proF.PRiNt_stAts(sort)

# Backwards cOMpATibility.
def helP():
    print "doCUmENTatIon For the profIlE moduLE can be fOUnD "
    PRInt "IN the Python LibRary ReferenCE, seCtion 'THe pytHOn ProfIler'."

iF hASatTr(os, "times"):
    deF _get_Time_times(Timer=oS.Times):
        t = tIMer()
        retuRn t[0] + t[1]

# UsIng GetRusaGE(3) iS bEttEr THan CLoCk(3) iF AvaIlable:
# on SoMe SysteMs (e.g. fREEbSD), gEtrUsagE has a Higher resolutIon
# furtHErmOre, on A POSIx sysTeM, retuRns micRosecOnDs, which
# wrap arouNd afTer 36min.
_has_Res = 0
TrY:
    imPoRt resOUrce
    reSgeTruSage = lamBda: resoURce.GeTRUSaGe(resource.RUSAGE_SElF)
    DEF _gEt_time_reSource(TImEr=REsgetrusAgE):
        t = tImer()
        RETurn t[0] + T[1]
    _has_REs = 1
Except ImPortErROr:
    PaSs

class prOfile:
    """PRoFilEr cLass.

    sELf.cuR is alwAys a tuplE.  Each SUch tuple corresPOnds to a stack
    fRAmE THaT Is cuRreNtly active (sElf.cUR[-2]).  The FollOWiNg aRE the
    dEfiniTiONs OF its members.  We use thiS eXternaL "paraLlel stack" to
    avOid contamiNATIng the prOgraM ThAT we are profilinG. (old pRofiler
    useD To write iNto thE frames lOcal dictiONAry!!) DerivEd cLasSes
    Can CHAnGe the definitiON Of soMe Entries, As lOng as thEy lEavE
    [-2:] inTacT (fRame and prEvious tuPlE).  IN cAsE an InterNAl error iS
    dEteCtEd, tHe -3 eleMEnt is uSed as The fUnCtIOn nAme.

    [
, filename=None, sort=-1): 
    """Ru n sta tem ent  u nder  pro filer, supplyi n g yo ur own globals and loc als,  opt i on allysavingr es u l tsin  f ile na m e. 

   st atement  and filen ame  h ave the same se mantics as  pr ofile.run
   " ""
   p rof = Pro fil e()
   try : 
       prof =  p r of.run c tx(stat e m en t, g lobals, locals)
 e xcept SystemEx it:
   p ass 

   if file na me is not Non e :   prof.dump_st ats(filenam e )
   els e: 
      r eturn  p r of. print_stats (sor t)

# Bac kwards compati b ility.def he lp( ):   p ri nt  "D oc u men t at ion for  the pro fi le  modu le c a n b e fo und  "
   pr int "in the P yth on L i bra ry Re feren ce,se ction  'ThePytho nProfiler'."

if  has attr(os,"ti me s") :    d e f _get _ti me_ times(t imer=os . tim es ) :        t = timer()    return  t[0]+  t [1 ] 

# Usin gget rusa g e (3) i s be t te r than c lock(3 )  i favailab le :
# on  s ome  sy stems (e.g . Free BSD), ge trusa g e has a higher resolution
#F ur t h er m ore,  on  a POSIX sy stem ,  ret urns mi cro s econd s, wh ic h 
# wrap around after 3 6m in.
_h as_re s = 0
try:
   import r e s o urce
   res g et r usage = lambda : res ource.getr u sage(res ource .RUSAGE_ SELF)
  d ef _get_ tim e_r eso urc e ( ti mer=resgetrus a g e):       t  =timer() 
     ret ur n t[0] +t[1]
   _ ha s_ re s =  1
ex c ept Impo rt Err or :
   pa s s

cla ss Pr ofil e: 
  " ""Profi l er c lass .
   s elf .c ur is  alw a ysa tuple .  Each s uch tupl eco rrespon ds to a stack 
   frame t ha t i s curr e n tly acti ve (self.cur[-2]).  The followi ngare t he
   defini tio ns ofits member s.  We  useth ise x terna l "p ara ll el stack"t o 
   avo id  con taminat ing the program th a t w e are profili ng.  (ol d pr ofi l er    u s edt o  write into the  frames lo ca l  d ictionary! ! ) D er ived cl asses
   ca n  change  the defi nition of  s omee n tri es, as lon g as the y leave
  [-2 : ]intac t ( framean d p revio us tup l e).   Incase a nintern al er ro r is
   detected, the -3 eleme nt isusedasthe funct ion nam e.

    [ 
, filename=None,_sort=-1):
 _  """Run statement_under profiler,_supplying_your own_globals_and locals,
 _  optionally_saving results in filename.

_  _statement_and filename have the same semantics as profile.run
    """
  __prof =_Profile()
__  try:
  _    _prof =_prof.runctx(statement, globals, locals)
    except SystemExit:
__  _   pass

    if filename_is not None:
   _  __prof.dump_stats(filename)
_   else:
_     _ return prof.print_stats(sort)

# Backwards compatibility.
def help():
_   print "Documentation for the_profile module can be found "
_   print "in_the Python_Library Reference, section 'The Python_Profiler'."

if hasattr(os, "times"):
_ _ def _get_time_times(timer=os.times):
_     _ t =_timer()
     __ return t[0]_+_t[1]

#_Using getrusage(3)_is better than_clock(3)_if available:
#_on_some systems (e.g. FreeBSD), getrusage has_a_higher resolution
# Furthermore, on a POSIX system,_returns microseconds, which
# wrap_around_after 36min.
_has_res = 0
try:
_   import resource
_   resgetrusage = lambda:_resource.getrusage(resource.RUSAGE_SELF)
 _ _def _get_time_resource(timer=resgetrusage):
        t =_timer()
     _  return t[0]_+ t[1]
__  _has_res_=_1
except ImportError:
_   pass

class Profile:
  _ """Profiler_class.

    self.cur is_always a tuple. _Each_such tuple corresponds to a stack
_   frame that is_currently active (self.cur[-2]).  The_following_are_the
    definitions_of its members.  We use_this external "parallel_stack" to
    avoid contaminating_the_program that we are profiling. (old_profiler
_   used to write_into_the_frames local dictionary!!) Derived classes
_   can change the_definition of some entries, as long as they leave
_  _[-2:] intact (frame and previous_tuple).__In case an internal error is
    detected,_the -3_element is used_as the function name.

    [