Browse Source

[1959] Print intermediate statistics (support for -t parameter).

Marcin Siodelski 12 years ago
parent
commit
23c33b29ab

+ 27 - 0
tests/tools/perfdhcp/stats_mgr.h

@@ -1096,6 +1096,33 @@ public:
         }
     }
 
+    /// \brief Print intermediate statistics.
+    ///
+    /// Method prints intermediate statistics for all exchanges.
+    /// Statistics includes sent, received and dropped packets
+    /// counters.
+    void printIntermediateStats() const {
+        std::ostringstream stream_sent("");
+        std::ostringstream stream_rcvd("");
+        std::ostringstream stream_drops("");
+        std::string sep("");
+        for (ExchangesMapIterator it = exchanges_.begin();
+             it != exchanges_.end();
+             ++it) {
+
+            if (it != exchanges_.begin()) {
+                sep = "/";
+            }
+            stream_sent << sep << it->second->getSentPacketsNum();
+            stream_rcvd << sep << it->second->getRcvdPacketsNum();
+            stream_drops << sep << it->second->getDroppedPacketsNum();
+        }
+        std::cout << "sent: " << stream_sent.str() 
+                  << "; received: " << stream_rcvd.str()
+                  << "; drops: " << stream_drops.str()
+                  << std::endl;
+    }
+
     /// \brief Print timestamps of all packets.
     ///
     /// Method prints timestamps of all sent and received

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

@@ -528,6 +528,22 @@ TestControl::printRate() const {
 }
 
 void
+TestControl::printIntermediateStats() {
+    CommandOptions& options = CommandOptions::instance();
+    int delay = options.getReportDelay();
+    ptime now = microsec_clock::universal_time();
+    time_period time_since_report(last_report_, now);
+    if (time_since_report.length().total_seconds() >= delay) {
+        if (options.getIpVersion() == 4) {
+            stats_mgr4_->printIntermediateStats();
+        } else if (options.getIpVersion() == 6) {
+            stats_mgr6_->printIntermediateStats();
+        }
+        last_report_ = now;
+    }
+}
+
+void
 TestControl::printStats() const {
     printRate();
     CommandOptions& options = CommandOptions::instance();
@@ -672,6 +688,7 @@ void
 TestControl::reset() {
     send_due_ = microsec_clock::universal_time();
     last_sent_ = send_due_;
+    last_report_ = send_due_;
     transid_gen_.reset();
     transid_gen_ = TransidGeneratorPtr(new TransidGenerator());
     first_packet_serverid_.clear();
@@ -735,6 +752,9 @@ TestControl::run() {
             }
             ++packets_sent;
         }
+        if (options.getReportDelay() > 0) {
+            printIntermediateStats();
+        }
     }
     printStats();
 }

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

@@ -365,6 +365,12 @@ protected:
     /// \return socket descriptor.
     int openSocket() const;
 
+    /// \brief Print intermediate statistics.
+    ///
+    /// Print brief statistics regarding number of sent packets,
+    /// received packets and dropped packets so far.
+    void printIntermediateStats();
+
     /// \brief Print rate statistics.
     ///
     /// Method print packet exchange rate statistics.
@@ -582,6 +588,9 @@ private:
                                            ///< of exchanges.
     boost::posix_time::ptime last_sent_;   ///< Indicates when the last exchange
                                            /// was initiated.
+
+    boost::posix_time::ptime last_report_; ///< Last intermediate report time.
+
     StatsMgr4Ptr stats_mgr4_;  ///< Statistics Manager 4.
     StatsMgr6Ptr stats_mgr6_;  ///< Statistics Manager 6.