Author: aconway
Date: Wed Nov 28 07:22:15 2007
New Revision: 599025

URL: http://svn.apache.org/viewvc?rev=599025&view=rev
Log:
src/tests/perftest.cpp:
 - Added help text explaining multi-process use.
 - Fixed bug in multi-process mode, too many threads were started.

Modified:
    incubator/qpid/trunk/qpid/cpp/src/tests/TestOptions.h
    incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/TestOptions.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/TestOptions.h?rev=599025&r1=599024&r2=599025&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/TestOptions.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/TestOptions.h Wed Nov 28 07:22:15 
2007
@@ -34,7 +34,11 @@
 
 struct TestOptions : public qpid::Options
 {
-    TestOptions() : Options("Test Options"), host("localhost"), 
port(TcpAddress::DEFAULT_PORT), clientid("cpp"), help(false)
+    TestOptions(const std::string& helpText_=std::string()) :
+        Options("Test Options"),
+        host("localhost"), port(TcpAddress::DEFAULT_PORT),
+        clientid("cpp"), help(false),
+        helpText(helpText_)
     {
         addOptions()
             ("host,h", optValue(host, "HOST"), "Broker host to connect to")
@@ -49,23 +53,24 @@
         add(log);
     }
 
-    /** As well as parsing, print help & exit if required */
+    /** As well as parsing, throw help message if requested. */
     void parse(int argc, char** argv) {
         try {
             qpid::Options::parse(argc, argv);
         } catch (const std::exception& e) {
-            std::cout << e.what() << std::endl << *this << std::endl;
-            exit(1);
+            std::ostringstream msg;
+            msg << *this << std::endl << std::endl << e.what() << std::endl;
+            throw qpid::Options::Exception(msg.str());
         }
+        qpid::log::Logger::instance().configure(log, argv[0]);
         if (help) {
-            std::cout << *this << std::endl;
-            exit(0);
+            std::ostringstream msg;
+            msg << *this << std::endl << std::endl << helpText << std::endl;
+            throw qpid::Options::Exception(msg.str());
         }
-        trace = log.trace;
-        qpid::log::Logger::instance().configure(log, argv[0]);
     }
 
-    /** Open a connection usin option values */
+    /** Open a connection using option values */
     void open(qpid::client::Connection& connection) {
         connection.open(host, port, username, password, virtualhost);
     }
@@ -77,9 +82,9 @@
     std::string clientid;
     std::string username;
     std::string password;
-    bool trace;
     bool help;
     log::Options log;
+    std::string helpText;
 };
 
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp?rev=599025&r1=599024&r2=599025&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/perftest.cpp Wed Nov 28 07:22:15 
2007
@@ -83,8 +83,11 @@
     size_t qt;
     Mode mode;
     bool summary;
+
+    static const std::string helpText;
     
     Opts() :
+        TestOptions(helpText),
         setup(false), control(false), publish(false), subscribe(false),
         pubs(1), count(500000), size(64), confirm(false), durable(false),
         subs(1), ack(0),
@@ -105,7 +108,7 @@
             ("count", optValue(count, "N"), "Each publisher sends N messages.")
             ("size", optValue(size, "BYTES"), "Size of messages in bytes.")
             ("pub-confirm", optValue(confirm), "Publisher use confirm-mode.")
-            ("durable", optValue(durable, "N"), "Publish messages as durable.")
+            ("durable", optValue(durable, "yes|no"), "Publish messages as 
durable.")
 
             ("nsubs", optValue(subs, "N"), "Create N subscribers.")
             ("sub-ack", optValue(ack, "N"), "N>0: Subscriber acks batches of 
N.\n"
@@ -152,6 +155,17 @@
     }
 };
 
+const std::string Opts::helpText=
+"There are two ways to use perftest: single process or multi-process.\n\n"
+"If none of the --setup, --publish, --subscribe or --control options\n"
+"are given perftest will run a single-process test.\n"
+"For a  multi-process test first run:\n"
+"  perftest --setup <other options>\n"
+"and wait for it to complete. The remaining process should run 
concurrently::\n"
+"Run --npubs times: perftest --publish <other options>\n"
+"Run --nsubs times: perftest --subscribe <other options>\n"
+"Run once:          perftest --control <other options>\n"
+"Note the <other options> must be identical for all processes.\n";
 
 Opts opts;
 
@@ -432,6 +446,7 @@
 };
 
 int main(int argc, char** argv) {
+    
     string exchange;
     switch (opts.mode) {
       case FANOUT: exchange="amq.fanout"; break;
@@ -441,7 +456,9 @@
 
     try {
         opts.parse(argc, argv);
-        if (!opts.setup && !opts.control && !opts.publish && !opts.subscribe)
+        bool singleProcess=
+            (!opts.setup && !opts.control && !opts.publish && !opts.subscribe);
+        if (singleProcess)
             opts.setup = opts.control = opts.publish = opts.subscribe = true;
 
         if (opts.setup) Setup().run();          // Set up queues
@@ -454,13 +471,15 @@
             ostringstream key;
             key << "perftest" << i; // Queue or topic name.
             if (opts.publish) {
-                for (size_t j = 0; j < opts.pubs; ++j)  {
+                size_t n = singleProcess ? opts.pubs : 1;
+                for (size_t j = 0; j < n; ++j)  {
                     pubs.push_back(new PublishThread(key.str(), exchange));
                     pubs.back().thread=Thread(pubs.back());
                 }
             }
             if (opts.subscribe) {
-                for (size_t j = 0; j < opts.subs; ++j)  {
+                size_t n = singleProcess ? opts.subs : 1;
+                for (size_t j = 0; j < n; ++j)  {
                     if (opts.mode==SHARED)
                         subs.push_back(new SubscribeThread(key.str()));
                     else
@@ -490,8 +509,10 @@
         }
         return 0;
     }
-    catch (const std::exception& e) {
-        cout << "Unexpected exception: " << e.what() << endl; 
-       return 1;
+    catch (const qpid::Options::Exception& e) {
+        cout << endl << e.what() << endl; 
     }
+    return 1;
 }
+
+                                            


Reply via email to