Module Expr Str ImportFrom alias ImportFrom alias ImportFrom alias alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults vararg kwarg body If AttributeLoad NameLoad attr body For NameStore Call NameLoad Call NameLoad body Assign NameStore SubscriptLoad NameLoad Index Num If UnaryOpNot Call AttributeLoad NameLoad attr Str body Assign NameStore SubscriptLoad NameLoad Index Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd BinOpAdd BinOpAdd BinOpAdd AttributeLoad NameLoad attr Str NameLoad Str Call NameLoad NameLoad Break Assign NameStore SubscriptLoad Call NameLoad Index Num AugAssignAdd AttributeStore NameLoad attr Num Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr TryFinally body Return Call AttributeLoad NameLoad attr NameLoad NameLoad finalbody Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad AugAssignSub AttributeStore NameLoad attr Num decorator_list FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body AugAssignAdd AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr BinOpSub NameLoad AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return Call AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults NameLoad body Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Call NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr ListLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call NameLoad AttributeLoad NameLoad attr If NameLoad body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr NameLoad Assign NameStore BinOpDiv NameLoad NameLoad For NameStore AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call NameLoad Assign NameStore Call NameLoad AttributeLoad NameLoad attr AugAssignAdd AttributeStore NameLoad attr Num Expr Call AttributeLoad NameLoad attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpSub NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr BinOpSub NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call NameLoad NameLoad If CompareNotIn NameLoad AttributeLoad NameLoad attr body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad Num Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad Num Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad Num AugAssignAdd SubscriptStore AttributeLoad NameLoad attr Index NameLoad AttributeLoad NameLoad attr AugAssignAdd SubscriptStore AttributeLoad NameLoad attr Index NameLoad AttributeLoad NameLoad attr AugAssignAdd SubscriptStore AttributeLoad NameLoad attr Index NameLoad Num decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore IfExp NameLoad NameLoad AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str If Call NameLoad NameLoad Str body Raise Call NameLoad Str Assign NameStore NameLoad ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults vararg kwarg body Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index AttributeLoad NameLoad attr Assign SubscriptStore AttributeLoad NameLoad attr Index AttributeLoad NameLoad attr Call NameLoad Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list decorator_list Assign AttributeStore NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Str body Expr Str If Call NameLoad NameLoad Str body Raise Call NameLoad Str Assign NameStore NameLoad ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults vararg kwarg body For TupleStore NameStore NameStore Call NameLoad NameLoad keyword NameLoad body If BoolOpOr UnaryOpNot NameLoad Call NameLoad NameLoad NameLoad body Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad Call NameLoad Call AttributeLoad NameLoad attr NameLoad BinOpAdd NameLoad NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list decorator_list Assign AttributeStore NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore ListLoad Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr For NameStore Call AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad NameLoad BinOpDiv NameLoad NameLoad NameLoad NameLoad BinOpDiv NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Return BinOpAdd Call AttributeLoad Str attr NameLoad BinOpMod Str AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Dict Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list decorator_list
N/A N/A  timer to wrap specific methods and calculate how long they take to execute.

    general usage:

        t = MonkeyTimer()
        ... patch functions or classes ...
        ... do some work ...
        print t.results()

    to patch a top-level function:

        import module  # NOT: from module import function
        module.function = t.patch_function(module.function, 'fun stats')

    to patch a function in a class:

        import module  # NOT: from module import SomeClass
        module.SomeClass = t.patch_class_one(module.SomeClass, module.SomeClass.some_function, 'some stats')

    to patch all functions in a class (or subset matching regex):

        import module  # NOT: from module import SomeClass
        module.SomeClass = t.patch_class_all(module.SomeClass, 'stats.')

    patches with the same name string are combined.  for example, these three functions will all be reported as 'http stats':

        module.get = t.patch_function(module.get, 'http stats')
        module.put = t.patch_function(module.put, 'http stats')
        module.head = t.patch_function(module.head, 'http stats')

    the results() shows cumulative time spent in function, # calls to function and average time per call.

    the job is complicated by the gevent model -- any blocking call could allow control to switch to a different thread,
    so the sum of the times of overlapping methods could exceed total clock time of the program.

    to address this, the results() output also includes "fractional" time.  if two or calls are made to traced functions
    (the same function from two threads or different traced functions) and the call times overlap, then a fraction of the
    overlapping time is attributed to each function.  for example, if two functions overlap for a 2sec period, then each
    function adds 1sec of execution time to its tally.  the total fractional time shown across all functions will not
    exceed the elapsed execution time, but the relative proportion of time taken by the traced functions gives each
    call equal weight.
 time time types MethodType inspect getmembers ismethod re match threading Lock traceback extract_stack pyon.util log _Wrapper N/A object N/A N/A  replacement for function to be timed  __init__ N/A N/A self timer function name logger N/A N/A N/A N/A self _original function N/A N/A self _timer timer N/A N/A self _name name N/A N/A self _simultaneous 0 N/A N/A self _log logger N/A proxy N/A N/A self N/A a b N/A N/A N/A self _log N/A N/A frame N/A reversed N/A extract_stack N/A N/A file N/A frame N/A 0 N/A N/A N/A N/A file endswith monkey_timer.py N/A N/A line N/A frame N/A 1 N/A N/A N/A N/A self _log info N/A N/A N/A N/A N/A self _name  called by  file : N/A str line N/A N/A tuple N/A N/A extract_stack N/A -2 N/A N/A self _simultaneous 1 N/A start N/A N/A N/A self _timer _start_timing N/A N/A N/A N/A N/A self _original a b N/A N/A N/A N/A N/A self _timer _stop_timing self start N/A N/A self _simultaneous 1 N/A __str__ N/A N/A self N/A N/A N/A N/A self _name N/A N/A _Call N/A object N/A N/A  track one in-flight call of a wrapped function  __init__ N/A N/A self index N/A N/A N/A N/A self proportional_time 0 N/A N/A self _index index N/A add_time N/A N/A self elapsed N/A N/A N/A N/A self proportional_time elapsed N/A start N/A N/A self time N/A N/A N/A N/A self _start_time time N/A stop N/A N/A self time N/A N/A N/A N/A self clock_time N/A time N/A self _start_time N/A __str__ N/A N/A self N/A N/A N/A N/A call %d N/A self _index N/A __repr__ N/A N/A self N/A N/A N/A N/A N/A self __str__ N/A N/A MonkeyTimer N/A object N/A N/A  utility to wrap methods and track time used by calls made to them  __init__ N/A N/A self nooverlap N/A False N/A N/A N/A self _proportional_time N/A N/A N/A self _clock_time N/A N/A N/A self _total_count N/A N/A N/A self _lock N/A Lock N/A N/A self _last_tick None N/A N/A self _currently_running N/A N/A N/A self _max_simultaneous 0 N/A N/A self _call_index 1 N/A N/A self logger None N/A set_logger N/A N/A self logger N/A N/A N/A  if set, will log caller of each wrapped function  N/A N/A self logger logger N/A _add_time N/A N/A self elapsed N/A N/A N/A running_count N/A len N/A self _currently_running N/A running_count N/A N/A N/A self _max_simultaneous N/A max N/A self _max_simultaneous running_count N/A delta N/A elapsed running_count N/A call N/A self _currently_running N/A N/A N/A N/A call add_time delta N/A _start_timing N/A N/A self N/A N/A N/A N/A N/A N/A self _lock acquire N/A this_tick N/A time N/A new_call N/A _Call N/A self _call_index N/A N/A self _call_index 1 N/A N/A N/A new_call start this_tick N/A N/A self _last_tick N/A N/A N/A N/A self _add_time N/A this_tick N/A self _last_tick N/A N/A self _last_tick this_tick N/A N/A N/A N/A self _currently_running append new_call N/A N/A N/A N/A self _lock release N/A new_call N/A _stop_timing N/A N/A self wrapper call N/A N/A N/A N/A N/A N/A self _lock acquire N/A this_tick N/A time N/A N/A N/A call stop this_tick N/A N/A N/A self _add_time N/A this_tick N/A self _last_tick N/A N/A self _last_tick this_tick N/A N/A N/A N/A self _currently_running remove call N/A N/A N/A N/A self _lock release N/A key N/A str wrapper N/A N/A key N/A self _proportional_time N/A N/A N/A N/A self _proportional_time N/A key 0 N/A N/A N/A self _clock_time N/A key 0 N/A N/A N/A self _total_count N/A key 0 N/A N/A N/A self _proportional_time N/A key N/A call proportional_time N/A N/A N/A self _clock_time N/A key N/A call clock_time N/A N/A N/A self _total_count N/A key 1 N/A patch_function N/A N/A self function name logger N/A None N/A N/A  return wrapped version of function  N/A wrapper_log N/A logger logger N/A self logger N/A wrapper N/A _Wrapper self function name wrapper_log N/A N/A wrapper proxy N/A patch_class_one N/A N/A self clazz function name N/A N/A N/A  return replacement class with one function wrapped  N/A N/A hasattr clazz _monkey_timer_patched N/A N/A N/A Exception can only patch once with patch_class N/A timer self _ProxyClass N/A clazz N/A __init__ N/A N/A self N/A a b N/A N/A orig N/A N/A clazz __dict__ N/A N/A function __name__ N/A N/A N/A self __dict__ N/A N/A function __name__ N/A MethodType N/A N/A timer patch_function orig name self _ProxyClass N/A N/A N/A clazz __init__ self a b N/A N/A N/A N/A _ProxyClass _monkey_timer_patched True N/A _ProxyClass N/A patch_class_all N/A N/A self clazz prefix regex N/A ^[^_] N/A N/A  return replacement class with all functions wrapped that match regex  N/A N/A hasattr clazz _monkey_timer_patched N/A N/A N/A Exception can only patch once with patch_class N/A timer self _ProxyClass N/A clazz N/A __init__ N/A N/A self N/A a b N/A N/A N/A name function N/A getmembers clazz predicate ismethod N/A N/A N/A N/A regex N/A match regex name N/A N/A N/A N/A self __dict__ N/A name N/A MethodType N/A N/A timer patch_function function N/A prefix name self _ProxyClass N/A N/A N/A clazz __init__ self a b N/A N/A N/A N/A _ProxyClass _monkey_timer_patched True N/A _ProxyClass N/A results N/A N/A self N/A N/A N/A  return a string describing times of calls to all wrapped functions  N/A lines N/A function	fractional time	cumulative time N/A N/A N/A N/A self _lock acquire N/A key N/A N/A N/A self _proportional_time keys N/A N/A time N/A N/A self _proportional_time N/A key N/A clocktime N/A N/A self _clock_time N/A key N/A count N/A N/A self _total_count N/A key N/A N/A N/A lines append N/A %s:	%.3e / %d = %.3e	%.3e / %d = %.3e N/A key time count N/A time count clocktime count N/A clocktime count N/A N/A N/A N/A self _lock release N/A N/A N/A N/A join lines N/A 
%d simultaneous N/A self _max_simultaneous N/A reset N/A N/A self N/A N/A N/A  reset all timing results (does not apply to in-flight calls  N/A N/A N/A N/A self _lock acquire N/A N/A self _proportional_time N/A N/A N/A self _clock_time N/A N/A N/A self _total_count N/A N/A N/A N/A N/A self _lock release N/A N/A