From 581e494b3cf7fd9e5373dd7c582fb26bdfa18dc5 Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Fri, 25 Feb 2022 12:52:19 +0100
Subject: [PATCH] Extend emper::printInfo(), add emper-info "app"

---
 apps/EmperInfo.cpp | 11 ++++++
 apps/meson.build   |  6 +++
 emper/Emper.cpp    | 93 +++++++++++++++++++++++++++++++++++++++++++---
 emper/Emper.hpp    |  8 ++++
 4 files changed, 113 insertions(+), 5 deletions(-)
 create mode 100644 apps/EmperInfo.cpp

diff --git a/apps/EmperInfo.cpp b/apps/EmperInfo.cpp
new file mode 100644
index 00000000..a0fec9d2
--- /dev/null
+++ b/apps/EmperInfo.cpp
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: LGPL-3.0-or-later
+// Copyright © 2022 Florian Schmaus
+#include <cstdlib>
+
+#include "Emper.hpp"
+#include "emper-common.h"
+
+auto main(UNUSED_ARG int argc, UNUSED_ARG char* argv[]) -> int {
+	emper::printInfo();
+	return EXIT_SUCCESS;
+}
diff --git a/apps/meson.build b/apps/meson.build
index 6ee5a2d1..70dc55a5 100644
--- a/apps/meson.build
+++ b/apps/meson.build
@@ -34,6 +34,12 @@ echoclient_exe = executable(
   dependencies: emper_dep,
 )
 
+emper_info_exe = executable(
+  'emper-info',
+  'EmperInfo.cpp',
+  dependencies: emper_dep,
+)
+
 qsort = executable(
   'qsort',
   'qsort.cpp',
diff --git a/emper/Emper.cpp b/emper/Emper.cpp
index a508a0ed..c696d9a2 100644
--- a/emper/Emper.cpp
+++ b/emper/Emper.cpp
@@ -49,12 +49,95 @@ void async(const Fiber::fiber_fun0_t& function, workeraffinity_t* affinity) {
 
 namespace emper {
 
-void printInfo(std::ostream strm) {
-	// clang-format: off
-	strm << "Extensible Massive-Parallelism Execution Realm (EMPER)" << std::endl
+auto operator<<(std::ostream& out, const ContinuationStealingMode& cont_stealing_mode)
+		-> std::ostream& {
+	switch (cont_stealing_mode) {
+		case ContinuationStealingMode::disabled:
+			out << "disabled";
+			break;
+		case ContinuationStealingMode::locked:
+			out << "locked";
+			break;
+		case ContinuationStealingMode::waitfree:
+			out << "waitfree";
+			break;
+	}
+	return out;
+}
+
+auto operator>>(std::istream& in, ContinuationStealingMode& cont_stealing_mode) -> std::istream& {
+	std::string token;
+	in >> token;
+	if (token == "disabled") {
+		cont_stealing_mode = ContinuationStealingMode::disabled;
+	} else if (token == "locked") {
+		cont_stealing_mode = ContinuationStealingMode::locked;
+	} else if (token == "waitfree") {
+		cont_stealing_mode = ContinuationStealingMode::waitfree;
+	} else {
+		in.setstate(std::ios_base::failbit);
+	}
+
+	return in;
+}
+
+auto operator<<(std::ostream& out,
+								const ContinuationStealingMadviseStack& cont_stealing_madvise_stack)
+		-> std::ostream& {
+	switch (cont_stealing_madvise_stack) {
+		case ContinuationStealingMadviseStack::no:
+			out << "no";
+			break;
+		case ContinuationStealingMadviseStack::dontneed:
+			out << "dontneed";
+			break;
+		case ContinuationStealingMadviseStack::free:
+			out << "free";
+			break;
+	}
+	return out;
+}
+
+auto operator>>(std::istream& in, ContinuationStealingMadviseStack& cont_stealing_madvise_stack)
+		-> std::istream& {
+	std::string token;
+	in >> token;
+	if (token == "no") {
+		cont_stealing_madvise_stack = ContinuationStealingMadviseStack::no;
+	} else if (token == "dontneed") {
+		cont_stealing_madvise_stack = ContinuationStealingMadviseStack::dontneed;
+	} else if (token == "free") {
+		cont_stealing_madvise_stack = ContinuationStealingMadviseStack::free;
+	} else {
+		in.setstate(std::ios_base::failbit);
+	}
+
+	return in;
+}
+
+void printInfo(std::ostream& strm) {
+	// clang-format off
+	strm << std::boolalpha << "Extensible Massive-Parallelism Execution Realm (EMPER)" << std::endl
 			 << "Version: " << getFullVersion() << std::endl
-			 << "Context Size: " << eu::bytesToHumanReadableString(Context::CONTEXT_SIZE) << std::endl;
-	// clang-format: on
+			 << "Debug: " << DEBUG << std::endl
+			 << "IO: " << IO << std::endl
+			 << "IO Stealing: " << IO_STEALING << std::endl
+			 << "IO Lockless CQ: " << IO_LOCKLESS_CQ << std::endl
+			 << "Set Affinity on Block: " << SET_AFFINITY_ON_BLOCK << std::endl
+			 << "Work-Stealing Queue Default: " << TOSTRING(EMPER_WS_QUEUE_DEFAULT_TYPE) << std::endl
+			 << "Work-Stealing Queue Scheduler: " << TOSTRING(EMPER_WS_QUEUE_SCHEDULER_TYPE) << std::endl
+			 << "Continuation-Stealing: " << CONTINUATION_STEALING_MODE << std::endl
+			 << "Continuation-Stealing Madvise Stack: " << CONTINUATION_STEALING_MADVISE_STACK << std::endl
+			 << "Context Size: " << eu::bytesToHumanReadableString(Context::CONTEXT_SIZE) << std::endl
+			 << "Context Manager with Memory Manager: " << CONTEXT_MANAGER_WITH_MEMORY_MANAGER << std::endl
+			 << "Memory Manager Victim Percentage: " << MEMORY_MANAGER_VICTIM_PERCENTAGE << std::endl
+			 << "Stack Guard Page: " << STACK_GUARD_PAGE << std::endl
+			 << "Assume Cache Line Size: " << ASSUME_CACHE_LINE_SIZE << std::endl
+			 << "Stats: " << STATS << std::endl
+			 << "Worker Sleep: " << WORKER_SLEEP << std::endl
+			 << "Overflow Queue: " << OVERFLOW_QUEUE << std::endl
+		;
+	// clang-format on
 }
 
 const bool IO_MUST_INVALIDATE_BROKEN_CHAIN = EMPER_LINUX_LT("5.15.0");
diff --git a/emper/Emper.hpp b/emper/Emper.hpp
index e1b86ddb..bc87b2ea 100644
--- a/emper/Emper.hpp
+++ b/emper/Emper.hpp
@@ -257,6 +257,9 @@ enum class ContinuationStealingMode {
 	locked,
 	waitfree,
 };
+auto operator<<(std::ostream& out, const ContinuationStealingMode& cont_stealing_mode)
+		-> std::ostream&;
+auto operator>>(std::istream& in, ContinuationStealingMode& cont_stealing_mode) -> std::istream&;
 
 const ContinuationStealingMode CONTINUATION_STEALING_MODE =
 		ContinuationStealingMode::EMPER_CONTINUATION_STEALING_MODE;
@@ -271,6 +274,11 @@ enum class ContinuationStealingMadviseStack {
 	dontneed,
 	free,
 };
+auto operator<<(std::ostream& out,
+								const ContinuationStealingMadviseStack& cont_stealing_madvise_stack)
+		-> std::ostream&;
+auto operator>>(std::istream& in, ContinuationStealingMadviseStack& cont_stealing_madvise_stack)
+		-> std::istream&;
 
 const enum ContinuationStealingMadviseStack CONTINUATION_STEALING_MADVISE_STACK =
 		ContinuationStealingMadviseStack::EMPER_CONTINUATION_STEALING_MADVISE_STACK;
-- 
GitLab