Author: Armin Rigo <ar...@tunes.org>
Branch: vmprof
Changeset: r76704:6fd836a1af7b
Date: 2015-04-03 19:17 +0200
http://bitbucket.org/pypy/pypy/changeset/6fd836a1af7b/

Log:    API change: _vmprof.enable() second argument is now measured in
        seconds, given as a float, as customary in Python

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
@@ -134,12 +134,12 @@
         self.fileno = -1
         self.current_codes = []
 
-    def enable(self, space, fileno, period):
+    def enable(self, space, fileno, period_usec):
         if self.is_enabled:
             raise oefmt(space.w_ValueError, "_vmprof already enabled")
         self.fileno = fileno
         self.is_enabled = True
-        self.write_header(fileno, period)
+        self.write_header(fileno, period_usec)
         if not self.ever_enabled:
             if we_are_translated():
                 pypy_vmprof_init()
@@ -148,7 +148,7 @@
         space.register_code_callback(vmprof_register_code)
         if we_are_translated():
             # does not work untranslated
-            res = vmprof_enable(fileno, period, 0,
+            res = vmprof_enable(fileno, period_usec, 0,
                                 lltype.nullptr(rffi.CCHARP.TO), 0)
         else:
             res = 0
@@ -161,11 +161,8 @@
         for code in all_code_objs:
             self.register_code(space, code)
 
-    def write_header(self, fileno, period):
-        if period == -1:
-            period_usec = 1000000 / 100 #  100hz
-        else:
-            period_usec = period
+    def write_header(self, fileno, period_usec):
+        assert period_usec > 0
         b = StringBuilder()
         write_long_to_string_builder(0, b)
         write_long_to_string_builder(3, b)
@@ -217,13 +214,22 @@
     mod_vmprof = space.getbuiltinmodule('_vmprof')
     assert isinstance(mod_vmprof, Module)
     mod_vmprof.vmprof.register_code(space, code)
-        
-@unwrap_spec(fileno=int, period=int)
-def enable(space, fileno, period=-1):
+
+@unwrap_spec(fileno=int, period=float)
+def enable(space, fileno, period=0.01):   # default 100 Hz
     from pypy.module._vmprof import Module
     mod_vmprof = space.getbuiltinmodule('_vmprof')
     assert isinstance(mod_vmprof, Module)
-    mod_vmprof.vmprof.enable(space, fileno, period)
+    #
+    try:
+        period_usec = int(period * 1000000.0 + 0.5)
+        if period_usec <= 0:
+            raise ValueError
+    except (ValueError, OverflowError):
+        raise OperationError(self.w_ValueError,
+                             self.wrap("'period' too large or non positive"))
+    #
+    mod_vmprof.vmprof.enable(space, fileno, period_usec)
 
 def disable(space):
     from pypy.module._vmprof import Module
diff --git a/pypy/module/_vmprof/src/vmprof.c b/pypy/module/_vmprof/src/vmprof.c
--- a/pypy/module/_vmprof/src/vmprof.c
+++ b/pypy/module/_vmprof/src/vmprof.c
@@ -65,6 +65,7 @@
 }
 
 static void prof_header(long period_usec) {
+    // XXX never used here?
     prof_word(0);
     prof_word(3);
     prof_word(0);
@@ -351,8 +352,7 @@
 int vmprof_enable(int fd, long period_usec, int write_header, char *s,
                                  int slen)
 {
-    if (period_usec == -1)
-        period_usec = 1000000 / 100; /* 100hz */
+    assert(period_usec > 0);
     if (open_profile(fd, period_usec, write_header, s, slen) == -1) {
                return -1;
        }
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to