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

Merge branch 'fix-io-stats' into 'master'

Fix race condition in io::Stats

See merge request !160
parents 385ec1c3 8d252617
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
/build-*/
/.cache/
/.clangd/
subprojects/packagecache/
subprojects/googletest*
......@@ -165,7 +165,7 @@ Runtime::~Runtime() {
// objects bound to the runtime's lifetime
if constexpr (emper::STATS) {
printLastRuntimeStats();
emper::io::Stats::printWorkerStats();
emper::io::Stats::printStats(globalIo, ioContexts);
}
for (unsigned int i = 0; i < workerCount; ++i) {
......
......@@ -181,5 +181,7 @@ class IoContext : public Logger<LogSubsystem::IO> {
}
}
}
auto getStats() -> Stats & { return stats; };
};
} // namespace emper::io
......@@ -7,13 +7,12 @@
#include <string> // for operator<<, to_string
#include <utility> // for pair
#include "io/IoContext.hpp"
#include "io/Operation.hpp" // for Operation, operator<<, Operation::RECV
#include "lib/math.hpp"
namespace emper::io {
std::vector<Stats*> Stats::workerStats;
auto operator<<(std::ostream& os, const Stats::CompletionType& t) -> std::ostream& {
switch (t) {
case Stats::CompletionType::FullCompletion:
......@@ -118,10 +117,9 @@ auto operator<<(std::ostream& os, const Stats& s) -> std::ostream& {
return os;
}
void Stats::printWorkerStats() {
auto* globalStats = workerStats.front();
workerStats.erase(workerStats.begin());
std::cout << *globalStats << std::endl;
void Stats::printStats(IoContext* globalIoContext,
const std::vector<IoContext*>& workerIoContexts) {
std::cout << globalIoContext->getStats() << std::endl;
// Use a stats object to calculate the averages
Stats avgs;
......@@ -130,7 +128,8 @@ void Stats::printWorkerStats() {
// calculate avgs
int i = 1;
for (auto& stats : workerStats) {
for (auto* workerIoContext : workerIoContexts) {
auto* stats = &workerIoContext->getStats();
for (const auto& op_pair : stats->io_uring_completions) {
auto op = op_pair.first;
auto op_map = op_pair.second;
......
......@@ -24,6 +24,11 @@
#include "lib/math.hpp"
class Runtime; // lines 28-28
namespace emper {
namespace io {
class IoContext;
}
} // namespace emper
namespace math = emper::lib::math;
......@@ -52,8 +57,6 @@ class Stats {
int workerId = 0;
static_assert(sizeof(int) > sizeof(workerid_t));
static std::vector<Stats*> workerStats;
enum CompletionType {
FullCompletion = 0,
ErrorCompletion,
......@@ -125,13 +128,10 @@ class Stats {
unsigned reReapCount_max = 0;
boost::circular_buffer<unsigned> reReapCount_last;
static void printWorkerStats();
static void printStats(IoContext* globalIoContext,
const std::vector<IoContext*>& workerIoContexts);
Stats() : reReapCount_last(10) {
if constexpr (emper::STATS) {
workerStats.push_back(this);
}
}
Stats() : reReapCount_last(10) {}
void recordCompletion(const Future& f, const int32_t& res) {
record_completion(f.op, res, PartialCompletableFuture::DISABLE_PARTIAL_COMPLETION, f.len);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment