[pypy-svn] pypy jit-lsprofile: use a faster timer. Seems in this variant to still not be any faster than
cfbolz
commits-noreply at bitbucket.org
Tue Jan 4 17:29:04 CET 2011
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: jit-lsprofile
Changeset: r40389:8e1ffe35c163
Date: 2011-01-04 17:15 +0100
http://bitbucket.org/pypy/pypy/changeset/8e1ffe35c163/
Log: use a faster timer. Seems in this variant to still not be any faster
than time.time. probably need to use the assembler version
diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py
--- a/pypy/module/_lsprof/interp_lsprof.py
+++ b/pypy/module/_lsprof/interp_lsprof.py
@@ -1,3 +1,4 @@
+import py
from pypy.interpreter.baseobjspace import (W_Root, ObjSpace, Wrappable,
Arguments)
@@ -6,8 +7,22 @@
from pypy.interpreter.gateway import interp2app, NoneNotWrapped
from pypy.interpreter.function import Method, Function
from pypy.rlib import jit
+from pypy.rpython.lltypesystem import rffi
+from pypy.tool.autopath import pypydir
+
import time, sys
+# timer
+
+eci = rffi.ExternalCompilationInfo(
+ include_dirs = [str(py.path.local(pypydir).join('translator', 'c'))],
+ includes=["src/timer.h"],
+ separate_module_sources = [' '],
+ )
+read_timestamp_double = rffi.llexternal(
+ 'pypy_read_timestamp_double', [], rffi.DOUBLE,
+ compilation_info=eci, _nowrapper=True)
+
class W_StatsEntry(Wrappable):
def __init__(self, space, frame, callcount, reccallcount, tt, it,
w_sublist):
@@ -213,7 +228,7 @@
if self.w_callable:
space = self.space
return space.float_w(space.call_function(self.w_callable))
- return time.time()
+ return read_timestamp_double()
def enable(self, space, w_subcalls=NoneNotWrapped,
w_builtins=NoneNotWrapped):
diff --git a/pypy/translator/c/src/timer.h b/pypy/translator/c/src/timer.h
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/timer.h
@@ -0,0 +1,42 @@
+#ifndef PYPY_TIMER_H
+#define PYPY_TIMER_H
+
+/* XXX Some overlap with the stuff in debug_print
+ */
+
+/* prototypes */
+double pypy_read_timestamp_double(void);
+
+#ifndef PYPY_NOT_MAIN_FILE
+/* implementations */
+
+# ifdef _WIN32
+ double pypy_read_timestamp_double(void) {
+ long long timestamp;
+ long long scale;
+ QueryPerformanceCounter((LARGE_INTEGER*)&(timestamp));
+ QueryPerformanceFrequency((LARGE_INTEGER*)&(scale));
+ return ((double)timestamp) / scale;
+ }
+
+# else
+# include <time.h>
+# include <sys/time.h>
+
+ double pypy_read_timestamp_double(void)
+ {
+# ifdef CLOCK_THREAD_CPUTIME_ID
+ struct timespec tspec;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tspec);
+ return ((double)tspec.tv_sec) + ((double)tspec.tv_nsec) / 1e9;
+# else
+ /* argh, we don't seem to have clock_gettime(). Bad OS. */
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return ((double)tv.tv_sec) + ((double)tv.tv_usec) / 1e6;
+# endif
+ }
+
+# endif
+#endif
+#endif
diff --git a/pypy/module/_lsprof/test/test_cprofile.py b/pypy/module/_lsprof/test/test_cprofile.py
--- a/pypy/module/_lsprof/test/test_cprofile.py
+++ b/pypy/module/_lsprof/test/test_cprofile.py
@@ -1,6 +1,14 @@
import py
from pypy.conftest import gettestobjspace, option
+def test_timer():
+ from pypy.module._lsprof.interp_lsprof import read_timestamp_double
+ import time
+ t1 = read_timestamp_double()
+ for i in range(1000000): pass
+ t2 = read_timestamp_double()
+ assert t2 - t1 > 0.01 # very approxiamte test, but well
+
class AppTestCProfile(object):
keywords = {}
More information about the Pypy-commit
mailing list