[pypy-commit] pypy default: Issue #2035

arigo noreply at buildbot.pypy.org
Sat May 23 10:33:17 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r77499:e7474795564a
Date: 2015-05-23 10:30 +0200
http://bitbucket.org/pypy/pypy/changeset/e7474795564a/

Log:	Issue #2035

	Introduce and use have_debug_prints_for().

diff --git a/rpython/jit/backend/llsupport/assembler.py b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -6,7 +6,7 @@
     ConstInt, BoxInt, AbstractFailDescr)
 from rpython.jit.metainterp.resoperation import ResOperation, rop
 from rpython.rlib import rgc
-from rpython.rlib.debug import (debug_start, debug_stop, have_debug_prints,
+from rpython.rlib.debug import (debug_start, debug_stop, have_debug_prints_for,
                                 debug_print)
 from rpython.rlib.rarithmetic import r_uint
 from rpython.rlib.objectmodel import specialize, compute_unique_id
@@ -120,9 +120,7 @@
             # if self._debug is already set it means that someone called
             # set_debug by hand before initializing the assembler. Leave it
             # as it is
-            debug_start('jit-backend-counts')
-            self.set_debug(have_debug_prints())
-            debug_stop('jit-backend-counts')
+            self.set_debug(have_debug_prints_for('jit-backend-counts'))
         # when finishing, we only have one value at [0], the rest dies
         self.gcmap_for_finish = lltype.malloc(jitframe.GCMAP, 1,
                                               flavor='raw',
diff --git a/rpython/jit/metainterp/warmstate.py b/rpython/jit/metainterp/warmstate.py
--- a/rpython/jit/metainterp/warmstate.py
+++ b/rpython/jit/metainterp/warmstate.py
@@ -4,7 +4,7 @@
 from rpython.jit.codewriter import support, heaptracker, longlong
 from rpython.jit.metainterp import history
 from rpython.rlib.debug import debug_start, debug_stop, debug_print
-from rpython.rlib.debug import have_debug_prints
+from rpython.rlib.debug import have_debug_prints_for
 from rpython.rlib.jit import PARAMETERS
 from rpython.rlib.nonconst import NonConstant
 from rpython.rlib.objectmodel import specialize, we_are_translated, r_dict
@@ -639,7 +639,7 @@
                        'disabled, no debug_print)' % drivername)
             #
             def get_location_str(greenkey):
-                if not have_debug_prints():
+                if not have_debug_prints_for("jit-"):
                     return missing
                 greenargs = unwrap_greenkey(greenkey)
                 fn = support.maybe_on_top_of_llinterp(rtyper, get_location_ptr)
diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -141,10 +141,16 @@
     # and False if they would not have any effect.
     return True
 
+def have_debug_prints_for(category_prefix):
+    # returns True if debug prints are enabled for at least some
+    # category strings starting with "prefix" (must be a constant).
+    assert len(category_prefix) > 0
+    return True
+
 class Entry(ExtRegistryEntry):
-    _about_ = have_debug_prints
+    _about_ = have_debug_prints, have_debug_prints_for
 
-    def compute_result_annotation(self):
+    def compute_result_annotation(self, s_prefix=None):
         from rpython.annotator import model as annmodel
         t = self.bookkeeper.annotator.translator
         if t.config.translation.log:
@@ -157,6 +163,12 @@
         t = hop.rtyper.annotator.translator
         hop.exception_cannot_occur()
         if t.config.translation.log:
+            if hop.args_v:
+                [c_prefix] = hop.args_v
+                assert len(c_prefix.value) > 0
+                args = [hop.inputconst(lltype.Void, c_prefix.value)]
+                return hop.genop('have_debug_prints_for', args,
+                                 resulttype=lltype.Bool)
             return hop.genop('have_debug_prints', [], resulttype=lltype.Bool)
         else:
             return hop.inputconst(lltype.Bool, False)
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -796,6 +796,13 @@
     def OP_DEBUG_STOP(self, op):
         return self._op_debug('PYPY_DEBUG_STOP', op.args[0])
 
+    def OP_HAVE_DEBUG_PRINTS_FOR(self, op):
+        arg = op.args[0]
+        assert isinstance(arg, Constant) and isinstance(arg.value, str)
+        string_literal = c_string_constant(arg.value)
+        return '%s = pypy_have_debug_prints_for(%s);' % (
+            self.expr(op.result), string_literal)
+
     def OP_DEBUG_ASSERT(self, op):
         return 'RPyAssert(%s, %s);' % (self.expr(op.args[0]),
                                        c_string_constant(op.args[1].value))
diff --git a/rpython/translator/c/src/debug_print.c b/rpython/translator/c/src/debug_print.c
--- a/rpython/translator/c/src/debug_print.c
+++ b/rpython/translator/c/src/debug_print.c
@@ -138,6 +138,7 @@
 
 static unsigned char startswithoneof(const char *str, const char *substr)
 {
+    /* any([str.startswith(x) for x in substr.split(',')]) */
   const char *p = str;
   for (; *substr; substr++)
     {
@@ -154,6 +155,23 @@
   return p != NULL;
 }
 
+static long oneofstartswith(const char *str, const char *substr)
+{
+    /* any([x.startswith(substr) for x in str.split(',')]) */
+    const char *p = substr;
+    for (; *str; str++) {
+        if (p) {
+            if (*p++ != *str)
+                p = NULL;   /* mismatch */
+            else if (*p == '\0')
+                return 1;   /* full substring match */
+        }
+        if (*str == ',')
+            p = substr;     /* restart looking */
+    }
+    return 0;
+}
+
 #if defined(_MSC_VER) || defined(__MINGW32__)
 #define PYPY_LONG_LONG_PRINTF_FORMAT "I64"
 #else
@@ -199,3 +217,13 @@
     display_startstop("", "}", category, debug_start_colors_2);
   pypy_have_debug_prints >>= 1;
 }
+
+long pypy_have_debug_prints_for(const char *category_prefix)
+{
+  pypy_debug_ensure_opened();
+  return (!debug_profile && debug_prefix &&
+          /* if 'PYPYLOG=abc,xyz:-' and prefix=="ab", then return 1 */
+          (oneofstartswith(debug_prefix, category_prefix) ||
+           /* if prefix=="abcdef" and 'PYPYLOG=abc,xyz:-' then return 1 */
+           startswithoneof(category_prefix, debug_prefix)));
+}
diff --git a/rpython/translator/c/src/debug_print.h b/rpython/translator/c/src/debug_print.h
--- a/rpython/translator/c/src/debug_print.h
+++ b/rpython/translator/c/src/debug_print.h
@@ -42,6 +42,7 @@
 RPY_EXTERN void pypy_debug_stop(const char *category);
 RPY_EXTERN long pypy_debug_offset(void);
 RPY_EXTERN void pypy_debug_forked(long original_offset);
+RPY_EXTERN long pypy_have_debug_prints_for(const char *category_prefix);
 
 RPY_EXTERN long pypy_have_debug_prints;
 RPY_EXPORTED FILE *pypy_debug_file;
diff --git a/rpython/translator/c/test/test_standalone.py b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -6,7 +6,8 @@
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rarithmetic import r_longlong
 from rpython.rlib.debug import ll_assert, have_debug_prints, debug_flush
-from rpython.rlib.debug import debug_print, debug_start, debug_stop, debug_offset
+from rpython.rlib.debug import debug_print, debug_start, debug_stop
+from rpython.rlib.debug import debug_offset, have_debug_prints_for
 from rpython.rlib.entrypoint import entrypoint, secondary_entrypoints
 from rpython.rtyper.lltypesystem import lltype
 from rpython.translator.translator import TranslationContext
@@ -350,6 +351,8 @@
             tell = -1
         def entry_point(argv):
             x = "got:"
+            if have_debug_prints_for("my"): x += "M"
+            if have_debug_prints_for("myc"): x += "m"
             debug_start  ("mycat")
             if have_debug_prints(): x += "b"
             debug_print    ("foo", r_longlong(2), "bar", 3)
@@ -387,7 +390,7 @@
         assert 'bok' not in err
         # check with PYPYLOG=:- (means print to stderr)
         out, err = cbuilder.cmdexec("", err=True, env={'PYPYLOG': ':-'})
-        assert out.strip() == 'got:bcda.%d.' % tell
+        assert out.strip() == 'got:Mmbcda.%d.' % tell
         assert 'toplevel' in err
         assert '{mycat' in err
         assert 'mycat}' in err
@@ -402,7 +405,7 @@
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': ':%s' % path})
         size = os.stat(str(path)).st_size
-        assert out.strip() == 'got:bcda.' + str(size) + '.'
+        assert out.strip() == 'got:Mmbcda.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -455,7 +458,7 @@
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': 'myc:%s' % path})
         size = os.stat(str(path)).st_size
-        assert out.strip() == 'got:bda.' + str(size) + '.'
+        assert out.strip() == 'got:Mmbda.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()
@@ -486,7 +489,7 @@
         out, err = cbuilder.cmdexec("", err=True,
                                     env={'PYPYLOG': 'myc,cat2:%s' % path})
         size = os.stat(str(path)).st_size
-        assert out.strip() == 'got:bcda.' + str(size) + '.'
+        assert out.strip() == 'got:Mmbcda.' + str(size) + '.'
         assert not err
         assert path.check(file=1)
         data = path.read()


More information about the pypy-commit mailing list