Skip to content

Commit

Permalink
Log query times (#531)
Browse files Browse the repository at this point in the history
* Hello World

* Hello World

* Print each query time into server console while startup

* Log query times into logs/surftimer/<map>.log logs
  • Loading branch information
Bara authored Oct 16, 2022
1 parent 0956982 commit 4afec45
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 81 deletions.
14 changes: 11 additions & 3 deletions addons/sourcemod/scripting/SurfTimer.sp
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,26 @@ public void OnMapStart()

// Load spawns
if (!g_bRenaming && !g_bInTransactionChain)
{
checkSpawnPoints();
}

db_viewMapSettings();

/// Start Loading Server Settings
ConVar cvHibernateWhenEmpty = FindConVar("sv_hibernate_when_empty");

if(g_tables_converted){
if(g_tables_converted)
{
if (!g_bRenaming && !g_bInTransactionChain && (IsServerProcessing() || !cvHibernateWhenEmpty.BoolValue))
{
LogToFileEx(g_szLogFile, "[surftimer] Starting to load server settings");
LogQueryTime("[surftimer] Starting to load server settings");
g_fServerLoading[0] = GetGameTime();
db_selectMapZones();
}
}
else{
else
{
CreateTimer(1.0, DatabaseUpgrading, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}

Expand All @@ -217,7 +221,9 @@ public void OnMapStart()
}

for (int i = 0; i < MAX_STYLES; i++)
{
g_bReplayTickFound[i] = false;
}

// Precache
InitPrecache();
Expand Down Expand Up @@ -249,7 +255,9 @@ public void OnMapStart()
// Hook Zones
iEnt = -1;
if (g_hTriggerMultiple != null)
{
CloseHandle(g_hTriggerMultiple);
}

g_hTriggerMultiple = CreateArray(256);
while ((iEnt = FindEntityByClassname(iEnt, "trigger_multiple")) != -1)
Expand Down
2 changes: 2 additions & 0 deletions addons/sourcemod/scripting/surftimer/convars.sp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ ConVar g_iHintsInterval = null; // Time between two hints. 0 = off
ConVar g_bHintsRandomOrder = null; // If hints are in random order
ConVar g_hOverrideClantag = null;
ConVar g_hDefaultPreSpeed = null;
ConVar g_hLogQueryTimes = null;

void CreateConVars()
{
Expand Down Expand Up @@ -408,6 +409,7 @@ void CreateConVars()
g_hSlayOnRoundEnd = AutoExecConfig_CreateConVar("ck_slay_on_round_end", "1", "If enabled, all players will be slain on round end. If disabled all players timers will be stopped on round end");

g_hLimitSpeedType = AutoExecConfig_CreateConVar("ck_limit_speed_type", "1", "1 Use new style of limiting speed, 0 use old/cksurf way");
g_hLogQueryTimes = AutoExecConfig_CreateConVar("ck_log_query_times", "1", "Log query times or just print in server console. Default \"0\", it'll just print into servers console.", _, true, 0.0, true, 1.0);

// Server Name
g_hHostName = FindConVar("hostname");
Expand Down
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/surftimer/db/updater.sp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void SQLCheckDataType(Handle owner, Handle hndl, const char[] error, Data

if (!g_bRenaming && !g_bInTransactionChain && (IsServerProcessing() || !cvHibernateWhenEmpty.BoolValue))
{
LogToFileEx(g_szLogFile, "[surftimer] Starting to load server settings");
LogQueryTime("[surftimer] Starting to load server settings");
g_fServerLoading[0] = GetGameTime();
db_selectMapZones();
}
Expand Down
6 changes: 4 additions & 2 deletions addons/sourcemod/scripting/surftimer/mapsettings.sp
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ public void db_viewMapSettings()
{
char szQuery[2048];
Format(szQuery, 2048, "SELECT `mapname`, `maxvelocity`, `announcerecord`, `gravityfix` FROM `ck_maptier` WHERE `mapname` = '%s'", g_szMapName);
SQL_TQuery(g_hDb, sql_viewMapSettingsCallback, szQuery, _, DBPrio_High);
SQL_TQuery(g_hDb, sql_viewMapSettingsCallback, szQuery, GetGameTime(), DBPrio_High);
}

public void sql_viewMapSettingsCallback(Handle owner, Handle hndl, const char[] error, any pack)
public void sql_viewMapSettingsCallback(Handle owner, Handle hndl, const char[] error, float time)
{
LogQueryTime("[SurfTimer] : Finished sql_viewMapSettingsCallback in: %f", GetGameTime() - time);

if (hndl == null)
{
LogError("[SurfTimer] SQL Error (sql_viewMapSettingsCallback): %s", error);
Expand Down
17 changes: 16 additions & 1 deletion addons/sourcemod/scripting/surftimer/misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5554,4 +5554,19 @@ public void resetCCPDefaults(int client){
g_iCCP_StageRank_Player[client][i] = 0;
g_iCCP_StageTotal_Player[client][i] = 0;
}
}
}

void LogQueryTime(const char[] format, any ...)
{
char sMessage[512];
VFormat(sMessage, sizeof(sMessage), format, 2);

if (g_hLogQueryTimes.BoolValue)
{
LogToFileEx(g_szLogFile, sMessage);
}
else
{
PrintToServer(sMessage);
}
}
Loading

0 comments on commit 4afec45

Please sign in to comment.