From 1a4a72ecdd26cf595be05035a603974a82a781d3 Mon Sep 17 00:00:00 2001 From: Riley S Date: Sun, 18 Apr 2021 16:02:33 -0400 Subject: [PATCH] fix project 2 bugz --- main.cpp | 5 ++++- project/metrics.h | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 3e454f0..da29e07 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,8 @@ using json = nlohmann::json; +std::mutex metrics_mutex {}; + auto onClientConnected(networked& client) { sscout << "Accepted Client on Server.\n"; @@ -77,6 +79,7 @@ auto execute_as_client(std::string ipaddress, std::uint16_t port) net_client.message_received += [&](std::string& message) { auto elapsed = clock.elapsed(); + const std::lock_guard lock(metrics_mutex); auto client_num = this_job.client_metrics.size()+1; //UX sscout << client_num << math::numerical_suffix(client_num) << " client response\n" @@ -151,4 +154,4 @@ int main() { << "╘════════════════════╝\n"; return 0; -} \ No newline at end of file +} diff --git a/project/metrics.h b/project/metrics.h index 87f687d..b959bc0 100644 --- a/project/metrics.h +++ b/project/metrics.h @@ -37,15 +37,23 @@ namespace metrics inline void to_json(json& j, const job& p) { auto total_trip_time = 0.; + auto summation_time = 0.f; for(auto&& client : p.client_metrics) + { + summation_time += client.trip_time; + #ifdef THREADED + total_trip_time = client.trip_time > total_trip_time ? client.trip_time : total_trip_time; + #else total_trip_time += client.trip_time; - j = json{ + #endif + } + j = json{ { "operation", p.operation }, { "total_trip_time", total_trip_time }, - { "average_trip_time",total_trip_time / p.client_metrics.size() }, + { "average_trip_time",summation_time / p.client_metrics.size() }, { "client_metrics", p.client_metrics} }; } inline std::vector job_metrics{}; -} \ No newline at end of file +}