Skip to content

Instantly share code, notes, and snippets.

Last active May 17, 2022 20:16
What would you like to do?
def _callback(event, args):
# switch and throw both switch the active greenlet from origin to target
if event not in set(['switch', 'throw']):
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):
if origin is gevent.hub.get_hub():
elapsed_ms = now_time - then_time
elapsed_ticks = now_tick - then_tick
if elapsed_ms <= threshold_ms:
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