You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2007/08/07 01:31:18 UTC

svn commit: r563335 - in /incubator/qpid/trunk/qpid: ./ cpp/perftest/topic_publisher.cpp

Author: astitcher
Date: Mon Aug  6 16:31:17 2007
New Revision: 563335

URL: http://svn.apache.org/viewvc?view=rev&rev=563335
Log:
 r899@fuschia:  andrew | 2007-08-07 00:30:24 +0100
 Fixed Bad time calculations

Modified:
    incubator/qpid/trunk/qpid/   (props changed)
    incubator/qpid/trunk/qpid/cpp/perftest/topic_publisher.cpp

Propchange: incubator/qpid/trunk/qpid/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Mon Aug  6 16:31:17 2007
@@ -1,2 +1,2 @@
 8427bd24-ae5a-4eba-a324-d2fc9c9c6c77:/local/qpid.0-9.ams:1224
-c99eadab-1afc-4df6-acde-a632afdabecb:/local/qpid/trunk/qpid:852
+c99eadab-1afc-4df6-acde-a632afdabecb:/local/qpid/trunk/qpid:899

Modified: incubator/qpid/trunk/qpid/cpp/perftest/topic_publisher.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/perftest/topic_publisher.cpp?view=diff&rev=563335&r1=563334&r2=563335
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/perftest/topic_publisher.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/perftest/topic_publisher.cpp Mon Aug  6 16:31:17 2007
@@ -34,6 +34,7 @@
 #include "qpid/sys/Time.h"
 #include <cstdlib>
 #include <iostream>
+#include <iomanip>
 #include <time.h>
 
 using namespace qpid::client;
@@ -44,29 +45,46 @@
 bool done = 0;
 
 
-class Listener : public MessageListener{
+struct timespec operator-(const struct timespec& lhs, const struct timespec& rhs) {
+	timespec r;
+	r.tv_nsec = lhs.tv_nsec - rhs.tv_nsec;
+	r.tv_sec = lhs.tv_sec - rhs.tv_sec;
+	if (r.tv_nsec < 0) {
+		r.tv_nsec += 1000000000;
+		r.tv_sec -= 1;
+	}
+	return r;
+}
+
+std::ostream& operator<<(std::ostream& o, const struct timespec& ts) {
+	o << ts.tv_sec << "." << std::setw(9) << std::setfill('0') << std::right << ts.tv_nsec;
+	return o;
+}
+
+double toDouble(const struct timespec& ts) {
+	return double(ts.tv_nsec)/1000000000 + ts.tv_sec;
+}
 
+class Listener : public MessageListener{
 
 void set_time() {
     timespec ts;
     if (::clock_gettime(CLOCK_REALTIME, &ts))
 	std::cout << "Error" << std::endl;
-    _ts_sec = ts.tv_sec;
-    _ts_nsec = ts.tv_nsec;
+    startTime = ts;
   }
 
 void print_time() {
     timespec ts;
     if (::clock_gettime(CLOCK_REALTIME, &ts))
 	std::cout << "Error" << std::endl;
-    std::cout << "Total Time:" << ts.tv_sec-_ts_sec <<"." <<ts.tv_nsec - _ts_nsec << std::endl;
-    float rate = messageCount*2/(ts.tv_sec-_ts_sec);
+    std::cout << "Total Time:" << ts-startTime << std::endl;
+    double rate = messageCount*2/toDouble(ts-startTime);
     std::cout << "returned Messages:" << messageCount  << std::endl;
     std::cout << "round trip Rate:" << rate  << std::endl;
   }
 
-  time_t _ts_sec;	  ///< Timestamp of journal initilailization
-  u_int32_t _ts_nsec;     ///< Timestamp of journal initilailization
+  struct timespec startTime;
   int messageCount;
 
  public:
@@ -131,27 +149,22 @@
 
 
 
-  time_t _ts_sec;	  ///< Timestamp of journal initilailization
-  u_int32_t _ts_nsec;     ///< Timestamp of journal initilailization
-    timespec ts;
-    if (::clock_gettime(CLOCK_REALTIME, &ts))
-	std::cout << "Error" << std::endl;
-    _ts_sec = ts.tv_sec;
-    _ts_nsec = ts.tv_nsec;
-
+	struct timespec startTime;
+	if (::clock_gettime(CLOCK_REALTIME, &startTime))
+		std::cout << "Error" << std::endl;
 
-	
 	for (int i=0; i<count; i++) {
-	    msg.setData("Message 0123456789 ");
-	    channel.publish(msg, Exchange::STANDARD_TOPIC_EXCHANGE, queueName);
+		msg.setData("Message 0123456789 ");
+		channel.publish(msg, Exchange::STANDARD_TOPIC_EXCHANGE, queueName);
 	}
 
-    if (::clock_gettime(CLOCK_REALTIME, &ts))
-	std::cout << "Error" << std::endl;
-    std::cout << "publish Time:" << ts.tv_sec-_ts_sec <<"." <<ts.tv_nsec - _ts_nsec << std::endl;
-    float rate = count/(ts.tv_sec-_ts_sec);
-    std::cout << "publish Messages:" << count  << std::endl;
-    std::cout << "publish Rate:" << rate  << std::endl;
+	struct timespec endTime;
+	if (::clock_gettime(CLOCK_REALTIME, &endTime))
+		std::cout << "Error" << std::endl;
+	std::cout << "publish Time:" << endTime-startTime << std::endl;
+	double rate = count/toDouble(endTime-startTime);
+	std::cout << "publish Messages:" << count  << std::endl;
+	std::cout << "publish Rate:" << rate  << std::endl;
 
 
 	msg.setData(queueName);  // last message to queue.