From bafe87b93d3993624db53364fb7d65424d422c37 Mon Sep 17 00:00:00 2001 From: Florian Fischer <florian.fl.fischer@fau.de> Date: Wed, 24 Mar 2021 14:04:59 +0100 Subject: [PATCH] [io/Stats] introduce named constants for special workerIds --- emper/Runtime.cpp | 2 +- emper/io/Stats.cpp | 8 ++++---- emper/io/Stats.hpp | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp index e4b18974..af097e0f 100644 --- a/emper/Runtime.cpp +++ b/emper/Runtime.cpp @@ -97,7 +97,7 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory } if constexpr (emper::STATS) { - globalIo->stats.workerId = -1; + globalIo->stats.workerId = emper::io::Stats::GLOBAL_COMPLETER_ID; std::atexit(emper::io::Stats::printWorkerStats); } } diff --git a/emper/io/Stats.cpp b/emper/io/Stats.cpp index a3e7fecc..ba4ffe4b 100644 --- a/emper/io/Stats.cpp +++ b/emper/io/Stats.cpp @@ -41,7 +41,7 @@ auto operator<<(std::ostream& os, const Stats::CompletionType& t) -> std::ostrea } auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& { - if (s.workerId == -1) { + if (s.workerId == Stats::GLOBAL_COMPLETER_ID) { bool futuresToPrint = false; std::stringstream ss; ss << "# global IO Stats: #" << std::endl; @@ -72,7 +72,7 @@ auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& { return os; } - if (s.workerId == -2) { + if (s.workerId == Stats::AVG_ID) { os << "# AVG IO worker Stats: #" << std::endl; } else { os << "# IO Stats of worker " << std::to_string(s.workerId) << ": #" << std::endl; @@ -95,7 +95,7 @@ auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& { os << std::endl; } - if (s.workerId == -1) { + if (s.workerId == Stats::GLOBAL_COMPLETER_ID) { return os; } @@ -126,7 +126,7 @@ void Stats::printWorkerStats() { // Use a stats object to calculate the averages Stats avgs; // mark as averages - avgs.workerId = -2; + avgs.workerId = Stats::AVG_ID; // calculate avgs int i = 1; diff --git a/emper/io/Stats.hpp b/emper/io/Stats.hpp index 84da03ad..776d247a 100644 --- a/emper/io/Stats.hpp +++ b/emper/io/Stats.hpp @@ -46,6 +46,9 @@ class Stats { friend class RecvFuture; friend class WritevFuture; + static const int GLOBAL_COMPLETER_ID = -1; + static const int AVG_ID = -2; + int workerId = 0; static_assert(sizeof(int) > sizeof(workerid_t)); -- GitLab