[pypy-commit] pypy vmprof-0.4.4: implement #123, vmprof.get_profile_path and vmprof.is_enabled, test is_enabled

plan_rich pypy.commits at gmail.com
Thu Apr 20 10:03:00 EDT 2017


Author: Richard Plangger <planrichi at gmail.com>
Branch: vmprof-0.4.4
Changeset: r91097:a5a64f8ac679
Date: 2017-04-20 09:54 -0400
http://bitbucket.org/pypy/pypy/changeset/a5a64f8ac679/

Log:	implement #123, vmprof.get_profile_path and vmprof.is_enabled, test
	is_enabled

diff --git a/pypy/module/_vmprof/__init__.py b/pypy/module/_vmprof/__init__.py
--- a/pypy/module/_vmprof/__init__.py
+++ b/pypy/module/_vmprof/__init__.py
@@ -12,6 +12,8 @@
         'enable': 'interp_vmprof.enable',
         'disable': 'interp_vmprof.disable',
         'write_all_code_objects': 'interp_vmprof.write_all_code_objects',
+        'is_enabled': 'interp_vmprof.is_enabled',
+        'get_profile_path': 'interp_vmprof.get_profile_path',
         'VMProfError': 'space.fromcache(interp_vmprof.Cache).w_VMProfError',
     }
 
diff --git a/pypy/module/_vmprof/interp_vmprof.py b/pypy/module/_vmprof/interp_vmprof.py
--- a/pypy/module/_vmprof/interp_vmprof.py
+++ b/pypy/module/_vmprof/interp_vmprof.py
@@ -4,6 +4,7 @@
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.baseobjspace import W_Root
 from rpython.rlib import rvmprof, jit
+from pypy.interpreter.error import oefmt
 
 # ____________________________________________________________
 
@@ -82,3 +83,16 @@
         rvmprof.disable()
     except rvmprof.VMProfError as e:
         raise VMProfError(space, e)
+
+def is_enabled(space):
+    return space.newbool(rvmprof.is_enabled())
+
+def get_profile_path(space):
+    path = rvmprof.get_profile_path(space)
+    if path is None:
+        # profiling is not enabled
+        return space.w_None
+    if path == "":
+        # Indicates an error! Assume platform does not implement the function call
+        raise oefmt(space.w_NotImplementedError, "platform not implemented")
+    return space.newtext(path)
diff --git a/pypy/module/_vmprof/test/test__vmprof.py b/pypy/module/_vmprof/test/test__vmprof.py
--- a/pypy/module/_vmprof/test/test__vmprof.py
+++ b/pypy/module/_vmprof/test/test__vmprof.py
@@ -94,3 +94,12 @@
         raises(_vmprof.VMProfError, _vmprof.enable, 2, 1e300 * 1e300, 0, 0, 0)
         NaN = (1e300*1e300) / (1e300*1e300)
         raises(_vmprof.VMProfError, _vmprof.enable, 2, NaN, 0, 0, 0)
+
+    def test_is_enabled(self):
+        import _vmprof
+        tmpfile = open(self.tmpfilename, 'wb')
+        assert _vmprof.is_enabled() is False
+        _vmprof.enable(tmpfile.fileno(), 0.01, 0, 0, 0)
+        assert _vmprof.is_enabled() is True
+        _vmprof.disable()
+        assert _vmprof.is_enabled() is False
diff --git a/rpython/rlib/rvmprof/__init__.py b/rpython/rlib/rvmprof/__init__.py
--- a/rpython/rlib/rvmprof/__init__.py
+++ b/rpython/rlib/rvmprof/__init__.py
@@ -3,6 +3,7 @@
 from rpython.rlib.rvmprof.rvmprof import vmprof_execute_code, MAX_FUNC_NAME
 from rpython.rlib.rvmprof.rvmprof import _was_registered
 from rpython.rlib.rvmprof.cintf import VMProfPlatformUnsupported
+from rpython.rtyper.lltypesystem import rffi
 
 #
 # See README.txt.
@@ -37,3 +38,22 @@
 
 def disable():
     _get_vmprof().disable()
+
+def is_enabled():
+    vmp = _get_vmprof()
+    return vmp.is_enabled
+
+def get_profile_path(space):
+    vmp = _get_vmprof()
+    if not vmp.is_enabled:
+        return None
+
+    buflen = 4096
+    with rffi.scoped_alloc_buffer(buflen) as buf:
+        length = vmp.cintf.vmprof_get_profile_path(buf, buflen)
+        if length == -1:
+            return ""
+        return rffi.charp2strn(buf, length)
+
+    return None
+
diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -107,6 +107,10 @@
                                   lltype.Signed, compilation_info=eci,
                                   _nowrapper=True)
 
+    vmprof_get_profile_path = rffi.llexternal("vmprof_get_profile_path", [rffi.CCHARP, lltype.Signed],
+                                              lltype.Signed, compilation_info=eci,
+                                              _nowrapper=True)
+
     return CInterface(locals())
 
 
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -178,23 +178,6 @@
     arguments given to the decorated function.
 
     'result_class' is ignored (backward compatibility).
-
-    ====================================
-    TRANSLATION NOTE CALL THIS ONLY ONCE
-    ====================================
-
-    This function can only be called once during translation.
-    It generates a C function called __vmprof_eval_vmprof which is used by
-    the vmprof C source code and is bound as an extern function.
-    This is necessary while walking the native stack.
-    If you see __vmprof_eval_vmprof defined twice during
-    translation, read on:
-
-    To remove this restriction do the following:
-
-    *) Extend the macro IS_VMPROF_EVAL in the vmprof source repo to check several
-       sybmols.
-    *) Give each function provided to this decorator a unique symbol name in C
     """
     if _hack_update_stack_untranslated:
         from rpython.rtyper.annlowlevel import llhelper


More information about the pypy-commit mailing list