Skip to content
Snippets Groups Projects
Commit b94eacc7 authored by Florian Fischer's avatar Florian Fischer
Browse files

Merge branch 'print_stats_in_runtime_destructor' into 'master'

[Runtime] print stats in the destructor not at exit

See merge request !147
parents 25d01022 7b2c05e2
No related branches found
No related tags found
1 merge request!147[Runtime] print stats in the destructor not at exit
Pipeline #59732 passed
...@@ -99,7 +99,6 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory ...@@ -99,7 +99,6 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory
if constexpr (emper::STATS) { if constexpr (emper::STATS) {
globalIo->stats.workerId = emper::io::Stats::GLOBAL_COMPLETER_ID; globalIo->stats.workerId = emper::io::Stats::GLOBAL_COMPLETER_ID;
std::atexit(emper::io::Stats::printWorkerStats);
} }
} }
...@@ -148,13 +147,6 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory ...@@ -148,13 +147,6 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory
threadsRunning = true; threadsRunning = true;
if constexpr (emper::STATS) {
int res = std::atexit(&printLastRuntimeStats);
if (res) {
DIE_MSG("could not register printStats() with at_exit()");
}
}
const std::string stacktraceOnAbortsEnvVar("EMPER_STACKTRACE_ON_ABORTS"); const std::string stacktraceOnAbortsEnvVar("EMPER_STACKTRACE_ON_ABORTS");
const char* envValueEnableStacktraces = std::getenv(stacktraceOnAbortsEnvVar.c_str()); const char* envValueEnableStacktraces = std::getenv(stacktraceOnAbortsEnvVar.c_str());
if (envValueEnableStacktraces && !std::strcmp(envValueEnableStacktraces, "true")) { if (envValueEnableStacktraces && !std::strcmp(envValueEnableStacktraces, "true")) {
...@@ -169,6 +161,13 @@ Runtime::~Runtime() { ...@@ -169,6 +161,13 @@ Runtime::~Runtime() {
initiateAndWaitUntilTermination(); initiateAndWaitUntilTermination();
} }
// Print the stats after all worker threads have terminated and before we delete
// objects bound to the runtime's lifetime
if constexpr (emper::STATS) {
printLastRuntimeStats();
emper::io::Stats::printWorkerStats();
}
for (unsigned int i = 0; i < workerCount; ++i) { for (unsigned int i = 0; i < workerCount; ++i) {
delete workers[i]; delete workers[i];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment