[rhmessaging-commits] rhmessaging commits: r2823 - in mgmt/trunk: mint/bin and 1 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Nov 17 12:06:56 EST 2008


Author: justi9
Date: 2008-11-17 12:06:56 -0500 (Mon, 17 Nov 2008)
New Revision: 2823

Added:
   mgmt/trunk/mint/bin/mint-bench
   mgmt/trunk/mint/python/mint/tools.py
Modified:
   mgmt/trunk/cumin/python/cumin/tools.py
Log:
Add a mint-bench tool; consolidate parsing logic on base commands

Modified: mgmt/trunk/cumin/python/cumin/tools.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/tools.py	2008-11-17 17:02:15 UTC (rev 2822)
+++ mgmt/trunk/cumin/python/cumin/tools.py	2008-11-17 17:06:56 UTC (rev 2823)
@@ -58,8 +58,22 @@
         self.config.init()
 
     def run(self):
-        pass
+        try:
+            opts, args = self.parse(sys.argv)
+        except CommandException, e:
+            print "Error: %s" % e.message
+            e.command.print_help()
+            sys.exit(1)
 
+        if "help" in opts:
+            self.print_help()
+            sys.exit(0)
+
+        self.do_run(opts, args)
+
+    def do_run(self, opts, args):
+        raise Exception("Not implemented")
+
     def main(self):
         self.check()
         self.init()
@@ -406,14 +420,7 @@
         opt = CommandOption(self, "ssl")
         opt.description = "Serve web pages using SSL"
 
-    def run(self):
-        try:
-            opts, args = self.parse(sys.argv)
-        except CommandException, e:
-            print "Error: %s" % e.message
-            e.command.print_help()
-            sys.exit(1)
-
+    def do_run(self, opts, args):
         self.config.load_dict(opts)
 
         self.config.ssl = "ssl" in opts
@@ -469,18 +476,7 @@
         opt.argument = "ADDR"
         opt.description = "Use existing broker at ADDR"
 
-    def run(self):
-        try:
-            opts, args = self.parse(sys.argv)
-        except CommandException, e:
-            print "Error: %s" % e.message
-            e.command.print_help()
-            sys.exit(1)
-
-        if "help" in opts:
-            self.print_help()
-            sys.exit(0)
-
+    def do_run(self, opts, args):
         self.config.load_dict(opts)
 
         if self.config.debug:
@@ -537,18 +533,7 @@
         opt = CommandOption(self, "check-xml")
         opt.description = "Check that page output is well-formed xml"
 
-    def run(self):
-        try:
-            opts, args = self.parse(sys.argv)
-        except CommandException, e:
-            print "Error: %s" % e.message
-            e.command.print_help()
-            sys.exit(1)
-
-        if "help" in opts:
-            self.print_help()
-            sys.exit(0)
-
+    def do_run(self, opts, args):
         self.config.load_dict(opts)
 
         if self.config.debug:

Added: mgmt/trunk/mint/bin/mint-bench
===================================================================
--- mgmt/trunk/mint/bin/mint-bench	                        (rev 0)
+++ mgmt/trunk/mint/bin/mint-bench	2008-11-17 17:06:56 UTC (rev 2823)
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+import sys, os, logging
+
+from mint.tools import MintBenchTool
+
+def do_main():
+    MintBenchTool("mint-bench").main()
+
+def main():
+    root = logging.getLogger("mint")
+    root.setLevel(logging.DEBUG)
+
+    h = logging.StreamHandler()
+    h.setLevel(logging.DEBUG)
+    root.addHandler(h)
+
+    if "--profile" in sys.argv:
+        from profile import Profile
+        from pstats import Stats
+
+        prof = Profile()
+
+        print "Calibrating"
+        
+        biases = list()
+    
+        for i in range(5):
+            bias = prof.calibrate(100000)
+            biases.append(bias)
+            print i, bias
+
+        prof.bias = sum(biases) / float(5)
+
+        print "Using bias %f" % prof.bias
+
+        try:
+	    prof.run("do_main()")
+	except KeyboardInterrupt:
+            pass
+
+        file = "/tmp/cumin-test-stats"
+
+        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:
+        do_main()
+
+if __name__ == "__main__":
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass


Property changes on: mgmt/trunk/mint/bin/mint-bench
___________________________________________________________________
Name: svn:executable
   + *

Added: mgmt/trunk/mint/python/mint/tools.py
===================================================================
--- mgmt/trunk/mint/python/mint/tools.py	                        (rev 0)
+++ mgmt/trunk/mint/python/mint/tools.py	2008-11-17 17:06:56 UTC (rev 2823)
@@ -0,0 +1,86 @@
+import sys, os
+
+from time import sleep
+from parsley.config import *
+from parsley.command import *
+
+from mint import *
+
+class BaseMintTool(Command):
+    def __init__(self, name):
+        super(BaseMintTool, self).__init__(None, name)
+
+        opt = CommandOption(self, "data")
+        opt.argument = "URI"
+        opt.description = "Connect to database at URI"
+
+        opt = CommandOption(self, "log-file")
+        opt.argument = "PATH"
+        opt.description = "Log to file at PATH"
+
+        opt = CommandOption(self, "log-level")
+        opt.argument = "LEVEL"
+        opt.description = "Log messages at or above LEVEL " + \
+            "('debug', 'info', 'warning', 'error')"
+
+        opt = CommandOption(self, "debug")
+        opt.description = "Enable debugging; print logging to console"
+
+    def check(self):
+        if os.getuid() not in (os.stat(__file__).st_uid, 0):
+            print "Error: You have insufficient privileges"
+            sys.exit(1)
+
+    def init(self):
+        super(BaseMintTool, self).init()
+
+        #self.config.init()
+
+    def run(self):
+        pass
+
+    def run(self):
+        try:
+            opts, args = self.parse(sys.argv)
+        except CommandException, e:
+            print "Error: %s" % e.message
+            e.command.print_help()
+            sys.exit(1)
+
+        if "help" in opts:
+            self.print_help()
+            sys.exit(0)
+
+        self.do_run(opts, args)
+
+    def do_run(self, opts, args):
+        raise Exception("Not implemented")
+
+    def main(self):
+        self.check()
+        self.init()
+        self.run()
+
+class MintBenchTool(BaseMintTool):
+    def __init__(self, name):
+        super(MintBenchTool, self).__init__(name)
+
+    def init(self):
+        super(MintBenchTool, self).init()
+
+    def do_run(self, opts, args):
+        ddef = "postgresql://cumin@localhost/cumin"
+        model = MintModel(opts.get("data", ddef), debug=True)
+
+        model.check()
+        model.init()
+        model.start()
+        
+        try:
+            for arg in args[1:]:
+                model.getSession().addBroker(arg)
+
+            while True:
+                sleep(1)
+        finally:
+            model.stop()




More information about the rhmessaging-commits mailing list