From 321c9e2d313268b83fa7039eb5f83f41c7ad2ca2 Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fl.fischer@fau.de>
Date: Sun, 25 Apr 2021 11:35:12 +0200
Subject: [PATCH] [EchoClient] remember and output the time when the terminator
 thread wakes up

---
 apps/EchoClient.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/apps/EchoClient.cpp b/apps/EchoClient.cpp
index 612e4436..606f031b 100644
--- a/apps/EchoClient.cpp
+++ b/apps/EchoClient.cpp
@@ -129,7 +129,7 @@ class Client {
 	static auto startNew(Semaphore& readySem, Semaphore& startSem, CPS& cps) -> bool;
 
  private:
-	inline auto shouldTerminate() const -> bool {
+	[[nodiscard]] auto shouldTerminate() const -> bool {
 		return iteration >= iterations || terminate.load(std::memory_order_relaxed);
 	}
 
@@ -506,10 +506,12 @@ auto main(int argc, char* argv[]) -> int {
 			readySemaphore.acquire();
 		}
 
+		high_resolution_clock::time_point echoTerminationTime;
 		if (execution_seconds) {
 			iterations = SIZE_MAX;
-			terminator = std::thread([] {
+			terminator = std::thread([&] {
 				std::this_thread::sleep_for(seconds(execution_seconds));
+				echoTerminationTime = high_resolution_clock::now();
 				terminate.store(true);
 			});
 		}
@@ -531,6 +533,11 @@ auto main(int argc, char* argv[]) -> int {
 		}
 
 		auto connect_duration = duration_cast<nanoseconds>(echo_start - connect_start).count();
+		uint64_t echoDurationUntilTermination;
+		if (execution_seconds) {
+			echoDurationUntilTermination =
+					duration_cast<nanoseconds>(echoTerminationTime - echo_start).count();
+		}
 		auto echo_duration = duration_cast<nanoseconds>(echo_end - echo_start).count();
 		auto total_duration = duration_cast<nanoseconds>(echo_end - connect_start).count();
 
@@ -561,6 +568,9 @@ auto main(int argc, char* argv[]) -> int {
 		sst << "total_unexpected_echos = " << total_unexpected_echos << std::endl;
 		sst << "avg_ns = " << avg_ns.getAverage() << std::endl;
 		sst << "connect_duration = " << connect_duration << std::endl;
+		if (execution_seconds) {
+			sst << "execution_duration = " << echoDurationUntilTermination << std::endl;
+		}
 		sst << "echo_duration = " << echo_duration << std::endl;
 		sst << "total_duration = " << total_duration << std::endl;
 		sst << std::endl;
-- 
GitLab