<s> """<STR_LIT>""" <EOL> profile_orig = __import__ ( '<STR_LIT>' ) <EOL> for var in profile_orig . __all__ : <EOL> exec "<STR_LIT>" % ( var , var ) <EOL> import new <EOL> import sys <EOL> import traceback <EOL> import functools <EOL> from eventlet import greenthread <EOL> from eventlet import patcher <EOL> thread = patcher . original ( '<STR_LIT>' ) <EOL> class Profile ( profile_orig . Profile ) : <EOL> base = profile_orig . Profile <EOL> def __init__ ( self , timer = None , bias = None ) : <EOL> self . current_tasklet = greenthread . getcurrent ( ) <EOL> self . thread_id = thread . get_ident ( ) <EOL> self . base . __init__ ( self , timer , bias ) <EOL> self . sleeping = { } <EOL> def __call__ ( self , * args ) : <EOL> "<STR_LIT>" <EOL> r = self . dispatcher ( * args ) <EOL> def _setup ( self ) : <EOL> self . cur , self . timings , self . current_tasklet = None , { } , greenthread . getcurrent ( ) <EOL> self . thread_id = thread . get_ident ( ) <EOL> self . simulate_call ( "<STR_LIT>" ) <EOL> def start ( self , name = "<STR_LIT:start>" ) : <EOL> if getattr ( self , "<STR_LIT>" , False ) : <EOL> return <EOL> self . _setup ( ) <EOL> self . simulate_call ( "<STR_LIT:start>" ) <EOL> self . running = True <EOL> sys . setprofile ( self . dispatcher ) <EOL> def stop ( self ) : <EOL> sys . setprofile ( None ) <EOL> self . running = False <EOL> self . TallyTimings ( ) <EOL> def runctx ( self , cmd , globals , locals ) : <EOL> self . _setup ( ) <EOL> try : <EOL> return profile_orig . Profile . runctx ( self , cmd , globals , locals ) <EOL> finally : <EOL> self . TallyTimings ( ) <EOL> def runcall ( self , func , * args , ** kw ) : <EOL> self . _setup ( ) <EOL> try : <EOL> return profile_orig . Profile . runcall ( self , func , * args , ** kw ) <EOL> finally : <EOL> self . TallyTimings ( ) <EOL> def trace_dispatch_return_extend_back ( self , frame , t ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( self . cur [ - <NUM_LIT:2> ] , Profile . fake_frame ) : <EOL> return False <EOL> self . trace_dispatch_call ( frame , <NUM_LIT:0> ) <EOL> return self . trace_dispatch_return ( frame , t ) ; <EOL> def trace_dispatch_c_return_extend_back ( self , frame , t ) : <EOL> if isinstance ( self . cur [ - <NUM_LIT:2> ] , Profile . fake_frame ) : <EOL> return False <EOL> self . trace_dispatch_c_call ( frame , <NUM_LIT:0> ) <EOL> return self . trace_dispatch_return ( frame , t ) <EOL> dispatch = dict ( profile_orig . Profile . dispatch ) <EOL> dispatch . update ( { <EOL> "<STR_LIT>" : trace_dispatch_return_extend_back , <EOL> "<STR_LIT>" : trace_dispatch_c_return_extend_back , <EOL> } ) <EOL> def SwitchTasklet ( self , t0 , t1 , t ) : <EOL> pt , it , et , fn , frame , rcur = self . cur <EOL> cur = ( pt , it + t , et , fn , frame , rcur ) <EOL> self . sleeping [ t0 ] = cur , self . timings <EOL> self . current_tasklet = t1 <EOL> try : <EOL> self . cur , self . timings = self . sleeping . pop ( t1 ) <EOL> except KeyError : <EOL> self . cur , self . timings = None , { } <EOL> self . simulate_call ( "<STR_LIT>" ) <EOL> self . simulate_call ( "<STR_LIT>" ) <EOL> def ContextWrap ( f ) : <EOL> @ functools . wraps ( f ) <EOL> def ContextWrapper ( self , arg , t ) : <EOL> current = greenthread . getcurrent ( ) <EOL> if current != self . current_tasklet : <EOL> self . SwitchTasklet ( self . current_tasklet , current , t ) <EOL> t = <NUM_LIT:0.0> <EOL> return f ( self , arg , t ) <EOL> return ContextWrapper <EOL> dispatch = dict ( [ ( key , ContextWrap ( val ) ) for key , val in dispatch . iteritems ( ) ] ) <EOL> def TallyTimings ( self ) : <EOL> oldtimings = self . sleeping <EOL> self . sleeping = { } <EOL> self . cur = self . Unwind ( self . cur , self . timings ) <EOL> for tasklet , ( cur , timings ) in oldtimings . iteritems ( ) : <EOL> self . Unwind ( cur , timings ) <EOL> for k , v in timings . iteritems ( ) : <EOL> if k not in self . timings : <EOL> self . timings [ k ] = v <EOL> else : <EOL> cc , ns , tt , ct , callers = self . timings [ k ] <EOL> cc += v [ <NUM_LIT:0> ] <EOL> tt += v [ <NUM_LIT:2> ] <EOL> ct += v [ <NUM_LIT:3> ] <EOL> for k1 , v1 in v [ <NUM_LIT:4> ] . iteritems ( ) : <EOL> callers [ k1 ] = callers . get ( k1 , <NUM_LIT:0> ) + v1 <EOL> self . timings [ k ] = cc , ns , tt , ct , callers <EOL> def Unwind ( self , cur , timings ) : <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> while ( cur [ - <NUM_LIT:1> ] ) : <EOL> rpt , rit , ret , rfn , frame , rcur = cur <EOL> frame_total = rit + ret <EOL> if rfn in timings : <EOL> cc , ns , tt , ct , callers = timings [ rfn ] <EOL> else : <EOL> cc , ns , tt , ct , callers = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , { } <EOL> if not ns : <EOL> ct = ct + frame_total <EOL> cc = cc + <NUM_LIT:1> <EOL> if rcur : <EOL> ppt , pit , pet , pfn , pframe , pcur = rcur <EOL> else : <EOL> pfn = None <EOL> if pfn in callers : <EOL> callers [ pfn ] = callers [ pfn ] + <NUM_LIT:1> <EOL> elif pfn : <EOL> callers [ pfn ] = <NUM_LIT:1> <EOL> timings [ rfn ] = cc , ns - <NUM_LIT:1> , tt + rit , ct , callers <EOL> ppt , pit , pet , pfn , pframe , pcur = rcur <EOL> rcur = ppt , pit + rpt , pet + frame_total , pfn , pframe , pcur <EOL> cur = rcur <EOL> return cur <EOL> def run ( statement , filename = None , sort = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> prof = Profile ( ) <EOL> try : <EOL> prof = prof . run ( statement ) <EOL> except SystemExit : <EOL> pass <EOL> if filename is not None : <EOL> prof . dump_stats ( filename ) <EOL> else : <EOL> return prof . print_stats ( sort ) <EOL> def runctx ( statement , globals , locals , filename = None ) : <EOL> """<STR_LIT>""" <EOL> prof = Profile ( ) <EOL> try : <EOL> prof = prof . runctx ( statement , globals , locals ) <EOL> except SystemExit : <EOL> pass <EOL> if filename is not None : <EOL> prof . dump_stats ( filename ) <EOL> else : <EOL> return prof . print_stats ( ) </s>
