[pypy-svn] r59602 - in pypy/build/benchmem: . testing

xoraxax at codespeak.net xoraxax at codespeak.net
Fri Oct 31 19:11:11 CET 2008


Author: xoraxax
Date: Fri Oct 31 19:11:11 2008
New Revision: 59602

Modified:
   pypy/build/benchmem/runbench.py
   pypy/build/benchmem/testing/test_benchtool.py
Log:
Added snapshot headers and timestamps.

Modified: pypy/build/benchmem/runbench.py
==============================================================================
--- pypy/build/benchmem/runbench.py	(original)
+++ pypy/build/benchmem/runbench.py	Fri Oct 31 19:11:11 2008
@@ -20,6 +20,7 @@
 
 class BenchRunner:
     SEPBENCH = "=" * 80
+    HEADERSEP = "HEADER"
 
     def __init__(self, executable, logpath, options):
         self.executable = executable
@@ -47,6 +48,12 @@
         print >>self.logstream, "#benchargs=%s" %(args,)
         print >>self.logstream
 
+    def write_internal_header(self, kw):
+        print >>self.logstream, self.HEADERSEP
+        for name, value in kw.items():
+            print >>self.logstream, "#%s=%s" % (name, value)
+        print >>self.logstream
+
     def log(self, *args):
         print " ".join(map(str, args))
 
@@ -225,6 +232,7 @@
     def interact_with_child(self, rec, stdin, stdout):
         while not stdin.closed:
             try:
+                self.write_internal_header({"TS": str(time.time())})
                 rec.snapshot()
             except py.error.ENOENT:
                 break
@@ -268,6 +276,22 @@
 # ================ reading a benchmark log file =======================
 #
 
+def parseheader(stream_iter):
+    kw = {}
+    for lineno, line in stream_iter:
+        if not line.strip():
+            return kw
+        assert line.startswith("#"), line
+        key, value = map(str.strip, line[1:].split("="))
+        kw[key] = value
+
+
+def parse_result(stream, kw, private_only):
+    benchtype = kw.pop('benchtype')
+    chosen_cls = benchtype2class[benchtype]
+    return chosen_cls.parse(stream, kw, private_only)
+
+
 class ResultSet(object):
     def __init__(self, results=None):
         if results is None:
@@ -296,15 +320,6 @@
         self.results.extend(self.yield_results(f, private_only))
         f.close()
 
-    def parseheader(self, stream_iter):
-        kw = {}
-        for lineno, line in stream_iter:
-            if not line.strip():
-                return kw
-            assert line.startswith("#"), line
-            key, value = map(str.strip, line[1:].split("="))
-            kw[key] = value
-
     def yield_results(self, stream, private_only):
         stream_iter = enumerate(stream)
         for lineno, line in stream_iter:
@@ -314,32 +329,32 @@
             else:
                 break
         while 1:
-            kw = self.parseheader(stream_iter)
+            kw = parseheader(stream_iter)
             if kw is None:
                 break
             yield parse_result(stream_iter, kw, private_only)
 
-def parse_result(stream, kw, private_only):
-    benchtype = kw.pop('benchtype')
-    chosen_cls = benchtype2class[benchtype]
-    return chosen_cls.parse(stream, kw, private_only)
-
 class Result(object):
     @classmethod
     def parse(cls, lnstream, kw, private_only):
         snapshots = []
         mappings = []
+        headerkw = {}
         for lineno, line in lnstream:
             line = line.rstrip()
             if line == smaps.SmapsRecorder.SEPSNAPSHOT:
                 if private_only:
-                    snapshots.append(SimpleSnapshot(mappings))
+                    snapshots.append(SimpleSnapshot(mappings, headerkw))
                 else:
-                    snapshots.append(Snapshot(mappings))
+                    snapshots.append(Snapshot(mappings, headerkw))
                 mappings = []
+                headerkw = {}
             elif line == BenchRunner.SEPBENCH:
                 break
             else:
+                if line.startswith(BenchRunner.HEADERSEP):
+                    headerkw.update(parseheader(lnstream))
+                    continue
                 if private_only:
                     mappings.append(smaps.private(line))
                 else:
@@ -464,16 +479,18 @@
         return "private: %d, shared: %d" %(self.private, self.shared)
 
 class Snapshot(Mappings):
-    def __init__(self, mappings):
+    def __init__(self, mappings, headerkw={}):
         assert mappings
+        self.header = headerkw
         Mappings.__init__(self, mappings)
 
     def heap_private(self):
         return self.filter(group=self.HEAP).private
 
 class SimpleSnapshot(object):
-    def __init__(self, privates):
+    def __init__(self, privates, headerkw):
         self.private = sum(privates)
+        self.header = headerkw
 
 #
 # ==============================================================================

Modified: pypy/build/benchmem/testing/test_benchtool.py
==============================================================================
--- pypy/build/benchmem/testing/test_benchtool.py	(original)
+++ pypy/build/benchmem/testing/test_benchtool.py	Fri Oct 31 19:11:11 2008
@@ -58,6 +58,7 @@
     for name, results in resultset.getname2results():
         assert len(results) == 1
         assert len(results[0].snapshots)
+        assert float(results[0].snapshots[0].header['TS']) > 42
 
 def test_pauses():
     tmpdir = py.test.ensuretemp("benchrunner")



More information about the Pypy-commit mailing list