Browse Source

add duration parameter

Murat Dogan 4 years ago
parent
commit
9cd01a265f

+ 9 - 4
examples/client-benchmark/main.cpp

@@ -1,7 +1,7 @@
 /*
 /*
  * libdatachannel client-benchmark example
  * libdatachannel client-benchmark example
  * Copyright (c) 2019-2020 Paul-Louis Ageneau
  * Copyright (c) 2019-2020 Paul-Louis Ageneau
- * Copyright (c) 2019 Murat Dogan
+ * Copyright (c) 2019-2021 Murat Dogan
  * Copyright (c) 2020 Will Munn
  * Copyright (c) 2020 Will Munn
  * Copyright (c) 2020 Nico Chatzi
  * Copyright (c) 2020 Nico Chatzi
  * Copyright (c) 2020 Lara Mackey
  * Copyright (c) 2020 Lara Mackey
@@ -157,7 +157,7 @@ int main(int argc, char **argv) try {
 		return 0;
 		return 0;
 	}
 	}
 	if (id == localId) {
 	if (id == localId) {
-		cout << "Invalid remote ID (This is my local ID). Exiting...";
+		cout << "Invalid remote ID (This is my local ID). Exiting..." << endl;
 		return 0;
 		return 0;
 	}
 	}
 
 
@@ -209,9 +209,12 @@ int main(int argc, char **argv) try {
 
 
 	dataChannelMap.emplace(id, dc);
 	dataChannelMap.emplace(id, dc);
 
 
-	const int duration = 20;
+	const int duration = params.durationInSec() > 0 ? params.durationInSec() : INT32_MAX;
+	cout << "Becnhmark will run for " << duration << " seconds" << endl;
+
 	int printStatCounter = 0;
 	int printStatCounter = 0;
-	for (int i = 0; i < duration; ++i) {
+
+	for (int i = 1; i <= duration; ++i) {
 		this_thread::sleep_for(1000ms);
 		this_thread::sleep_for(1000ms);
 		cout << "#" << i << " Received: " << receivedSize.load() / 1024 << " KB/s"
 		cout << "#" << i << " Received: " << receivedSize.load() / 1024 << " KB/s"
 		     << "   Sent: " << sentSize.load() / 1024 << " KB/s"
 		     << "   Sent: " << sentSize.load() / 1024 << " KB/s"
@@ -275,7 +278,9 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
 		     << endl;
 		     << endl;
 
 
 		cout << "Starting benchmark test. Sending data..." << endl;
 		cout << "Starting benchmark test. Sending data..." << endl;
+		cout << "###########################################" << endl;
 		cout << "### Check other peer's screen for stats ###" << endl;
 		cout << "### Check other peer's screen for stats ###" << endl;
+		cout << "###########################################" << endl;
 		try {
 		try {
 			while (dc->bufferedAmount() == 0) {
 			while (dc->bufferedAmount() == 0) {
 				dc->send(messageData);
 				dc->send(messageData);

+ 15 - 1
examples/client-benchmark/parse_cl.cpp

@@ -48,6 +48,7 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
     {"stunPort", required_argument, NULL, 't'},
     {"stunPort", required_argument, NULL, 't'},
     {"webSocketServer", required_argument, NULL, 'w'},
     {"webSocketServer", required_argument, NULL, 'w'},
     {"webSocketPort", required_argument, NULL, 'x'},
     {"webSocketPort", required_argument, NULL, 'x'},
+    {"durationInSec",required_argument,NULL,'d'},
     {"help", no_argument, NULL, 'h'},
     {"help", no_argument, NULL, 'h'},
     {NULL, 0, NULL, 0}
     {NULL, 0, NULL, 0}
   };
   };
@@ -61,9 +62,10 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
   _w = "localhost";
   _w = "localhost";
   _x = 8000;
   _x = 8000;
   _h = false;
   _h = false;
+  _d = 300;
 
 
   optind = 0;
   optind = 0;
-  while ((c = getopt_long (argc, argv, "s:t:w:x:enhv", long_options, &optind)) != - 1)
+  while ((c = getopt_long (argc, argv, "s:t:w:x:d:enhv", long_options, &optind)) != - 1)
     {
     {
       switch (c)
       switch (c)
         {
         {
@@ -111,6 +113,16 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
             }
             }
           break;
           break;
 
 
+        case 'd':
+          _d = atoi (optarg);
+          if (_d < 0)
+            {
+              std::string err;
+              err += "parameter range error: d must be >= 0";
+              throw (std::range_error(err));
+            }
+          break;
+
         case 'h':
         case 'h':
           _h = true;
           _h = true;
           this->usage (EXIT_SUCCESS);
           this->usage (EXIT_SUCCESS);
@@ -152,6 +164,8 @@ libdatachannel client implementing WebRTC Data Channels with WebSocket signaling
           Web socket server URL or IP address.\n\
           Web socket server URL or IP address.\n\
    [ -x ] [ --webSocketPort ] (type=INTEGER, range=0...65535, default=8000)\n\
    [ -x ] [ --webSocketPort ] (type=INTEGER, range=0...65535, default=8000)\n\
           Web socket server port.\n\
           Web socket server port.\n\
+   [ -d ] [ --durationInSec ] (type=INTEGER, range>=0...INT32_MAX, 0:infinite(INT32_MAX), Valid only for offering client, default=300)\n\
+          Benchmark duration in seconds.\n\
    [ -h ] [ --help ] (type=FLAG)\n\
    [ -h ] [ --help ] (type=FLAG)\n\
           Display this help and exit.\n";
           Display this help and exit.\n";
     }
     }

+ 2 - 0
examples/client-benchmark/parse_cl.h

@@ -40,6 +40,7 @@ private:
   std::string _w;
   std::string _w;
   int _x;
   int _x;
   bool _h;
   bool _h;
+  int _d;
 
 
   /* other stuff to keep track of */
   /* other stuff to keep track of */
   std::string _program_name;
   std::string _program_name;
@@ -62,6 +63,7 @@ public:
   std::string webSocketServer () const { return _w; }
   std::string webSocketServer () const { return _w; }
   int webSocketPort () const { return _x; }
   int webSocketPort () const { return _x; }
   bool h () const { return _h; }
   bool h () const { return _h; }
+  int durationInSec () const { return _d; }
 };
 };
 
 
 #endif
 #endif