Przeglądaj źródła

added overall statistics

thomas 4 lat temu
rodzic
commit
03e6dd9446
1 zmienionych plików z 15 dodań i 3 usunięć
  1. 15 3
      src/ua-stress-test/main.cpp

+ 15 - 3
src/ua-stress-test/main.cpp

@@ -27,6 +27,7 @@ char *cfg_OpcUa_ServerEndpoint;
 
 using namespace std;
 
+int overallRequests = 0;
 bool stop = false; // when set to true, the client threads terminate
 
 struct myUserdata {
@@ -78,7 +79,8 @@ void workerThread()
     chrono::system_clock::time_point startTime = chrono::system_clock::now();
     unsigned long intervalUs = 1.0 / ((double)cfg_OpcUaReadsPerConnectionPerS) * 1000000.0;
     UA_UInt32 reqId = 0;
-    for(int i = 0; !stop; i++) // loop repeats every intervalUs microseconds
+    int i = 0;
+    for(; !stop; i++) // loop repeats every intervalUs microseconds
     {
         std::this_thread::sleep_until(startTime + chrono::microseconds(i * intervalUs));
         UA_Client_readValueAttribute_async(client,
@@ -92,12 +94,14 @@ void workerThread()
     UA_Client_disconnect(client);
     UA_Client_delete(client);
 
+    overallRequests += i;
+
     cout << "Thread " << threadId << " terminating. ";
     cout << "Statistics: " << endl;
-    cout << "\tRequests sent: " << reqId << endl;
+    cout << "\tRequests sent: " << i << endl;
     cout << "\tResponses received: " << d.numberOfResponesReceived << endl;
     cout << "\tRuntime(ms): " << (std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime)).count() << endl;
-    cout << "\tRequests sent per s: " << ((double)reqId) / (std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime)).count() * 1000.0 << endl;
+    cout << "\tRequests sent per s: " << ((double)i) / (std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime)).count() * 1000.0 << endl;
 }
 
 int main(int argc, char **argv) {
@@ -136,6 +140,7 @@ int main(int argc, char **argv) {
         return EXIT_FAILURE;
     }
     
+    chrono::system_clock::time_point startTime = chrono::system_clock::now();
     // start a thread for each connection
     list<thread> threadList;
     for (int i = 0; i < cfg_NumberOfConnections; i++) {  // loop repeats every intervalUs microseconds
@@ -152,6 +157,13 @@ int main(int argc, char **argv) {
     for (it = threadList.begin(); it != threadList.end(); ++it){
         it->join();
     }
+    chrono::system_clock::time_point endTime = chrono::system_clock::now();
+
+    cout << "Overall Statistics: " << endl;
+    cout << "\tRequests sent: " << overallRequests << endl;
+    cout << "\tRuntime(ms): " << (std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime)).count() << endl;
+    cout << "\tRequests sent per s: " << ((double)overallRequests) / (std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime)).count() * 1000.0 << endl;
+
 
     return EXIT_SUCCESS;
 }