Author: Armin Rigo <[email protected]>
Branch: vmprof-review
Changeset: r78848:7acf82e90804
Date: 2015-08-07 12:25 +0200
http://bitbucket.org/pypy/pypy/changeset/7acf82e90804/
Log: Fix the logic here. Previously, all functions being called before
enable() would have a vmprof_unique_id of 0, and this 0 was stored
in the stack.
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
@@ -13,10 +13,10 @@
'error': 'space.fromcache(interp_vmprof.Cache).w_error',
}
- def setup_after_space_initialization(self):
- # Force the __extend__ hacks and method replacements to occur
- # early. Without this, for example, 'PyCode._init_ready' was
- # already found by the annotator to be the original empty
- # method, and the annotator doesn't notice that interp_vmprof.py
- # (loaded later) replaces this method.
- import pypy.module._vmprof.interp_vmprof
+
+# Force the __extend__ hacks and method replacements to occur
+# early. Without this, for example, 'PyCode._init_ready' was
+# already found by the annotator to be the original empty
+# method, and the annotator doesn't notice that interp_vmprof.py
+# (loaded later) replaces this method.
+import pypy.module._vmprof.interp_vmprof
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
@@ -27,38 +27,38 @@
self._code_classes = set()
self._gather_all_code_objs = lambda: None
self._cleanup_()
+ if sys.maxint == 2147483647:
+ self._code_unique_id = 0 # XXX this is wrong, it won't work on
32bit
+ else:
+ self._code_unique_id = 0x7000000000000000
def _cleanup_(self):
self.is_enabled = False
self.fileno = -1
self._current_codes = None
- if sys.maxint == 2147483647:
- self._code_unique_id = 0 # XXX this is wrong, it won't work on
32bit
- else:
- self._code_unique_id = 0x7000000000000000
@specialize.argtype(1)
def register_code(self, code, full_name_func):
"""Register the code object. Call when a new code object is made.
"""
- if self.is_enabled and code._vmprof_unique_id == 0:
+ if code._vmprof_unique_id == 0:
uid = self._code_unique_id + 1
code._vmprof_unique_id = uid
self._code_unique_id = uid
- self._write_code_registration(uid, full_name_func(code))
+ if self.is_enabled:
+ self._write_code_registration(uid, full_name_func(code))
@specialize.argtype(1)
def get_unique_id(self, code):
"""Return the internal unique ID of a code object. Can only be
called after register_code(). Call this in the jitdriver's
- method 'get_unique_id(*greenkey)'. Always returns 0 if we
- didn't call register_code_object_class() on the class.
+ method 'get_unique_id(*greenkey)'. The wrapper from __init__.py
+ always returns 0 if we didn't call register_code_object_class()
+ on the class.
"""
uid = code._vmprof_unique_id
- if uid == 0:
- uid = self._code_unique_id + 1
- code._vmprof_unique_id = uid
- self._code_unique_id = uid
+ # 'uid == 0' can occur here if the code object was prebuilt,
+ # or if register_code() was not called for another reason.
return uid
def register_code_object_class(self, CodeClass, full_name_func):
@@ -91,8 +91,9 @@
def gather_all_code_objs():
all_code_objs = rgc.do_get_objects(try_cast_to_code)
for code in all_code_objs:
- uid = self.get_unique_id(code)
- self._write_code_registration(uid, full_name_func(code))
+ uid = code._vmprof_unique_id
+ if uid != 0:
+ self._write_code_registration(uid, full_name_func(code))
prev()
# make a chained list of the gather() functions for all
# the types of code objects
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit