Skip to content

Commit 4afec45

Browse files
authored
Log query times (#531)
* Hello World * Hello World * Print each query time into server console while startup * Log query times into logs/surftimer/<map>.log logs
1 parent 0956982 commit 4afec45

File tree

6 files changed

+170
-81
lines changed

6 files changed

+170
-81
lines changed

addons/sourcemod/scripting/SurfTimer.sp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,26 @@ public void OnMapStart()
180180

181181
// Load spawns
182182
if (!g_bRenaming && !g_bInTransactionChain)
183+
{
183184
checkSpawnPoints();
185+
}
184186

185187
db_viewMapSettings();
186188

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

190-
if(g_tables_converted){
192+
if(g_tables_converted)
193+
{
191194
if (!g_bRenaming && !g_bInTransactionChain && (IsServerProcessing() || !cvHibernateWhenEmpty.BoolValue))
192195
{
193-
LogToFileEx(g_szLogFile, "[surftimer] Starting to load server settings");
196+
LogQueryTime("[surftimer] Starting to load server settings");
194197
g_fServerLoading[0] = GetGameTime();
195198
db_selectMapZones();
196199
}
197200
}
198-
else{
201+
else
202+
{
199203
CreateTimer(1.0, DatabaseUpgrading, INVALID_HANDLE, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
200204
}
201205

@@ -217,7 +221,9 @@ public void OnMapStart()
217221
}
218222

219223
for (int i = 0; i < MAX_STYLES; i++)
224+
{
220225
g_bReplayTickFound[i] = false;
226+
}
221227

222228
// Precache
223229
InitPrecache();
@@ -249,7 +255,9 @@ public void OnMapStart()
249255
// Hook Zones
250256
iEnt = -1;
251257
if (g_hTriggerMultiple != null)
258+
{
252259
CloseHandle(g_hTriggerMultiple);
260+
}
253261

254262
g_hTriggerMultiple = CreateArray(256);
255263
while ((iEnt = FindEntityByClassname(iEnt, "trigger_multiple")) != -1)

addons/sourcemod/scripting/surftimer/convars.sp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ConVar g_iHintsInterval = null; // Time between two hints. 0 = off
115115
ConVar g_bHintsRandomOrder = null; // If hints are in random order
116116
ConVar g_hOverrideClantag = null;
117117
ConVar g_hDefaultPreSpeed = null;
118+
ConVar g_hLogQueryTimes = null;
118119

119120
void CreateConVars()
120121
{
@@ -408,6 +409,7 @@ void CreateConVars()
408409
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");
409410

410411
g_hLimitSpeedType = AutoExecConfig_CreateConVar("ck_limit_speed_type", "1", "1 Use new style of limiting speed, 0 use old/cksurf way");
412+
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);
411413

412414
// Server Name
413415
g_hHostName = FindConVar("hostname");

addons/sourcemod/scripting/surftimer/db/updater.sp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void SQLCheckDataType(Handle owner, Handle hndl, const char[] error, Data
284284

285285
if (!g_bRenaming && !g_bInTransactionChain && (IsServerProcessing() || !cvHibernateWhenEmpty.BoolValue))
286286
{
287-
LogToFileEx(g_szLogFile, "[surftimer] Starting to load server settings");
287+
LogQueryTime("[surftimer] Starting to load server settings");
288288
g_fServerLoading[0] = GetGameTime();
289289
db_selectMapZones();
290290
}

addons/sourcemod/scripting/surftimer/mapsettings.sp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,13 @@ public void db_viewMapSettings()
273273
{
274274
char szQuery[2048];
275275
Format(szQuery, 2048, "SELECT `mapname`, `maxvelocity`, `announcerecord`, `gravityfix` FROM `ck_maptier` WHERE `mapname` = '%s'", g_szMapName);
276-
SQL_TQuery(g_hDb, sql_viewMapSettingsCallback, szQuery, _, DBPrio_High);
276+
SQL_TQuery(g_hDb, sql_viewMapSettingsCallback, szQuery, GetGameTime(), DBPrio_High);
277277
}
278278

279-
public void sql_viewMapSettingsCallback(Handle owner, Handle hndl, const char[] error, any pack)
279+
public void sql_viewMapSettingsCallback(Handle owner, Handle hndl, const char[] error, float time)
280280
{
281+
LogQueryTime("[SurfTimer] : Finished sql_viewMapSettingsCallback in: %f", GetGameTime() - time);
282+
281283
if (hndl == null)
282284
{
283285
LogError("[SurfTimer] SQL Error (sql_viewMapSettingsCallback): %s", error);

addons/sourcemod/scripting/surftimer/misc.sp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5554,4 +5554,19 @@ public void resetCCPDefaults(int client){
55545554
g_iCCP_StageRank_Player[client][i] = 0;
55555555
g_iCCP_StageTotal_Player[client][i] = 0;
55565556
}
5557-
}
5557+
}
5558+
5559+
void LogQueryTime(const char[] format, any ...)
5560+
{
5561+
char sMessage[512];
5562+
VFormat(sMessage, sizeof(sMessage), format, 2);
5563+
5564+
if (g_hLogQueryTimes.BoolValue)
5565+
{
5566+
LogToFileEx(g_szLogFile, sMessage);
5567+
}
5568+
else
5569+
{
5570+
PrintToServer(sMessage);
5571+
}
5572+
}

0 commit comments

Comments
 (0)