[pypy-svn] r68994 - in pypy/trunk/pypy: jit/metainterp translator/c/src translator/c/test

arigo at codespeak.net arigo at codespeak.net
Thu Nov 5 18:20:50 CET 2009


Author: arigo
Date: Thu Nov  5 18:20:48 2009
New Revision: 68994

Modified:
   pypy/trunk/pypy/jit/metainterp/logger.py
   pypy/trunk/pypy/jit/metainterp/resume.py
   pypy/trunk/pypy/translator/c/src/debug.h
   pypy/trunk/pypy/translator/c/test/test_standalone.py
Log:
Fix the debugging logic to include nested subsections
even if the parent section was disabled.


Modified: pypy/trunk/pypy/jit/metainterp/logger.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/logger.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/logger.py	Thu Nov  5 18:20:48 2009
@@ -12,8 +12,6 @@
         self.guard_number=guard_number
 
     def log_loop(self, inputargs, operations, number=0, type=None):
-        if not have_debug_prints():
-            return
         if type is None:
             debug_start("jit-log-noopt-loop")
             self._log_operations(inputargs, operations)
@@ -26,8 +24,6 @@
             debug_stop("jit-log-opt-loop")
 
     def log_bridge(self, inputargs, operations, number=-1):
-        if not have_debug_prints():
-            return
         if number == -1:
             debug_start("jit-log-noopt-bridge")
             self._log_operations(inputargs, operations)

Modified: pypy/trunk/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/resume.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/resume.py	Thu Nov  5 18:20:48 2009
@@ -257,8 +257,7 @@
         self._number_virtuals(liveboxes)
 
         storage.rd_consts = self.memo.consts
-        if have_debug_prints():
-            dump_storage(storage, liveboxes)
+        dump_storage(storage, liveboxes)
         return liveboxes[:]
 
     def _number_virtuals(self, liveboxes):
@@ -431,27 +430,28 @@
     "For profiling only."
     from pypy.rlib.objectmodel import compute_unique_id
     debug_start("jit-resume")
-    debug_print('Log storage', compute_unique_id(storage))
-    frameinfo = storage.rd_frame_info_list
-    while frameinfo is not None:
-        try:
-            jitcodename = frameinfo.jitcode.name
-        except AttributeError:
-            jitcodename = str(compute_unique_id(frameinfo.jitcode))
-        debug_print('\tjitcode/pc', jitcodename,
-                    frameinfo.pc, frameinfo.exception_target,
-                    'at', compute_unique_id(frameinfo))
-        frameinfo = frameinfo.prev
-    numb = storage.rd_numb
-    while numb is not None:
-        debug_print('\tnumb', str([untag(i) for i in numb.nums]),
-                    'at', compute_unique_id(numb))
-        numb = numb.prev
-    for const in storage.rd_consts:
-        debug_print('\tconst', const.repr_rpython())
-    for box in liveboxes:
-        debug_print('\tbox', box.repr_rpython())
-    if storage.rd_virtuals is not None:
-        for virtual in storage.rd_virtuals:
-            virtual.debug_prints()
+    if have_debug_prints():
+        debug_print('Log storage', compute_unique_id(storage))
+        frameinfo = storage.rd_frame_info_list
+        while frameinfo is not None:
+            try:
+                jitcodename = frameinfo.jitcode.name
+            except AttributeError:
+                jitcodename = str(compute_unique_id(frameinfo.jitcode))
+            debug_print('\tjitcode/pc', jitcodename,
+                        frameinfo.pc, frameinfo.exception_target,
+                        'at', compute_unique_id(frameinfo))
+            frameinfo = frameinfo.prev
+        numb = storage.rd_numb
+        while numb is not None:
+            debug_print('\tnumb', str([untag(i) for i in numb.nums]),
+                        'at', compute_unique_id(numb))
+            numb = numb.prev
+        for const in storage.rd_consts:
+            debug_print('\tconst', const.repr_rpython())
+        for box in liveboxes:
+            debug_print('\tbox', box.repr_rpython())
+        if storage.rd_virtuals is not None:
+            for virtual in storage.rd_virtuals:
+                virtual.debug_prints()
     debug_stop("jit-resume")

Modified: pypy/trunk/pypy/translator/c/src/debug.h
==============================================================================
--- pypy/trunk/pypy/translator/c/src/debug.h	(original)
+++ pypy/trunk/pypy/translator/c/src/debug.h	Thu Nov  5 18:20:48 2009
@@ -21,12 +21,12 @@
 
 
 /* macros used by the generated code */
-#define PYPY_HAVE_DEBUG_PRINTS    (pypy_ignoring_nested_prints ? 0 : \
-                                   (pypy_debug_ensure_opened(), 1))
+#define PYPY_HAVE_DEBUG_PRINTS    (pypy_have_debug_prints & 1 ? \
+                                   (pypy_debug_ensure_opened(), 1) : 0)
 #define PYPY_DEBUG_FILE           pypy_debug_file
 #define PYPY_DEBUG_START(cat)     pypy_debug_start(cat)
 #define PYPY_DEBUG_STOP(cat)      pypy_debug_stop(cat)
-#define OP_HAVE_DEBUG_PRINTS(r)   r = !pypy_ignoring_nested_prints
+#define OP_HAVE_DEBUG_PRINTS(r)   r = (pypy_have_debug_prints & 1)
 
 
 /************************************************************/
@@ -36,7 +36,7 @@
 void pypy_debug_start(const char *category);
 void pypy_debug_stop(const char *category);
 
-extern int pypy_ignoring_nested_prints;
+extern long pypy_have_debug_prints;
 extern FILE *pypy_debug_file;
 
 
@@ -45,7 +45,7 @@
 #ifndef PYPY_NOT_MAIN_FILE
 #include <string.h>
 
-int pypy_ignoring_nested_prints = 0;
+long pypy_have_debug_prints = -1;
 FILE *pypy_debug_file = NULL;
 static bool_t debug_ready = 0;
 static bool_t debug_profile = 0;
@@ -139,39 +139,30 @@
 void pypy_debug_start(const char *category)
 {
   pypy_debug_ensure_opened();
-  if (debug_profile)
-    {
-      /* profiling version */
-      pypy_ignoring_nested_prints++;    /* disable nested debug_print */
-    }
-  else
+  /* Enter a nesting level.  Nested debug_prints are disabled by default
+     because the following left shift introduces a 0 in the last bit.
+     Note that this logic assumes that we are never going to nest
+     debug_starts more than 31 levels (63 on 64-bits). */
+  pypy_have_debug_prints <<= 1;
+  if (!debug_profile)
     {
       /* non-profiling version */
-      if (pypy_ignoring_nested_prints > 0)
-        {
-          /* already ignoring the parent section */
-          pypy_ignoring_nested_prints++;
-          return;
-        }
       if (!debug_prefix || !startswith(category, debug_prefix))
         {
           /* wrong section name, or no PYPYLOG at all, skip it */
-          pypy_ignoring_nested_prints = 1;
           return;
         }
+      /* else make this subsection active */
+      pypy_have_debug_prints |= 1;
     }
   display_startstop("{", "", category, debug_start_colors_1);
 }
 
 void pypy_debug_stop(const char *category)
 {
-  if (pypy_ignoring_nested_prints > 0)
-    {
-      pypy_ignoring_nested_prints--;
-      if (!debug_profile)
-        return;
-    }
-  display_startstop("", "}", category, debug_start_colors_2);
+  if (debug_profile | (pypy_have_debug_prints & 1))
+    display_startstop("", "}", category, debug_start_colors_2);
+  pypy_have_debug_prints >>= 1;
 }
 
 #endif /* PYPY_NOT_MAIN_FILE */

Modified: pypy/trunk/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/trunk/pypy/translator/c/test/test_standalone.py	Thu Nov  5 18:20:48 2009
@@ -353,15 +353,15 @@
         path = udir.join('test_debug_xxx_cat.log')
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': 'cat:%s' % path})
-        assert out.strip() == 'got:a.'
+        assert out.strip() == 'got:ca.'
         assert not err
         assert path.check(file=1)
         data = path.read()
         assert 'toplevel' in path.read()
         assert 'mycat' not in path.read()
         assert 'foo 2 bar 3' not in path.read()
-        assert 'cat2' not in data      # because it is nested
-        assert 'baz' not in data
+        assert 'cat2' in data
+        assert 'baz' in data
         assert 'bok' not in data
         #
         # finally, check compiling with logging disabled



More information about the Pypy-commit mailing list