[pypy-svn] pypy jit-lsprofile: fix XXX

cfbolz commits-noreply at bitbucket.org
Tue Jan 4 02:18:27 CET 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: jit-lsprofile
Changeset: r40370:3d2f406c050b
Date: 2011-01-04 02:03 +0100
http://bitbucket.org/pypy/pypy/changeset/3d2f406c050b/

Log:	fix XXX

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
@@ -80,7 +80,7 @@
             l_w.append(v.stats(space, factor))
     return space.newlist(l_w)
 
-class ProfilerEntry(object):
+class ProfilerSubEntry(object):
     def __init__(self, frame):
         self.frame = frame
         self.tt = 0
@@ -88,6 +88,25 @@
         self.callcount = 0
         self.recursivecallcount = 0
         self.recursionLevel = 0
+
+    def stats(self, space, parent, factor):
+        w_sse = W_StatsSubEntry(space, self.frame,
+                                self.callcount, self.recursivecallcount,
+                                factor * self.tt, factor * self.it)
+        return space.wrap(w_sse)
+
+    def _stop(self, tt, it):
+        self.recursionLevel -= 1
+        if self.recursionLevel == 0:
+            self.tt += tt
+        else:
+            self.recursivecallcount += 1
+        self.it += it
+        self.callcount += 1
+
+class ProfilerEntry(ProfilerSubEntry):
+    def __init__(self, frame):
+        ProfilerSubEntry.__init__(self, frame)
         self.calls = {}
 
     def stats(self, space, factor):
@@ -112,21 +131,6 @@
                 return subentry
             return None
 
-class ProfilerSubEntry(object):
-    def __init__(self, frame):
-        self.frame = frame
-        self.tt = 0
-        self.it = 0
-        self.callcount = 0
-        self.recursivecallcount = 0
-        self.recursionLevel = 0
-
-    def stats(self, space, parent, factor):
-        w_sse = W_StatsSubEntry(space, self.frame,
-                                self.callcount, self.recursivecallcount,
-                                factor * self.tt, factor * self.it)
-        return space.wrap(w_sse)
-
 class ProfilerContext(object):
     def __init__(self, profobj, entry):
         self.entry = entry
@@ -140,29 +144,16 @@
         self.t0 = profobj.timer()
 
     def _stop(self, profobj, entry):
-        # XXX factor out two pieces of the same code
         tt = profobj.timer() - self.t0
         it = tt - self.subt
         if self.previous:
             self.previous.subt += tt
-        entry.recursionLevel -= 1
-        if entry.recursionLevel == 0:
-            entry.tt += tt
-        else:
-            entry.recursivecallcount += 1
-        entry.it += it
-        entry.callcount += 1
+        entry._stop(tt, it)
         if profobj.subcalls and self.previous:
             caller = jit.hint(self.previous.entry, promote=True)
             subentry = caller._get_or_make_subentry(entry, False)
             if subentry is not None:
-                subentry.recursionLevel -= 1
-                if subentry.recursionLevel == 0:
-                    subentry.tt += tt
-                else:
-                    subentry.recursivecallcount += 1
-                subentry.it += it
-                subentry.callcount += 1
+                subentry._stop(tt, it)
 
 def create_spec(space, w_arg):
     if isinstance(w_arg, Method):


More information about the Pypy-commit mailing list