[pypy-svn] r58001 - pypy/branch/cross-compilation/pypy/translator/benchmark

fijal at codespeak.net fijal at codespeak.net
Tue Sep 9 13:53:58 CEST 2008


Author: fijal
Date: Tue Sep  9 13:53:57 2008
New Revision: 58001

Modified:
   pypy/branch/cross-compilation/pypy/translator/benchmark/bench_mem.py
   pypy/branch/cross-compilation/pypy/translator/benchmark/microbench_mem.py
Log:
revert usage of py.execnet - it seems not to be the best idea.


Modified: pypy/branch/cross-compilation/pypy/translator/benchmark/bench_mem.py
==============================================================================
--- pypy/branch/cross-compilation/pypy/translator/benchmark/bench_mem.py	(original)
+++ pypy/branch/cross-compilation/pypy/translator/benchmark/bench_mem.py	Tue Sep  9 13:53:57 2008
@@ -91,22 +91,31 @@
 
 SOCK_FILE = '/tmp/bench_mem'
 
-def run_cooperative(f, func_name=None):
+def run_cooperative(func):
     """ The idea is that we fork() and execute the function func in one
     process. In parent process we measure private memory obtained by a process
     when we read anything in pipe. We send back that we did that
     """
-    gw = py.execnet.PopenGateway()
-    if func_name is None:
-        func_name = f.func_name
-    code = py.code.Source(py.code.Source("""
-    import os
-    channel.send(os.getpid())
-    """), py.code.Source(f), py.code.Source(
-    "%s(channel.receive, channel.send)" % func_name))
-    channel = gw.remote_exec(code)
-    pid = channel.receive()
-    return channel.receive, channel.send, pid
+    parentread, childwrite = os.pipe()
+    childread, parentwrite = os.pipe()
+    pid = os.fork()
+    if not pid:
+        os.close(parentread)
+        os.close(parentwrite)
+        try:
+            func(lambda : os.read(childread, 1),
+                 lambda x: os.write(childwrite, x))
+        except (SystemExit, KeyboardInterrupt):
+            pass
+        except:
+            import traceback
+            traceback.print_tb(sys.exc_info()[2])
+        os._exit(1)
+    os.close(childread)
+    os.close(childwrite)
+    return (lambda : os.read(parentread, 1),
+            lambda x: os.write(parentwrite, x),
+            pid)
 
 def smaps_measure_func(pid):
     return parse_smaps_output(open('/proc/%d/smaps' % pid).read())    
@@ -114,10 +123,7 @@
 def measure(measure_func, funcs_to_run):
     results = []
     for num, func in enumerate(funcs_to_run):
-        if isinstance(func, tuple):
-            read, write, pid = run_cooperative(*func)
-        else:
-            read, write, pid = run_cooperative(func)
+        read, write, pid = run_cooperative(func)
         elem = []
         while 1:
             res = read()

Modified: pypy/branch/cross-compilation/pypy/translator/benchmark/microbench_mem.py
==============================================================================
--- pypy/branch/cross-compilation/pypy/translator/benchmark/microbench_mem.py	(original)
+++ pypy/branch/cross-compilation/pypy/translator/benchmark/microbench_mem.py	Tue Sep  9 13:53:57 2008
@@ -53,11 +53,7 @@
     i = 0
     funcs = []
     while i < 10:
-        f = py.code.Source(list_of_instances_with_int, """
-        def f(r, w):
-            list_of_instances_with_int(r, w, %d)
-        """ % coeff)
-        funcs.append((f, 'f'))
+        funcs.append(lambda r, w, coeff=coeff: list_of_instances_with_int(r, w, coeff))
         coeff *= 2
         i += 1
     res = measure(measure_func, funcs)



More information about the Pypy-commit mailing list