Statistic reports mainly packets per second

This commit is contained in:
Anonymous275
2020-06-18 21:55:58 +03:00
parent a05acee04f
commit 280e3a8daa
6 changed files with 62 additions and 26 deletions

View File

@@ -90,7 +90,7 @@ void GrabRole(Client*c){
std::thread t1(HTTP,c);
t1.detach();
}
extern int PPS;
void GlobalParser(Client*c, const std::string&Packet){
if(Packet.empty())return;
if(Packet.find("TEST")!=std::string::npos)SyncVehicles(c);
@@ -131,10 +131,9 @@ void GlobalParser(Client*c, const std::string&Packet){
break;
}
//V to Z
if(Packet.length() > 1000){
std::cout << "Received data from: " << c->GetName() << " Size: " << Packet.length() << std::endl;
if(Code <= 90 && Code >= 86){
PPS++;
SendToAll(c,Packet,false,false);
}
if(Code <= 90 && Code >= 86)SendToAll(c,Packet,false,false);
if(Debug)debug("Data : " + Packet);
if(Debug)debug("Vehicle Data Received from " + c->GetName());
}

View File

@@ -6,7 +6,6 @@
#include "Client.hpp"
#include <iostream>
#include <fstream>
#include <thread>
#include <any>

View File

@@ -0,0 +1,33 @@
///
/// Created by Anonymous275 on 6/18/2020
///
#include "Client.hpp"
#include <string>
#include <thread>
std::string StatReport = "-";
int PPS = 0;
[[noreturn]] void Monitor(){
int R,C;
while(true){
if(Clients.empty()){
StatReport = "-";
}else{
C = 0;
for(Client *c : Clients){
if(c->GetCarCount() > 0)C++;
}
if(C == 0 || PPS == 0){
StatReport = "-";
}else{
R = PPS/C;
StatReport = std::to_string(R);
}
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
void StatInit(){
std::thread Init(Monitor);
Init.detach();
}