Author: justi9
Date: 2007-10-13 10:17:34 -0400 (Sat, 13 Oct 2007)
New Revision: 1039
Modified:
mgmt/cumin/bin/cumin-test
mgmt/cumin/python/wooly/devel.py
Log:
More profiling improvements. Adds a max param to the benchmark
harness. Fixes profile dumps.
Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test 2007-10-13 02:49:17 UTC (rev 1038)
+++ mgmt/cumin/bin/cumin-test 2007-10-13 14:17:34 UTC (rev 1039)
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import sys, profile, pstats
+import sys
from time import time
from wooly.devel import BenchmarkHarness
from wooly.server import WebServer
@@ -23,7 +23,7 @@
return args
-def do_main(port, debug=True, bench=False, demodata=True):
+def do_main(port, bench_hits, debug=True, demodata=True):
model = CuminModel()
app = Cumin(model)
@@ -36,9 +36,9 @@
if debug or bench:
app.enable_debug()
- if bench:
+ if bench_hits:
harness = BenchmarkHarness(app)
- harness.run()
+ harness.run(bench_hits)
else:
server = WebServer(app, port)
server.run()
@@ -49,27 +49,36 @@
in_port = int(args.get("port", 9090))
in_profile = "profile" in args
in_debug = "no-debug" not in args
- in_bench = "bench" in args
+ in_bench = "bench" in args and int(args.get("bench", None) or
200) or 0
in_demodata = "no-demo-data" not in args
- stats_file = "/tmp/cumin-test-stats-%i" % time()
+ if in_profile:
+ from profile import Profile
+ from pstats import Stats
- if in_profile:
- try:
- code = "do_main(%i, %r, %r, %r)" % \
- (in_port, in_debug, in_bench, in_demodata)
- profile.run(code, stats_file)
+ prof = Profile()
+
+ try:
+ statement = "do_main(%i, %i, %r, %r)" % \
+ (in_port, in_bench, in_debug, in_demodata)
+
+ prof.run(statement)
+
raise KeyboardInterrupt()
except KeyboardInterrupt:
- stats = pstats.Stats(stats_file)
+ file = "/tmp/cumin-test-stats-%i" % time()
- stats.sort_stats("cumulative").print_stats(40)
- stats.sort_stats("time").print_stats(40)
+ prof.dump_stats(file)
+ stats = Stats(file)
+
+ stats.sort_stats("cumulative").print_stats(15)
+ stats.sort_stats("time").print_stats(15)
+
stats.strip_dirs()
else:
try:
- do_main(in_port, in_debug, in_bench, in_demodata)
+ do_main(in_port, in_bench, in_debug, in_demodata)
except KeyboardInterrupt:
pass
Modified: mgmt/cumin/python/wooly/devel.py
===================================================================
--- mgmt/cumin/python/wooly/devel.py 2007-10-13 02:49:17 UTC (rev 1038)
+++ mgmt/cumin/python/wooly/devel.py 2007-10-13 14:17:34 UTC (rev 1039)
@@ -8,7 +8,7 @@
def __init__(self, app):
self.app = app
- def run(self):
+ def run(self, max=-1):
visited = set()
self.app.debug.urls.add("")
count = 0
@@ -31,10 +31,14 @@
bytes = len(html)
millis = (clock() - start) * 1000
- count += 1
print count, bytes, millis, url
+ if count == max:
+ break
+
+ count += 1
+
class DevelPage(Page):
html = """
<html>