feat(servers): time the main loops' phases and the known heavy spots

Frames and phase scopes in the world, auth, chat and UGC loops (packets per type, entities, physics, ghosting, replica, spawners, log flush, saves, web requests by route). Scopes at LoadPlayer, CreateEntity, each component's construction, InventoryComponent::LoadXml, script timers and a world's zone load; game database queries in the query helpers; CDClient statements timed through sqlite3_trace_v2 as CDClient <table> (CppSQLite3DB gets a handle accessor). Task 96.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 22:06:31 -05:00
parent 63666c3c6b
commit d4e9423264
13 changed files with 164 additions and 14 deletions

View File

@@ -6,6 +6,7 @@
#include <thread>
//DLU Includes:
#include "Profiler.h"
#include "dCommonVars.h"
#include "ConfigSync.h"
#include "dServer.h"
@@ -117,6 +118,7 @@ int main(int argc, char** argv) {
Game::logger->Flush(); // once immediately before main loop
while (!Game::ShouldShutdown()) {
Profiler::BeginFrame();
//Check if we're still connected to master:
if (!Game::server->GetIsConnectedToMaster()) {
framesSinceMasterDisconnect++;
@@ -130,9 +132,13 @@ int main(int argc, char** argv) {
//In world we'd update our other systems here.
//Check for packets here:
Game::server->ReceiveFromMaster(); //ReceiveFromMaster also handles the master packets if needed.
{
Profiler::Scope scope("Master packets", Profiler::Phase::PACKETS);
Game::server->ReceiveFromMaster(); //ReceiveFromMaster also handles the master packets if needed.
}
packet = Game::server->Receive();
if (packet) {
Profiler::PacketScope scope(packet->data, packet->length);
HandlePacket(packet);
Game::server->DeallocatePacket(packet);
packet = nullptr;
@@ -140,6 +146,7 @@ int main(int argc, char** argv) {
//Push our log every 30s:
if (framesSinceLastFlush >= logFlushTime) {
Profiler::Scope scope("Log flush", Profiler::Phase::LOG_FLUSH);
Game::logger->Flush();
framesSinceLastFlush = 0;
} else framesSinceLastFlush++;
@@ -158,6 +165,7 @@ int main(int argc, char** argv) {
framesSinceLastSQLPing = 0;
} else framesSinceLastSQLPing++;
Profiler::EndFrame();
//Sleep our thread since auth can afford to.
t += std::chrono::milliseconds(authFrameDelta); //Auth can run at a lower "fps"
std::this_thread::sleep_until(t);