Author: justi9
Date: 2007-10-12 21:40:04 -0400 (Fri, 12 Oct 2007)
New Revision: 1036
Modified:
mgmt/cumin/bin/cumin-test
mgmt/cumin/python/wooly/__init__.py
mgmt/cumin/python/wooly/devel.py
mgmt/cumin/python/wooly/server.py
Log:
More cumin-test improvements. Adds a --bench option to run randomly
selected page views in a loop.
Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test 2007-10-12 23:54:47 UTC (rev 1035)
+++ mgmt/cumin/bin/cumin-test 2007-10-13 01:40:04 UTC (rev 1036)
@@ -1,8 +1,13 @@
#!/usr/bin/env python
-import sys
-from cumin import CuminServer
+import sys, profile, pstats
+from wooly.devel import BenchmarkHarness
+from wooly.server import WebServer
+from cumin import *
+from cumin.demo import *
+from cumin.model import *
+
def load_args(argv):
args = dict()
key = None
@@ -10,35 +15,48 @@
for arg in sys.argv:
if arg.startswith("--"):
key = arg[2:]
+ args[key] = None
elif key:
args[key] = arg
key = None
- if key:
- args[key] = None
-
return args
-def main(port, debug=True):
- server = CuminServer(port)
+def do_main(port, debug=True, bench=False, demodata=True):
+ model = CuminModel()
- if debug:
- server.enable_debug()
-
- server.run()
+ app = Cumin(model)
-if __name__ == "__main__":
- args = load_args(sys.argv)
+ if demodata:
+ data = DemoData(model)
+ data.load()
+ data.start_updates()
+
+ if debug or bench:
+ app.enable_debug()
+
+ if bench:
+ harness = BenchmarkHarness(app)
+ harness.run()
+ else:
+ server = WebServer(app, port)
+ server.run()
+
+def main(sargs):
+ args = load_args(sargs)
+
+ in_port = int(args.get("port", 9090))
+ in_debug = True
+ in_profile = "profile" in args
+ in_bench = "bench" in args
+ in_demodata = "no-demo-data" not in args
- port = int(args.get("port", 9090))
-
- if "profile" in args:
- import profile, pstats
+ stats_file = "/tmp/cumin-test-stats"
- stats_file = "/tmp/cumin-test-stats"
-
+ if in_profile:
try:
- code = "main(%i, %r)" % (port, False)
+ code = "do_main(%i, %r, %r, %r)" % \
+ (in_port, False, in_bench, in_demodata)
profile.run(code, stats_file)
raise KeyboardInterrupt()
except KeyboardInterrupt:
@@ -48,11 +66,11 @@
stats.sort_stats("time").print_stats(15)
stats.strip_dirs()
-
- #stats.print_callers("interpolate")
- #stats.print_callees("interpolate")
else:
try:
- main(port)
+ do_main(in_port, in_debug, in_bench, in_demodata)
except KeyboardInterrupt:
pass
+
+if __name__ == "__main__":
+ main(sys.argv)
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-12 23:54:47 UTC (rev 1035)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 01:40:04 UTC (rev 1036)
@@ -2,6 +2,7 @@
from cStringIO import StringIO
from urllib import quote_plus, unquote_plus
from copy import copy
+# XXX use clock instead
from time import time
from datetime import datetime
@@ -325,6 +326,7 @@
def __init__(self, app):
self.app = app
self.sessions = list()
+ self.urls = set()
def add_page(self, page):
if page.parent:
@@ -467,8 +469,13 @@
self.saved_parameters += params
def marshal(self):
- return self.marshal_page() + "?" + self.marshal_url_vars()
+ url = self.marshal_page() + "?" + self.marshal_url_vars()
+ if self.debug:
+ self.app.debug.urls.add(url)
+
+ return url
+
def marshal_page(self):
return self.get_page().name
Modified: mgmt/cumin/python/wooly/devel.py
===================================================================
--- mgmt/cumin/python/wooly/devel.py 2007-10-12 23:54:47 UTC (rev 1035)
+++ mgmt/cumin/python/wooly/devel.py 2007-10-13 01:40:04 UTC (rev 1036)
@@ -1,7 +1,36 @@
import sys, os
+from random import sample
+from time import clock
from wooly import *
+class BenchmarkHarness(object):
+ def __init__(self, app):
+ self.app = app
+
+ def run(self):
+ self.app.debug.urls.add("")
+ count = 0
+
+ while True:
+ url = sample(self.app.debug.urls, 1)[0]
+
+ start = clock()
+
+ session = Session(self.app)
+ session.unmarshal(url)
+
+ page = session.get_page()
+ page.process(session, None)
+
+ html = page.render(session, None)
+
+ bytes = len(html)
+ millis = (clock() - start) * 1000
+ count += 1
+
+ print count, bytes, millis, url
+
class DevelPage(Page):
html = """
<html>
Modified: mgmt/cumin/python/wooly/server.py
===================================================================
--- mgmt/cumin/python/wooly/server.py 2007-10-12 23:54:47 UTC (rev 1035)
+++ mgmt/cumin/python/wooly/server.py 2007-10-13 01:40:04 UTC (rev 1036)
@@ -11,9 +11,6 @@
self.app = app
self.port = port
- def enable_debug(self):
- self.app.enable_debug()
-
def run(self):
server = HTTPServer(("", self.port), self.RequestHandler)