Browse Source

[1959] Print overall rate statistics.

Marcin Siodelski 12 years ago
parent
commit
3e6ed8d543

+ 18 - 1
tests/tools/perfdhcp/stats_mgr.h

@@ -775,7 +775,8 @@ public:
     StatsMgr(const bool archive_enabled = false) :
         exchanges_(),
         custom_counters_(),
-        archive_enabled_(archive_enabled) {
+        archive_enabled_(archive_enabled),
+        boot_time_(boost::posix_time::microsec_clock::universal_time()) {
     }
 
     /// \brief Specify new exchange type.
@@ -1028,6 +1029,20 @@ public:
         return(xchg_stats->getDroppedPacketsNum());
     }
 
+    /// \brief Get time period since the start of test.
+    ///
+    /// Calculate dna return period since the test start. This
+    /// can be specifically helpful when calculating packet
+    /// exchange rates.
+    ///
+    /// \return test period so far.
+    boost::posix_time::time_period getTestPeriod() const {
+        using namespace boost::posix_time;
+        time_period test_period(boot_time_,
+                                microsec_clock::universal_time());
+        return test_period;
+    }
+
     /// \brief Return name of the exchange.
     ///
     /// Method returns name of the specified exchange type.
@@ -1158,6 +1173,8 @@ private:
     /// for extended period of time and many packets have to be
     /// archived.
     bool archive_enabled_;
+
+    boost::posix_time::ptime boot_time_; ///< Time when test is started.
 };
 
 } // namespace perfdhcp

+ 23 - 0
tests/tools/perfdhcp/test_control.cc

@@ -481,7 +481,30 @@ TestControl::openSocket(uint16_t port) const {
 }
 
 void
+TestControl::printRate() const {
+    double rate = 0;
+    CommandOptions& options = CommandOptions::instance();
+    if (options.getIpVersion() == 4) {
+        double duration =
+            stats_mgr4_->getTestPeriod().length().total_nanoseconds() / 1e9;
+        rate = stats_mgr4_->getRcvdPacketsNum(StatsMgr4::XCHG_DO) / duration;
+    } else if (options.getIpVersion() == 6) {
+        double duration =
+            stats_mgr6_->getTestPeriod().length().total_nanoseconds() / 1e9;
+        rate = stats_mgr6_->getRcvdPacketsNum(StatsMgr6::XCHG_SA) / duration;
+    }
+    std::cout << "***Rate statistics***" << std::endl;
+    if (options.getRate() > 0) {
+        std::cout << "Rate: " << rate << ", expected rate: "
+                  << options.getRate() << std::endl << std::endl;
+    } else {
+        std::cout << "Rate: " << rate << std::endl << std::endl;
+    }
+}
+
+void
 TestControl::printStats() const {
+    printRate();
     CommandOptions& options = CommandOptions::instance();
     if (options.getIpVersion() == 4) {
         if (!stats_mgr4_) {

+ 5 - 0
tests/tools/perfdhcp/test_control.h

@@ -360,6 +360,11 @@ protected:
     /// \return socket descriptor.
     int openSocket(uint16_t port = 0) const;
 
+    /// \brief Print rate statistics.
+    ///
+    /// Method print packet exchange rate statistics.
+    void printRate() const;
+
     /// \brief Print performance statistics.
     ///
     /// Method prints performance statistics.