[pypy-commit] pypy value-profiling: rename valueprof to heapprof

cfbolz pypy.commits at gmail.com
Thu Jan 21 14:54:15 EST 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: value-profiling
Changeset: r81894:b6d1c55ce142
Date: 2016-01-21 18:39 +0100
http://bitbucket.org/pypy/pypy/changeset/b6d1c55ce142/

Log:	rename valueprof to heapprof

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -4,7 +4,7 @@
 from rpython.rlib.rarithmetic import intmask, r_uint
 
 from pypy.interpreter.baseobjspace import W_Root
-from rpython.rlib import valueprof
+from rpython.rlib import heapprof
 from pypy.objspace.std.dictmultiobject import (
     W_DictMultiObject, DictStrategy, ObjectDictStrategy, BaseKeyIterator,
     BaseValueIterator, BaseItemIterator, _never_equal_to_string,
@@ -335,7 +335,7 @@
 class PlainAttribute(AbstractAttribute):
     _immutable_fields_ = ['name', 'index', 'storageindex', 'back',
                           'ever_mutated?', 'can_contain_mutable_cell?']
-    objectmodel.import_from_mixin(valueprof.ValueProf)
+    objectmodel.import_from_mixin(heapprof.HeapProf)
 
     def __init__(self, name, index, back):
         AbstractAttribute.__init__(self, back.space, back.terminator)
@@ -345,7 +345,7 @@
         self.back = back
         self._size_estimate = self.length() * NUM_DIGITS_POW2
         self.ever_mutated = False
-        self.init_valueprof('%s.%s' % (back.terminator.w_cls.name if back.terminator.w_cls else '???', name))
+        self.init_heapprof('%s.%s' % (back.terminator.w_cls.name if back.terminator.w_cls else '???', name))
         # this flag means: at some point there was an instance that used a
         # derivative of this map that had a MutableCell stored into the
         # corresponding field.
@@ -360,7 +360,7 @@
         return self._read_cell(result)
 
     # ____________________________________________________________
-    # methods for ValueProf mixin
+    # methods for HeapProf mixin
     def is_int(self, w_obj):
         from pypy.objspace.std.intobject import W_IntObject
         return type(w_obj) is W_IntObject
diff --git a/rpython/rlib/valueprof.py b/rpython/rlib/heapprof.py
rename from rpython/rlib/valueprof.py
rename to rpython/rlib/heapprof.py
--- a/rpython/rlib/valueprof.py
+++ b/rpython/rlib/heapprof.py
@@ -7,19 +7,19 @@
 SEEN_CONSTANT_CLASS = 'c'
 SEEN_TOO_MUCH = '?'
 
-class ValueProf(object):
+class HeapProf(object):
     """ Some reusal heap profiling infrastructure. Can be used either as a base
     class, or as a mixin.
 
-    The idea of this class is to have one ValueProf instance for many heap
+    The idea of this class is to have one HeapProf instance for many heap
     storage cells that are likely to store the same content. An example is
-    having a ValueProf per field of a specific class. """
+    having a HeapProf per field of a specific class. """
 
-    _immutable_fields_ = ['_vprof_status?']
+    _immutable_fields_ = ['_hprof_status?']
 
     def __init__(self, msg=''):
         # only if you subclass normally
-        self.init_valueprof(msg)
+        self.init_heapprof(msg)
 
 
     # ________________________________________________________________________
@@ -38,70 +38,70 @@
     # ________________________________________________________________________
     # public interface
 
-    def init_valueprof(self, msg=''):
-        """ initialize the profiler. must be called if ValueProf is used as a
+    def init_heapprof(self, msg=''):
+        """ initialize the profiler. must be called if HeapProf is used as a
         mixin upon construction. """
-        self._vprof_status = SEEN_NOTHING
-        self._vprof_value_int = 0
-        self._vprof_value_wref = dead_ref
-        self._vprof_const_cls = None
-        self._vprof_counter = 0
-        self._vprof_msg = msg
+        self._hprof_status = SEEN_NOTHING
+        self._hprof_value_int = 0
+        self._hprof_value_wref = dead_ref
+        self._hprof_const_cls = None
+        self._hprof_counter = 0
+        self._hprof_msg = msg
 
     def see_write(self, w_value):
         """ inform the value profiler of a write."""
-        status = self._vprof_status
+        status = self._hprof_status
         if status == SEEN_TOO_MUCH:
             return
 
         if w_value is None:
-            self._vprof_status = SEEN_TOO_MUCH
+            self._hprof_status = SEEN_TOO_MUCH
             return
 
         if status == SEEN_NOTHING:
             if self.is_int(w_value):
-                self._vprof_value_int = self.get_int_val(w_value)
-                self._vprof_status = SEEN_CONSTANT_INT
+                self._hprof_value_int = self.get_int_val(w_value)
+                self._hprof_status = SEEN_CONSTANT_INT
             else:
                 try:
-                    self._vprof_value_wref = ref(w_value)
+                    self._hprof_value_wref = ref(w_value)
                 except TypeError:
                     # for tests, which really use unwrapped ints in a few places
-                    self._vprof_status = SEEN_TOO_MUCH
+                    self._hprof_status = SEEN_TOO_MUCH
                 else:
-                    self._vprof_const_cls = w_value.__class__
-                    self._vprof_status = SEEN_CONSTANT_OBJ
+                    self._hprof_const_cls = w_value.__class__
+                    self._hprof_status = SEEN_CONSTANT_OBJ
         elif status == SEEN_CONSTANT_INT:
             if self.is_int(w_value):
                 if self.read_constant_int() != self.get_int_val(w_value):
-                    self._vprof_status = SEEN_CONSTANT_CLASS
-                    self._vprof_const_cls = w_value.__class__
+                    self._hprof_status = SEEN_CONSTANT_CLASS
+                    self._hprof_const_cls = w_value.__class__
                 else:
                     return
             else:
-                self._vprof_status = SEEN_TOO_MUCH
+                self._hprof_status = SEEN_TOO_MUCH
         elif status == SEEN_CONSTANT_OBJ:
             prev_obj = self.try_read_constant_obj()
             if prev_obj is not w_value:
                 prev_cls = self.read_constant_cls()
                 if prev_cls is w_value.__class__:
-                    self._vprof_const_cls = prev_cls
-                    self._vprof_status = SEEN_CONSTANT_CLASS
+                    self._hprof_const_cls = prev_cls
+                    self._hprof_status = SEEN_CONSTANT_CLASS
                 else:
-                    self._vprof_status = SEEN_TOO_MUCH
+                    self._hprof_status = SEEN_TOO_MUCH
             else:
                 return
         elif status == SEEN_CONSTANT_CLASS:
             cls = self.read_constant_cls()
             if cls is not w_value.__class__:
-                self._vprof_status = SEEN_TOO_MUCH
+                self._hprof_status = SEEN_TOO_MUCH
         return
 
     def write_necessary(self, w_value):
         """ for an already initialized object check whether writing w_value
         into the object is necessary. it is unnecessary if the profiler knows
         the value is a constant and that constant is equal to w_value. """
-        status = self._vprof_status
+        status = self._hprof_status
         if status == SEEN_TOO_MUCH:
             return True
         # we must have seen something already, because it only makes sense to
@@ -118,17 +118,17 @@
     def can_fold_read_int(self):
         """ returns True if the heap profiler knows that the object stores a
         constant integer. """
-        return self._vprof_status == SEEN_CONSTANT_INT
+        return self._hprof_status == SEEN_CONSTANT_INT
 
     def can_fold_read_obj(self):
         """ returns True if the heap profiler knows that the object stores a
         constant non-integer object. """
-        return self._vprof_status == SEEN_CONSTANT_OBJ
+        return self._hprof_status == SEEN_CONSTANT_OBJ
 
     def class_is_known(self):
         """ returns True if the heap profiler knows the class of the stored
         object. """
-        return self._vprof_status == SEEN_CONSTANT_CLASS
+        return self._hprof_status == SEEN_CONSTANT_CLASS
 
     @jit.elidable
     def read_constant_int(self):
@@ -136,7 +136,7 @@
         must only be called directly after having called
         self.can_fold_read_int() and that returned True. """
         assert self.can_fold_read_int()
-        return self._vprof_value_int
+        return self._hprof_value_int
 
     @jit.elidable
     def try_read_constant_obj(self):
@@ -145,7 +145,7 @@
         returned True. The method may still return False, if the constant
         object was garbage collected in the meantime."""
         assert self.can_fold_read_obj()
-        return self._vprof_value_wref()
+        return self._hprof_value_wref()
 
     @jit.elidable
     def read_constant_cls(self):
@@ -153,5 +153,5 @@
         directly after having called self.class_is_known() and that returned
         True. The returned class is typically used with
         jit.record_exact_class(..., class)"""
-        return self._vprof_const_cls
+        return self._hprof_const_cls
 
diff --git a/rpython/rlib/test/test_valueprof.py b/rpython/rlib/test/test_heapprof.py
rename from rpython/rlib/test/test_valueprof.py
rename to rpython/rlib/test/test_heapprof.py
--- a/rpython/rlib/test/test_valueprof.py
+++ b/rpython/rlib/test/test_heapprof.py
@@ -1,4 +1,4 @@
-from rpython.rlib.valueprof import *
+from rpython.rlib.heapprof import *
 
 class Value(object):
     pass
@@ -11,7 +11,7 @@
         self.intval = val
 
 
-class ValueProf(ValueProf):
+class HeapProf(HeapProf):
     def is_int(self, val):
         return isinstance(val, ValueInt)
 
@@ -20,113 +20,113 @@
 
 
 def test_int():
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(ValueInt(1))
     v.see_write(ValueInt(1))
     v.see_write(ValueInt(1))
     v.see_write(ValueInt(1))
     assert v.read_constant_int() == 1
-    assert v._vprof_status == SEEN_CONSTANT_INT
+    assert v._hprof_status == SEEN_CONSTANT_INT
     v.see_write(ValueInt(2))
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
-    assert v._vprof_const_cls is ValueInt
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_const_cls is ValueInt
     v.see_write(ValueInt(1))
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
-    assert v._vprof_const_cls is ValueInt
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_const_cls is ValueInt
     v.see_write(ValueInt(2))
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
-    assert v._vprof_const_cls is ValueInt
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_const_cls is ValueInt
     v.see_write(ValueInt(3))
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
-    assert v._vprof_const_cls is ValueInt
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_const_cls is ValueInt
 
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(ValueInt(1))
     v.see_write(Value())
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
     v.see_write(Value())
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
 
 def test_obj():
-    v = ValueProf()
+    v = HeapProf()
     value = Value()
-    assert v._vprof_status == SEEN_NOTHING
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(value)
     v.see_write(value)
     v.see_write(value)
     v.see_write(value)
     assert v.try_read_constant_obj() is value
-    assert v._vprof_status == SEEN_CONSTANT_OBJ
+    assert v._hprof_status == SEEN_CONSTANT_OBJ
     v.see_write(ValueInt(2))
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(Value())
     v.see_write(OtherValue())
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
 
 def test_none():
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(None)
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
     v.see_write(None)
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
-    v = ValueProf()
+    v = HeapProf()
     v.see_write(ValueInt(1))
-    assert v._vprof_status == SEEN_CONSTANT_INT
+    assert v._hprof_status == SEEN_CONSTANT_INT
     v.see_write(None)
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
-    v = ValueProf()
+    v = HeapProf()
     v.see_write(Value())
-    assert v._vprof_status == SEEN_CONSTANT_OBJ
+    assert v._hprof_status == SEEN_CONSTANT_OBJ
     v.see_write(None)
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
 def test_known_class():
     import gc
 
-    v = ValueProf()
+    v = HeapProf()
     value = Value()
-    assert v._vprof_status == SEEN_NOTHING
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(value)
-    assert v._vprof_status == SEEN_CONSTANT_OBJ
+    assert v._hprof_status == SEEN_CONSTANT_OBJ
     v.see_write(Value())
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
     v.see_write(OtherValue())
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(value)
-    assert v._vprof_status == SEEN_CONSTANT_OBJ
+    assert v._hprof_status == SEEN_CONSTANT_OBJ
     v.see_write(Value())
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
     v.see_write(ValueInt(5))
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(Value())
-    assert v._vprof_status == SEEN_CONSTANT_OBJ
+    assert v._hprof_status == SEEN_CONSTANT_OBJ
     gc.collect()
     gc.collect()
     gc.collect()
     v.see_write(Value())
-    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._hprof_status == SEEN_CONSTANT_CLASS
     v.see_write(OtherValue())
-    assert v._vprof_status == SEEN_TOO_MUCH
+    assert v._hprof_status == SEEN_TOO_MUCH
 
 def test_write_necessary_int():
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     v.see_write(ValueInt(1))
     res = v.write_necessary(ValueInt(1))
     assert not res
@@ -144,8 +144,8 @@
     assert res
 
 def test_write_not_necessary_obj():
-    v = ValueProf()
-    assert v._vprof_status == SEEN_NOTHING
+    v = HeapProf()
+    assert v._hprof_status == SEEN_NOTHING
     val = Value()
     v.see_write(val)
     res = v.write_necessary(val)


More information about the pypy-commit mailing list