gevent_tracer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _callback(event, args): | |
# switch and throw both switch the active greenlet from origin to target | |
if event not in set(['switch', 'throw']): | |
return | |
origin, target = args | |
# record last switch (time and CPU tick) | |
global __last_switch_time_ms, __last_switch_cpu_tick | |
then_time, then_tick = __last_switch_time_ms, __last_switch_cpu_tick | |
now_time, now_tick = switch_timer() | |
__last_switch_time_ms, __last_switch_cpu_tick = now_time, now_tick | |
# first switch, nothing to record | |
if None in (then_time, then_tick): | |
return | |
if origin is gevent.hub.get_hub(): | |
return | |
elapsed_ms = now_time - then_time | |
elapsed_ticks = now_tick - then_tick | |
if elapsed_ms <= threshold_ms: | |
return | |
log_fn(timing=elapsed_ms, value=elapsed_ticks, reason=trace_info) # log extra information e.g. stack frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment