1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
from pypy.interpreter.gateway import unwrap_spec
from rpython.rlib import debug, jit
from rpython.rlib import rtimer
@jit.dont_look_inside
@unwrap_spec(category='text', timestamp=bool)
def debug_start(space, category, timestamp=False):
res = debug.debug_start(category, timestamp=timestamp)
if timestamp:
return space.newint(res)
return space.w_None
@jit.dont_look_inside
def debug_print(space, args_w):
parts = [space.text_w(space.str(w_item)) for w_item in args_w]
debug.debug_print(' '.join(parts))
@jit.dont_look_inside
@unwrap_spec(category='text', timestamp=bool)
def debug_stop(space, category, timestamp=False):
res = debug.debug_stop(category, timestamp=timestamp)
if timestamp:
return space.newint(res)
return space.w_None
@unwrap_spec(category='text')
def debug_print_once(space, category, args_w):
debug_start(space, category)
debug_print(space, args_w)
debug_stop(space, category)
@jit.dont_look_inside
def debug_flush(space):
debug.debug_flush()
def debug_read_timestamp(space):
return space.newint(rtimer.read_timestamp())
def debug_get_timestamp_unit(space):
unit = rtimer.get_timestamp_unit()
if unit == rtimer.UNIT_TSC:
unit_str = 'tsc'
elif unit == rtimer.UNIT_NS:
unit_str = 'ns'
elif unit == rtimer.UNIT_QUERY_PERFORMANCE_COUNTER:
unit_str = 'QueryPerformanceCounter'
else:
unit_str = 'UNKNOWN(%d)' % unit
return space.newtext(unit_str)
|