utils/flowmon/bench-all.py
changeset 3981 87b9a5f37324
parent 3979 d135e4bfe043
child 3988 56d6b2ecf538
--- a/utils/flowmon/bench-all.py	Tue May 12 14:51:19 2009 +0100
+++ b/utils/flowmon/bench-all.py	Tue May 12 14:58:13 2009 +0100
@@ -6,7 +6,6 @@
 import re
 import tempfile
 import os
-from xml.dom import minidom
 
 DATA_LIMIT = None
 CPU_LIMIT = None
@@ -31,7 +30,7 @@
     while 1:
         if proc.poll() is not None:
             break
-        time.sleep(1.0)
+        time.sleep(0.2)
         mem = int(open("/proc/%i/statm" % proc.pid, "rt").read().split()[0])*4
         if mem > max_mem:
             max_mem = mem
@@ -41,13 +40,7 @@
     if retval:
         raise RuntimeError("Simulation exited with code %i.\t" % (retval,))
 
-    if os.path.exists(results_fname):
-        results = minidom.parse(results_fname)
-        os.unlink(results_fname)
-    else:
-        results = None
-    
-    return max_mem, (end_time - start_time), results
+    return max_mem, (end_time - start_time), results_fname
 
 
 def main():
@@ -85,38 +78,62 @@
     DATA_LIMIT /= int(int(options.concurrency)*1.25)
     print >> sys.stderr, "Per-process data limit: %.3f GiB (%r)" % (DATA_LIMIT/1024.0/1024.0/1024.0, DATA_LIMIT)
 
-    newdoc = minidom.getDOMImplementation().createDocument(None, "flowmon-bench-results", None)
-    results_root_el = newdoc.documentElement
+    out = open("results.xml", "wt")
+    out.write("<?xml version=\"1.0\" ?>\n")
+
+    # branch
+    proc = subprocess.Popen(["hg", "paths"], stdout=subprocess.PIPE)
+    for line in proc.stdout:
+        if line.startswith('default ='):
+            branch = line.split('=')[1].strip()
+            break
+    proc.stdout.close()
+    proc.wait()
+
+    # revision
+    proc = subprocess.Popen(["hg", "identify"], stdout=subprocess.PIPE)
+    revision = proc.stdout.read().strip()
+    proc.wait()
+    
+    # date
+    date = time.asctime()
 
-    for num_nodes_side in range(3,int(options.num_nodes_side_max) + 1):
-        for run_number in range(10):
-            for enable_monitor in [False, True]:
-                args = ["--NumNodesSide=%i" % num_nodes_side,
-                        "--RunNumber=%i" % run_number,
-                        "--EnableMonitor=%i" % enable_monitor,
-                        "--StopTime=%s" % options.stop_time,
-                        ]
-                try:
-                    max_mem, duration, results = run_sim(args)
-                except RuntimeError, ex:
-                    print >> sys.stderr, "Error running simulation %r: %s" % (args, ex)
-                    continue
-                simulation_el = results_root_el.appendChild(newdoc.createElement('simulation'))
+    out.write("<results branch=%r revision=%r date=%r>\n" % (branch, revision, date))
+    try:
+        for num_nodes_side in range(3,int(options.num_nodes_side_max) + 1):
+            for run_number in range(10):
+                for enable_monitor in [False, True]:
+                    args = ["--NumNodesSide=%i" % num_nodes_side,
+                            "--RunNumber=%i" % run_number,
+                            "--EnableMonitor=%i" % enable_monitor,
+                            "--StopTime=%s" % options.stop_time,
+                            ]
+                    try:
+                        max_mem, duration, results_fname = run_sim(args)
+                    except RuntimeError, ex:
+                        print >> sys.stderr, "Error running simulation %r: %s" % (args, ex)
+                        continue
 
-                simulation_el.setAttribute("num-nodes-side", str(num_nodes_side))
-                simulation_el.setAttribute("run-number", str(run_number))
-                simulation_el.setAttribute("enable-monitor", str(enable_monitor))
-                simulation_el.setAttribute("max-memory", str(max_mem))
-                simulation_el.setAttribute("cpu-time", str(duration))
-
-                if enable_monitor:
-                    simulation_el.appendChild(results.documentElement.cloneNode(True))
-
-    out = open("results.xml", "wt")
-    newdoc.writexml(out, addindent='  ', newl='\n', encoding='utf-8')
-    out.close()
-
-
+                    if os.path.exists(results_fname):
+                        xml_size = os.stat(results_fname).st_size
+                    else:
+                        xml_size = 0
+                    out.write("  <simulation num-nodes-side=%r run-number=%r enable-monitor=%r"
+                              " max-memory=%r cpu-time=%r xml-file-size=%r>\n"
+                              % (str(num_nodes_side), str(run_number), str(int(enable_monitor)),
+                                 str(max_mem), str(duration), str(xml_size)))
+                    if os.path.exists(results_fname):
+                        res_iter = iter(open(results_fname, "rt"))
+                        # skip the first line
+                        line = res_iter.next()
+                        assert line.startswith("<?xml ")
+                        for line in res_iter:
+                            out.write(4*' ' + line)
+                        os.unlink(results_fname)
+                    out.write("  </simulation>\n")
+    finally:
+        out.write("</results>")
+        out.close()
 
 if __name__ == '__main__':
     main()