directories: make the profiling behavior of bench_dirnode.py accessible by adding...
authorZooko O'Whielacronx <zooko@zooko.com>
Tue, 7 Jul 2009 03:30:35 +0000 (20:30 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Tue, 7 Jul 2009 03:30:35 +0000 (20:30 -0700)
src/allmydata/test/bench_dirnode.py

index e72fbbc0c6e7a72fc2f65b5bea766725efc8a25b..1d5d5d66680ce983d8d2e827c94d89021e32358e 100644 (file)
@@ -1,4 +1,4 @@
-import hotshot.stats, os, random
+import hotshot.stats, os, random, sys
 
 from pyutil import benchutil, randutil # http://allmydata.org/trac/pyutil
 
@@ -88,13 +88,15 @@ def unpack(N):
 def unpack_and_repack(N):
     return testdirnode._pack_contents(testdirnode._unpack_contents(packstr))
 
+PROF_FILE_NAME="bench_dirnode.prof"
+
 def run_benchmarks(profile=False):
     for (func, initfunc) in [(unpack, init_for_unpack), (pack, init_for_pack), (unpack_and_repack, init_for_unpack)]:
         print "benchmarking %s" % (func,)
-        benchutil.bench(unpack_and_repack, initfunc=init_for_unpack, TOPXP=12, profile=profile, profresults="bench_dirnode.prof")
+        benchutil.bench(unpack_and_repack, initfunc=init_for_unpack, TOPXP=12, profile=profile, profresults=PROF_FILE_NAME)
 
 def print_stats():
-    s = hotshot.stats.load("bench_dirnode.prof")
+    s = hotshot.stats.load(PROF_FILE_NAME)
     s.strip_dirs().sort_stats("time").print_stats(32)
 
 def prof_benchmarks():
@@ -102,6 +104,10 @@ def prof_benchmarks():
     run_benchmarks(profile=True)
 
 if __name__ == "__main__":
-    run_benchmarks()
-    # prof_benchmarks()
-    # print_stats()
+    if '--profile' in sys.argv:
+        if os.path.exists(PROF_FILE_NAME):
+            print "WARNING: profiling results file '%s' already exists -- the profiling results from this run will be added into the profiling results stored in that file and then the sum of them will be printed out after this run."
+        prof_benchmarks()
+        print_stats()
+    else:
+        run_benchmarks()