Skip to content
Snippets Groups Projects
Commit 2177250a authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'worker_stats_is_named_constants' into 'master'

[io/Stats] introduce named constants for special workerIds

See merge request !148
parents 6f7d534c bafe87b9
No related branches found
No related tags found
1 merge request!148[io/Stats] introduce named constants for special workerIds
Pipeline #59726 passed
...@@ -97,7 +97,7 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory ...@@ -97,7 +97,7 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory
} }
if constexpr (emper::STATS) { if constexpr (emper::STATS) {
globalIo->stats.workerId = -1; globalIo->stats.workerId = emper::io::Stats::GLOBAL_COMPLETER_ID;
std::atexit(emper::io::Stats::printWorkerStats); std::atexit(emper::io::Stats::printWorkerStats);
} }
} }
......
...@@ -41,7 +41,7 @@ auto operator<<(std::ostream& os, const Stats::CompletionType& t) -> std::ostrea ...@@ -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& { auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& {
if (s.workerId == -1) { if (s.workerId == Stats::GLOBAL_COMPLETER_ID) {
bool futuresToPrint = false; bool futuresToPrint = false;
std::stringstream ss; std::stringstream ss;
ss << "# global IO Stats: #" << std::endl; ss << "# global IO Stats: #" << std::endl;
...@@ -72,7 +72,7 @@ auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& { ...@@ -72,7 +72,7 @@ auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& {
return os; return os;
} }
if (s.workerId == -2) { if (s.workerId == Stats::AVG_ID) {
os << "# AVG IO worker Stats: #" << std::endl; os << "# AVG IO worker Stats: #" << std::endl;
} else { } else {
os << "# IO Stats of worker " << std::to_string(s.workerId) << ": #" << std::endl; 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& { ...@@ -95,7 +95,7 @@ auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& {
os << std::endl; os << std::endl;
} }
if (s.workerId == -1) { if (s.workerId == Stats::GLOBAL_COMPLETER_ID) {
return os; return os;
} }
...@@ -126,7 +126,7 @@ void Stats::printWorkerStats() { ...@@ -126,7 +126,7 @@ void Stats::printWorkerStats() {
// Use a stats object to calculate the averages // Use a stats object to calculate the averages
Stats avgs; Stats avgs;
// mark as averages // mark as averages
avgs.workerId = -2; avgs.workerId = Stats::AVG_ID;
// calculate avgs // calculate avgs
int i = 1; int i = 1;
......
...@@ -46,6 +46,9 @@ class Stats { ...@@ -46,6 +46,9 @@ class Stats {
friend class RecvFuture; friend class RecvFuture;
friend class WritevFuture; friend class WritevFuture;
static const int GLOBAL_COMPLETER_ID = -1;
static const int AVG_ID = -2;
int workerId = 0; int workerId = 0;
static_assert(sizeof(int) > sizeof(workerid_t)); static_assert(sizeof(int) > sizeof(workerid_t));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment