[pypy-svn] r68860 - in pypy/branch/logging2/pypy/translator/c: src test

arigo at codespeak.net arigo at codespeak.net
Fri Oct 30 14:44:40 CET 2009


Author: arigo
Date: Fri Oct 30 14:44:39 2009
New Revision: 68860

Modified:
   pypy/branch/logging2/pypy/translator/c/src/debug.h
   pypy/branch/logging2/pypy/translator/c/test/test_standalone.py
Log:
Add the option to set PYPYLOG to 'prof:filename'.
Document and test it.


Modified: pypy/branch/logging2/pypy/translator/c/src/debug.h
==============================================================================
--- pypy/branch/logging2/pypy/translator/c/src/debug.h	(original)
+++ pypy/branch/logging2/pypy/translator/c/src/debug.h	Fri Oct 30 14:44:39 2009
@@ -1,12 +1,20 @@
 /************************************************************/
  /***  C header subsection: debug_print & related tools    ***/
 
+/* values of the PYPYLOG environment variable:
+
+   (empty)        logging is turned off
+   -              logging goes to stderr
+   filename       logging goes to the given file; overwritten at process start
+   prof:filename  logs only debug_start and debug_stop, not debug_print
+*/
+
 
 /* macros used by the generated code */
-#define PYPY_DEBUG_ENABLED     (pypy_debug_enabled && pypy_debug_is_ready())
+#define PYPY_DEBUG_ENABLED     (pypy_debug_full && pypy_debug_is_ready())
 #define PYPY_DEBUG_FILE        pypy_debug_file
-#define PYPY_DEBUG_START(cat)  if (pypy_debug_enabled) pypy_debug_start(cat)
-#define PYPY_DEBUG_STOP(cat)   if (pypy_debug_enabled) pypy_debug_stop(cat)
+#define PYPY_DEBUG_START(cat)  if (pypy_debug_profiling) pypy_debug_start(cat)
+#define PYPY_DEBUG_STOP(cat)   if (pypy_debug_profiling) pypy_debug_stop(cat)
 
 
 /************************************************************/
@@ -16,7 +24,8 @@
 void pypy_debug_start(const char *category);
 void pypy_debug_stop(const char *category);
 
-extern bool_t pypy_debug_enabled;
+extern bool_t pypy_debug_full;
+extern bool_t pypy_debug_profiling;
 extern FILE *pypy_debug_file;
 
 
@@ -26,7 +35,9 @@
 #include <sys/time.h>
 
 static bool_t pypy_debug_initialized = 0;
-bool_t pypy_debug_enabled = 1;   /* set to 0 if PYPYLOG is not defined */
+bool_t pypy_debug_full = 1;      /* set to 0 if PYPYLOG is not defined
+                                    or starts with 'prof:'             */
+bool_t pypy_debug_profiling = 1; /* set to 0 if PYPYLOG is not defined */
 FILE *pypy_debug_file;
 
 static void pypy_debug_open(void)
@@ -34,6 +45,15 @@
   char *filename = getenv("PYPYLOG");
   if (filename && filename[0])
     {
+      if (filename[0] == 'p' &&
+          filename[1] == 'r' &&
+          filename[2] == 'o' &&
+          filename[3] == 'f' &&
+          filename[4] == ':')
+        {
+          pypy_debug_full = 0;
+          filename += 5;
+        }
       if (filename[0] == '-' && filename[1] == 0)
         pypy_debug_file = stderr;
       else
@@ -43,7 +63,8 @@
     {
       pypy_debug_file = NULL;
     }
-  pypy_debug_enabled = (pypy_debug_file != NULL);
+  pypy_debug_full      &= (pypy_debug_file != NULL);
+  pypy_debug_profiling &= (pypy_debug_file != NULL);
   pypy_debug_initialized = 1;
 }
 
@@ -51,7 +72,7 @@
 {
   if (!pypy_debug_initialized)
     pypy_debug_open();
-  return pypy_debug_enabled;
+  return pypy_debug_full;
 }
 
 
@@ -63,7 +84,9 @@
 static void pypy_debug_category(const char *start, const char *category)
 {
   long long timestamp;
-  if (!pypy_debug_is_ready())
+  if (!pypy_debug_initialized)
+    pypy_debug_open();
+  if (!pypy_debug_profiling)
     return;
   READ_TIMESTAMP(timestamp);
   fprintf(pypy_debug_file, "{%llx} -%s- %s\n", timestamp, start, category);

Modified: pypy/branch/logging2/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/logging2/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/branch/logging2/pypy/translator/c/test/test_standalone.py	Fri Oct 30 14:44:39 2009
@@ -266,11 +266,11 @@
         out, err = cbuilder.cmdexec("", err=True, env={})
         assert not out
         assert not err
-        # check with PYPYLOG defined to an empty string
+        # check with PYPYLOG defined to an empty string (same as undefined)
         out, err = cbuilder.cmdexec("", err=True, env={'PYPYLOG': ''})
         assert not out
         assert not err
-        # check with PYPYLOG=-
+        # check with PYPYLOG=- (means print to stderr)
         out, err = cbuilder.cmdexec("", err=True, env={'PYPYLOG': '-'})
         assert not out
         assert 'mycat' in err
@@ -283,6 +283,15 @@
         assert path.check(file=1)
         assert 'mycat' in path.read()
         assert 'foo 2 bar 3' in path.read()
+        # check with PYPYLOG=prof:somefilename   (only start/stop events)
+        path = udir.join('test_debug_xxx_prof.log')
+        out, err = cbuilder.cmdexec("", err=True,
+                                    env={'PYPYLOG': 'prof:%s' % path})
+        assert not out
+        assert not err
+        assert path.check(file=1)
+        assert 'mycat' in path.read()
+        assert 'foo 2 bar 3' not in path.read()
 
 
 class TestMaemo(TestStandalone):



More information about the Pypy-commit mailing list