Author: Antonio Cuni <[email protected]>
Branch: gc-hooks
Changeset: r94347:0803e12ba2c3
Date: 2018-04-16 11:37 +0200
http://bitbucket.org/pypy/pypy/changeset/0803e12ba2c3/
Log: expose rtimer.get_timestamp_unit to applevel, for the same
motivations as the previous commit
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -83,6 +83,7 @@
'debug_print_once' : 'interp_debug.debug_print_once',
'debug_flush' : 'interp_debug.debug_flush',
'debug_read_timestamp' : 'interp_debug.debug_read_timestamp',
+ 'debug_get_timestamp_unit' : 'interp_debug.debug_get_timestamp_unit',
'builtinify' : 'interp_magic.builtinify',
'hidden_applevel' : 'interp_magic.hidden_applevel',
'get_hidden_tb' : 'interp_magic.get_hidden_tb',
diff --git a/pypy/module/__pypy__/interp_debug.py
b/pypy/module/__pypy__/interp_debug.py
--- a/pypy/module/__pypy__/interp_debug.py
+++ b/pypy/module/__pypy__/interp_debug.py
@@ -2,7 +2,6 @@
from rpython.rlib import debug, jit
from rpython.rlib import rtimer
-
@jit.dont_look_inside
@unwrap_spec(category='text')
def debug_start(space, category):
@@ -32,3 +31,11 @@
def debug_read_timestamp(space):
return space.newint(rtimer.read_timestamp())
+
+def debug_get_timestamp_unit(space):
+ unit = rtimer.get_timestamp_unit()
+ try:
+ unit_str = rtimer.UNITS[unit]
+ except IndexError:
+ unit_str = 'UNKNOWN(%d)' % unit
+ return space.newtext(unit_str)
diff --git a/pypy/module/__pypy__/test/test_debug.py
b/pypy/module/__pypy__/test/test_debug.py
--- a/pypy/module/__pypy__/test/test_debug.py
+++ b/pypy/module/__pypy__/test/test_debug.py
@@ -54,3 +54,8 @@
a = debug_read_timestamp()
b = debug_read_timestamp()
assert b > a
+
+ def test_debug_get_timestamp_unit(self):
+ from __pypy__ import debug_get_timestamp_unit
+ unit = debug_get_timestamp_unit()
+ assert unit in ('tsc', 'ns', 'QueryPerformanceCounter')
diff --git a/rpython/rlib/rtimer.py b/rpython/rlib/rtimer.py
--- a/rpython/rlib/rtimer.py
+++ b/rpython/rlib/rtimer.py
@@ -10,8 +10,9 @@
# unit of values returned by read_timestamp. Should be in sync with the ones
# defined in translator/c/debug_print.h
UNIT_TSC = 0
-UNIT_NS = 1
+UNIT_NS = 1 # nanoseconds
UNIT_QUERY_PERFORMANCE_COUNTER = 2
+UNITS = ('tsc', 'ns', 'QueryPerformanceCounter')
def read_timestamp():
# Returns a longlong on 32-bit, and a regular int on 64-bit.
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit