]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1046] added cleaner output mode for perfdhcp
authorWlodek Wencel <wlodek@isc.org>
Wed, 18 Mar 2020 11:35:12 +0000 (12:35 +0100)
committerWlodzimierz Wencel <wlodek@isc.org>
Fri, 20 Mar 2020 16:01:34 +0000 (16:01 +0000)
src/bin/perfdhcp/command_options.cc
src/bin/perfdhcp/command_options.h
src/bin/perfdhcp/stats_mgr.h
src/bin/perfdhcp/test_control.cc
src/bin/perfdhcp/tests/command_options_unittest.cc

index d63cb68403d834295e82e3274c3b666ae2b4cd62..356cb02a7b3cb75250ad17b4de7970838bb530fa 100644 (file)
@@ -117,6 +117,7 @@ CommandOptions::reset() {
     renew_rate_ = 0;
     release_rate_ = 0;
     report_delay_ = 0;
+    clean_report_ = false;
     clients_num_ = 0;
     mac_template_.assign(mac, mac + 6);
     duid_template_.clear();
@@ -238,7 +239,7 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
     // they will be tuned and validated elsewhere
     while((opt = getopt_long(argc, argv,
                              "huv46A:r:t:R:b:n:p:d:D:l:P:a:L:N:M:s:iBc1"
-                             "J:T:X:O:o:E:S:I:x:W:w:e:f:F:g:",
+                             "J:T:X:O:o:E:S:I:x:W:w:e:f:F:g:C",
                              long_options, NULL)) != -1) {
         stream << " -" << static_cast<char>(opt);
         if (optarg) {
@@ -291,6 +292,10 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
             rapid_commit_ = true;
             break;
 
+        case 'C':
+            clean_report_ = true;
+            break;
+
         case 'd':
             check(drop_time_set_ > 1,
                   "maximum number of drops already specified, "
@@ -622,19 +627,20 @@ CommandOptions::initialize(int argc, char** argv, bool print_cmd_line) {
             server_name_ = ALL_DHCP_SERVERS;
         }
     }
+    if (!getCleanReport()) {
+        if (print_cmd_line) {
+            std::cout << "Running: " << stream.str() << std::endl;
+        }
 
-    if (print_cmd_line) {
-        std::cout << "Running: " << stream.str() << std::endl;
-    }
-
-    if (scenario_ == Scenario::BASIC) {
-        std::cout << "Scenario: basic." << std::endl;
-    } else if (scenario_ == Scenario::AVALANCHE) {
-        std::cout << "Scenario: avalanche." << std::endl;
-    }
+        if (scenario_ == Scenario::BASIC) {
+            std::cout << "Scenario: basic." << std::endl;
+        } else if (scenario_ == Scenario::AVALANCHE) {
+            std::cout << "Scenario: avalanche." << std::endl;
+        }
 
-    if (!isSingleThreaded()) {
-        std::cout << "Multi-thread mode enabled." << std::endl;
+        if (!isSingleThreaded()) {
+            std::cout << "Multi-thread mode enabled." << std::endl;
+        }
     }
 
     // Handle the local '-l' address/interface
@@ -1142,7 +1148,7 @@ CommandOptions::printCommandLine() const {
 void
 CommandOptions::usage() const {
     std::cout <<
-        "perfdhcp [-huv] [-4|-6] [-A<encapsulation-level>] [-e<lease-type>]\n"
+        "perfdhcp [-huvC] [-4|-6] [-A<encapsulation-level>] [-e<lease-type>]\n"
         "         [-r<rate>] [-f<renew-rate>]\n"
         "         [-F<release-rate>] [-t<report>] [-R<range>] [-b<base>]\n"
         "         [-n<num-request>] [-p<test-period>] [-d<drop-time>]\n"
@@ -1298,6 +1304,7 @@ CommandOptions::usage() const {
         "    alternative to -n, or both options can be given, in which case the\n"
         "    testing is completed when either limit is reached.\n"
         "-t<report>: Delay in seconds between two periodic reports.\n"
+        "-C: Output reduced, periodic reports generated in easy parsable mode.\n"
         "\n"
         "Errors:\n"
         "- tooshort: received a too short message\n"
index 49a0573ba7beeae1f83b5e68406918f33e2346a1..0d61d0d75c8b780211827e1946ca0d688d38d3eb 100644 (file)
@@ -173,6 +173,11 @@ public:
     /// \return delay between two consecutive performance reports.
     int getReportDelay() const { return report_delay_; }
 
+    /// \brief Returns clean report mode.
+    ///
+    /// \return true if cleaner report is enabled.
+    int getCleanReport() const { return clean_report_; }
+
     /// \brief Returns number of simulated clients.
     ///
     /// \return number of simulated clients.
@@ -574,6 +579,9 @@ private:
     /// Delay between generation of two consecutive performance reports.
     int report_delay_;
 
+    /// Enable cleaner, easy to parse, output of performance reports.
+    bool clean_report_;
+
     /// Number of simulated clients (aka randomization range).
     uint32_t clients_num_;
 
index cef159dc7ea79f8c444bebfeac339c44253e3d92..fcd106f0cbf9f65eb692a93faee2e362978b8469 100644 (file)
@@ -1087,7 +1087,9 @@ public:
     /// Method prints intermediate statistics for all exchanges.
     /// Statistics includes sent, received and dropped packets
     /// counters.
-    void printIntermediateStats() const {
+    ///
+    /// \param clean_report value to generate easy to parse report.
+    void printIntermediateStats(bool clean_report) const {
         std::ostringstream stream_sent;
         std::ostringstream stream_rcvd;
         std::ostringstream stream_drops;
@@ -1097,18 +1099,32 @@ public:
              it != exchanges_.end(); ++it) {
 
             if (it != exchanges_.begin()) {
-                sep = "/";
+                if (clean_report) {
+                    sep = " ";
+                } else {
+                    sep = "/";
+                }
             }
             stream_sent << sep << it->second->getSentPacketsNum();
             stream_rcvd << sep << it->second->getRcvdPacketsNum();
             stream_drops << sep << it->second->getDroppedPacketsNum();
             stream_reject << sep << it->second->getRejLeasesNum();
-        }
+        }//teraz
+
+        if (clean_report) {
+        std::cout << stream_sent.str()
+                  << " " << stream_rcvd.str()
+                  << " " << stream_drops.str()
+                  << " " << stream_reject.str()
+                  << std::endl;
+
+        } else {
         std::cout << "sent: " << stream_sent.str()
                   << "; received: " << stream_rcvd.str()
                   << "; drops: " << stream_drops.str()
                   << "; rejected: " << stream_reject.str()
                   << std::endl;
+        }
     }
 
     /// \brief Print timestamps of all packets.
index da22012e9325d40591dd66101b6d02a96894405c..2df771ad48c9410e2ecda48da50bc894004f0783 100644 (file)
@@ -678,7 +678,7 @@ TestControl::printIntermediateStats() {
     ptime now = microsec_clock::universal_time();
     time_period time_since_report(last_report_, now);
     if (time_since_report.length().total_seconds() >= delay) {
-        stats_mgr_.printIntermediateStats();
+        stats_mgr_.printIntermediateStats(options_.getCleanReport());
         last_report_ = now;
     }
 }
index e307fc181ab5a0f21197025197ccff8fb0047135..67ebaee426efb69dc994a3dbe34bccda62e05216 100644 (file)
@@ -276,6 +276,12 @@ TEST_F(CommandOptionsTest, UseFirst) {
     EXPECT_TRUE(opt.isUseFirst());
 }
 
+TEST_F(CommandOptionsTest, UseCleanOutput) {
+    CommandOptions opt;
+    EXPECT_NO_THROW(process(opt, "perfdhcp -6 -C -l ethx all"));
+    EXPECT_TRUE(opt.getCleanReport());
+}
+
 TEST_F(CommandOptionsTest, UseRelayV6) {
     CommandOptions opt;
     EXPECT_NO_THROW(process(opt, "perfdhcp -6 -A1 -l ethx all"));