[pypy-svn] r34633 - in pypy/dist/pypy: config rpython rpython/lltypesystem translator/c translator/c/src translator/c/test

pedronis at codespeak.net pedronis at codespeak.net
Wed Nov 15 16:46:39 CET 2006


Author: pedronis
Date: Wed Nov 15 16:46:35 2006
New Revision: 34633

Modified:
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/translator/c/database.py
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/src/g_include.h
   pypy/dist/pypy/translator/c/src/main.h
   pypy/dist/pypy/translator/c/test/test_standalone.py
Log:
some support for persistent instrumentation counters (for unix, standalone for now). with a test.



Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Wed Nov 15 16:46:35 2006
@@ -159,6 +159,9 @@
         BoolOption("debug_transform", "Perform the debug transformation",
                    default=False, cmdline="--debug-transform", negation=False),
 
+        BoolOption("instrument", "internal: turn instrumentation on",
+                   default=False, cmdline=None),
+
         # portability options
         BoolOption("vanilla",
                    "Try to be as portable as possible, which is not much",

Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Wed Nov 15 16:46:35 2006
@@ -460,6 +460,9 @@
             ll_exc_type = lltype.cast_pointer(rclass.OBJECTPTR, ll_exc).typeptr
             raise LLFatalError(msg, LLException(ll_exc_type, ll_exc))
 
+    def op_instrument_count(self, ll_tag, ll_label):
+        pass # xxx for now
+
     def op_keepalive(self, value):
         pass
 

Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Wed Nov 15 16:46:35 2006
@@ -402,6 +402,9 @@
     'debug_log_exc':        LLOp(),
     'debug_assert':         LLOp(canfold=True),
     'debug_fatalerror':     LLOp(),
+
+    # __________ instrumentation _________
+    'instrument_count':     LLOp(),
 }
 
     # __________ operations on PyObjects __________

Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Wed Nov 15 16:46:35 2006
@@ -62,6 +62,8 @@
             self.gctransformer = self.gcpolicy.transformerclass(translator)
         self.completed = False
 
+        self.instrument_ncounter = 0
+
     def gettypedefnode(self, T, varlength=1):
         if varlength <= 1:
             varlength = 1   # it's C after all

Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Wed Nov 15 16:46:35 2006
@@ -736,6 +736,13 @@
             msg = 'RPyString_AsString(%s)' % self.expr(msg)
 
         return 'fprintf(stderr, "%%s\\n", %s); abort();' % msg
+
+    def OP_INSTRUMENT_COUNT(self, op):
+        counter_label = op.args[1].value
+        self.db.instrument_ncounter = max(self.db.instrument_ncounter,
+                                          counter_label+1)
+        counter_label = self.expr(op.args[1])
+        return 'INSTRUMENT_COUNT(%s);' % counter_label
             
 
 assert not USESLOTS or '__dict__' not in dir(FunctionCodeGenerator)

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Wed Nov 15 16:46:35 2006
@@ -132,6 +132,7 @@
         if CBuilder.have___thread is None:
             CBuilder.have___thread = check_under_under_thread()
         if not self.standalone:
+            assert not self.config.translation.instrument
             from pypy.translator.c.symboltable import SymbolTable
             # XXX fix symboltable
             #self.symboltable = SymbolTable()
@@ -140,6 +141,8 @@
                                       exports = self.exports,
                                       symboltable = self.symboltable)
         else:
+            if self.config.translation.instrument:
+                defines['INSTRUMENT'] = 1
             if CBuilder.have___thread:
                 if not self.config.translation.no__thread:
                     defines['USE___THREAD'] = 1
@@ -641,6 +644,13 @@
     gen_startupcode(f, database)
 
     f.close()
+
+    if 'INSTRUMENT' in defines:
+        fi = incfilename.open('a')
+        n = database.instrument_ncounter
+        print >>fi, "#define INSTRUMENT_NCOUNTER %d" % n
+        fi.close()
+    
     return filename, sg.getextrafiles()
 
 

Modified: pypy/dist/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/g_include.h	(original)
+++ pypy/dist/pypy/translator/c/src/g_include.h	Wed Nov 15 16:46:35 2006
@@ -30,6 +30,8 @@
 #include "src/float.h"
 #include "src/address.h"
 
+#include "src/instrument.h"
+
 /* optional assembler bits */
 #if defined(__GNUC__) && defined(__i386__)
 #  include "src/asm_gcc_x86.h"

Modified: pypy/dist/pypy/translator/c/src/main.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/main.h	(original)
+++ pypy/dist/pypy/translator/c/src/main.h	Wed Nov 15 16:46:35 2006
@@ -20,6 +20,9 @@
     char *errmsg;
     int i, exitcode;
     RPyListOfString *list;
+
+    instrument_setup();
+
     errmsg = RPython_StartupCode();
     if (errmsg) goto error;
 

Modified: pypy/dist/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_standalone.py	Wed Nov 15 16:46:35 2006
@@ -1,7 +1,10 @@
+import py
+import sys, os
+
 from pypy.translator.translator import TranslationContext
 from pypy.translator.c.genc import CStandaloneBuilder
 from pypy.annotation.listdef import s_list_of_strings
-import os
+from pypy.tool.udir import udir
 
 
 def test_hello_world():
@@ -47,3 +50,40 @@
                            '''argument lengths: [2, 5]\n''')
     # NB. RPython has only str, not repr, so str() on a list of strings
     # gives the strings unquoted in the list
+
+def test_counters():
+    if sys.platform != 'linux2':
+        py.test.skip("instrument counters support is unix only for now")
+    from pypy.rpython.lltypesystem import lltype
+    from pypy.rpython.lltypesystem.lloperation import llop
+    def entry_point(argv):
+        llop.instrument_count(lltype.Void, 'test', 2)
+        llop.instrument_count(lltype.Void, 'test', 1)
+        llop.instrument_count(lltype.Void, 'test', 1)
+        llop.instrument_count(lltype.Void, 'test', 2)
+        llop.instrument_count(lltype.Void, 'test', 1)        
+        return 0
+    t = TranslationContext()
+    t.config.translation.instrument = True
+    t.buildannotator().build_types(entry_point, [s_list_of_strings])
+    t.buildrtyper().specialize()
+
+    cbuilder = CStandaloneBuilder(t, entry_point, config=t.config) # xxx
+    cbuilder.generate_source()
+    cbuilder.compile()
+
+    counters_fname = udir.join("_counters_")
+    os.putenv('_INSTRUMENT_COUNTERS', str(counters_fname))
+    try:
+        data = cbuilder.cmdexec()
+    finally:
+        os.unsetenv('_INSTRUMENT_COUNTERS')
+
+    f = counters_fname.open('rb')
+    counters_data = f.read()
+    f.close()
+
+    import struct
+    counters = struct.unpack("LLL", counters_data)
+
+    assert counters == (0,3,2)



More information about the Pypy-commit mailing list