[pypy-svn] r59292 - pypy/build/benchmem

fijal at codespeak.net fijal at codespeak.net
Tue Oct 21 12:19:53 CEST 2008


Author: fijal
Date: Tue Oct 21 12:19:51 2008
New Revision: 59292

Added:
   pypy/build/benchmem/report_graphic.py   (contents, props changed)
Modified:
   pypy/build/benchmem/runbench.py
   pypy/build/benchmem/smaps.py
Log:
* A tool for reporting graphs
* A hack that allows to speed up parsing data 3 times, if we want to see
  only private memory consumption


Added: pypy/build/benchmem/report_graphic.py
==============================================================================
--- (empty file)
+++ pypy/build/benchmem/report_graphic.py	Tue Oct 21 12:19:51 2008
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+""" Run: report_graphic [bench_log]
+"""
+
+import sys, py
+import smaps, runbench
+from pylab import plot, show
+
+def main(filename):
+    resultset = runbench.ResultSet()
+    resultset.parse(py.path.local(filename), True)
+    # XXX I'm not sure how to determine a number (optparse maybe...)
+    #     right now, just adjust the number below. Also if we want to
+    #     generate postscript or whatever we would need to do this for
+    #     all anyway
+    name, results = resultset.getname2results()[0]
+    for result in results:
+        lgt = len(result.snapshots)
+        x = [float(i)/lgt for i in range(lgt)]
+        y = [snapshot.private for snapshot in result.snapshots]
+        plot(x, y)
+    show()
+
+if __name__ == '__main__':
+    if len(sys.argv) > 3:
+        print >>sys.stderr, __doc__
+        sys.exit(1)
+    if len(sys.argv) == 2:
+        name = sys.argv[1]
+    else:
+        name = 'bench.log'
+    main(name)

Modified: pypy/build/benchmem/runbench.py
==============================================================================
--- pypy/build/benchmem/runbench.py	(original)
+++ pypy/build/benchmem/runbench.py	Tue Oct 21 12:19:51 2008
@@ -261,9 +261,9 @@
                 l.append(result)
         return ResultSet(l)
 
-    def parse(self, logpath):
+    def parse(self, logpath, private_only=False):
         f = logpath.open()
-        self.results.extend(self.yield_results(f))
+        self.results.extend(self.yield_results(f, private_only))
         f.close()
 
     def parseheader(self, stream_iter):
@@ -275,7 +275,7 @@
             key, value = map(str.strip, line[1:].split("="))
             kw[key] = value
 
-    def yield_results(self, stream):
+    def yield_results(self, stream, private_only):
         stream_iter = enumerate(stream)
         for lineno, line in stream_iter:
             line = line.rstrip()
@@ -287,26 +287,32 @@
             kw = self.parseheader(stream_iter)
             if kw is None:
                 break
-            yield parse_result(stream_iter, kw)
+            yield parse_result(stream_iter, kw, private_only)
 
-def parse_result(stream, kw):
+def parse_result(stream, kw, private_only):
     chosen_cls = benchtype2class[kw.pop('benchtype')]
-    return chosen_cls.parse(stream, kw)
+    return chosen_cls.parse(stream, kw, private_only)
 
 class Result(object):
     @classmethod
-    def parse(cls, lnstream, kw):
+    def parse(cls, lnstream, kw, private_only):
         snapshots = []
         mappings = []
         for lineno, line in lnstream:
             line = line.rstrip()
             if line == smaps.SmapsRecorder.SEPSNAPSHOT:
-                snapshots.append(Snapshot(mappings))
+                if private_only:
+                    snapshots.append(SimpleSnapshot(mappings))
+                else:
+                    snapshots.append(Snapshot(mappings))
                 mappings = []
             elif line == BenchRunner.SEPBENCH:
                 break
             else:
-                mappings.append(smaps.Mapping(line))
+                if private_only:
+                    mappings.append(smaps.private(line))
+                else:
+                    mappings.append(smaps.Mapping(line))
                 continue
         return cls(snapshots, **kw)
 
@@ -355,7 +361,7 @@
             self.mintimings.append((name, min(timing, key=lambda x: x['real'])))
 
     @classmethod
-    def parse(cls, lnstream, kw):
+    def parse(cls, lnstream, kw, private_only=False):
         timings = []
         for lineno, line in lnstream:
             if line.strip() == BenchRunner.SEPBENCH:
@@ -416,6 +422,10 @@
     def heap_private(self):
         return self.filter(group=self.HEAP).private
 
+class SimpleSnapshot(object):
+    def __init__(self, privates):
+        self.private = sum(privates)
+
 #
 # ==============================================================================
 # Option Handling

Modified: pypy/build/benchmem/smaps.py
==============================================================================
--- pypy/build/benchmem/smaps.py	(original)
+++ pypy/build/benchmem/smaps.py	Tue Oct 21 12:19:51 2008
@@ -1,5 +1,6 @@
 import os, sys, re
 import py
+import time
 
 class SmapsRecorder:
     SEPSNAPSHOT = "-"*80
@@ -47,6 +48,11 @@
 #
 # objects gained from reading of the logfile 
 #
+
+def private(line):
+    attrs = line.split()[0].split(',')
+    return int(attrs[4]) + int(attrs[5])
+        
 class Mapping: 
     _attrnames = ("size rss shared_clean shared_dirty "
                   "private_clean private_dirty".split())



More information about the Pypy-commit mailing list