#include "stats.hpp" void Stats::accept_connection(std::unique_ptr&& socket) { auto it = connections.emplace(connections.end(), std::move(socket)); it->on_done([this, it](){ connections.erase(it); }); it->async_receive([it, this](cmix_proto::CMixMessage const& message) { handle_message(it, message); }); } void Stats::handle_performance(std::list::iterator it, const cmix_proto::Performance& perf) { data[perf.node()][perf.column() + "wall_time"].push_back(std::stol(perf.wall_time())); data[perf.node()][perf.column() + "system_time"].push_back(std::stol(perf.system_time())); data[perf.node()][perf.column() + "user_time"].push_back(std::stol(perf.user_time())); it->async_receive([it, this](cmix_proto::CMixMessage const& message) { handle_message(it, message); }); } void Stats::handle_message(std::list::iterator it, cmix_proto::CMixMessage message) { switch(message.contents_case()) { case cmix_proto::CMixMessage::ContentsCase::kPerformance: { BOOST_LOG_TRIVIAL(trace) << "Handling performance"; handle_performance(it, message.performance()); break; } case cmix_proto::CMixMessage::ContentsCase::kBye: { BOOST_LOG_TRIVIAL(trace) << "Handling Bye"; break; } default: { BOOST_LOG_TRIVIAL(error) << "handle_message: CMixMessage contains unknown contents."; connections.erase(it); } } } Stats::Stats(ListenSettings lsettings) : io_service() , server(io_service, lsettings, [this](std::unique_ptr&& socket){accept_connection(std::move(socket));}) {} void Stats::run() { io_service.run(); }