add PPSMonitor

This commit is contained in:
Lion Kortlepel
2021-02-16 13:19:39 +01:00
committed by Anonymous275
parent 72607583bf
commit f19a012509
15 changed files with 185 additions and 66 deletions

35
src/TPPSMonitor.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "TPPSMonitor.h"
#include "Client.h"
TPPSMonitor::TPPSMonitor(TServer& Server)
: mServer(Server) {
Application::SetPPS("-");
Application::RegisterShutdownHandler([&] { mShutdown = true; });
}
void TPPSMonitor::operator()() {
while (!mShutdown) {
int C = 0, V = 0;
if (mServer.ClientCount() == 0) {
Application::SetPPS("-");
return;
}
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
if (!ClientPtr.expired()) {
auto c = ClientPtr.lock();
if (c->GetCarCount() > 0) {
C++;
V += c->GetCarCount();
}
}
return true;
});
if (C == 0 || mInternalPPS == 0) {
Application::SetPPS("-");
} else {
int R = (mInternalPPS / C) / V;
Application::SetPPS(std::to_string(R));
}
mInternalPPS = 0;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}