mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-03 06:16:04 +00:00
add PPSMonitor
This commit is contained in:
committed by
Anonymous275
parent
72607583bf
commit
f19a012509
35
src/TPPSMonitor.cpp
Normal file
35
src/TPPSMonitor.cpp
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user