fix project 2 bugz
This commit is contained in:
parent
1570e9f069
commit
1a4a72ecdd
5
main.cpp
5
main.cpp
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
std::mutex metrics_mutex {};
|
||||||
|
|
||||||
auto onClientConnected(networked& client)
|
auto onClientConnected(networked& client)
|
||||||
{
|
{
|
||||||
sscout << "Accepted Client on Server.\n";
|
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)
|
net_client.message_received += [&](std::string& message)
|
||||||
{
|
{
|
||||||
auto elapsed = clock.elapsed<double, std::milli>();
|
auto elapsed = clock.elapsed<double, std::milli>();
|
||||||
|
const std::lock_guard<std::mutex> lock(metrics_mutex);
|
||||||
auto client_num = this_job.client_metrics.size()+1;
|
auto client_num = this_job.client_metrics.size()+1;
|
||||||
//UX
|
//UX
|
||||||
sscout << client_num << math::numerical_suffix(client_num) << " client response\n"
|
sscout << client_num << math::numerical_suffix(client_num) << " client response\n"
|
||||||
@ -151,4 +154,4 @@ int main() {
|
|||||||
<< "╘════════════════════╝\n";
|
<< "╘════════════════════╝\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,23 @@ namespace metrics
|
|||||||
inline void to_json(json& j, const job& p)
|
inline void to_json(json& j, const job& p)
|
||||||
{
|
{
|
||||||
auto total_trip_time = 0.;
|
auto total_trip_time = 0.;
|
||||||
|
auto summation_time = 0.f;
|
||||||
for(auto&& client : p.client_metrics)
|
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;
|
total_trip_time += client.trip_time;
|
||||||
j = json{
|
#endif
|
||||||
|
}
|
||||||
|
j = json{
|
||||||
{ "operation", p.operation },
|
{ "operation", p.operation },
|
||||||
{ "total_trip_time", total_trip_time },
|
{ "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}
|
{ "client_metrics", p.client_metrics}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::vector<job> job_metrics{};
|
inline std::vector<job> job_metrics{};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user