diff --git a/code/__HELPERS/_logging.dm b/code/__HELPERS/_logging.dm index 6585aebd36a..8e02faa3834 100644 --- a/code/__HELPERS/_logging.dm +++ b/code/__HELPERS/_logging.dm @@ -128,6 +128,9 @@ /proc/log_qdel(text) WRITE_LOG(GLOB.world_qdel_log, "QDEL: [text]") +/proc/log_qdl(text) + WRITE_LOG(GLOB.query_debug_log, "SQL: [text]") + /* Log to both DD and the logfile. */ /proc/log_world(text) WRITE_LOG(GLOB.world_runtime_log, text) diff --git a/code/_globalvars/logging.dm b/code/_globalvars/logging.dm index ff397785d89..545ffbcbefc 100644 --- a/code/_globalvars/logging.dm +++ b/code/_globalvars/logging.dm @@ -20,6 +20,8 @@ GLOBAL_VAR(world_pda_log) GLOBAL_PROTECT(world_pda_log) GLOBAL_VAR(world_manifest_log) GLOBAL_PROTECT(world_manifest_log) +GLOBAL_VAR(query_debug_log) +GLOBAL_PROTECT(query_debug_log) GLOBAL_LIST_EMPTY(bombers) GLOBAL_PROTECT(bombers) diff --git a/code/controllers/subsystem/dbcore.dm b/code/controllers/subsystem/dbcore.dm index 0609b78d999..c3e8fb2f07d 100644 --- a/code/controllers/subsystem/dbcore.dm +++ b/code/controllers/subsystem/dbcore.dm @@ -37,10 +37,10 @@ SUBSYSTEM_DEF(dbcore) message_admins("Database schema ([db_major].[db_minor]) doesn't match the latest schema version ([DB_MAJOR_VERSION].[DB_MINOR_VERSION]), this may lead to undefined behaviour or errors") if(2) message_admins("Could not get schema version from database") - + return ..() - + /datum/controller/subsystem/dbcore/Recover() _db_con = SSdbcore._db_con @@ -231,10 +231,20 @@ Delayed insert mode was removed in mysql 7 and only works with MyISAM type table to_chat(usr, "A SQL error occurred during this operation, check the server logs.") /datum/DBQuery/proc/Execute(sql_query = sql, cursor_handler = default_cursor, log_error = TRUE) + log_qdl("Query execution started at [SQLtime()] | [REALTIMEOFDAY]") + var/stime = REALTIMEOFDAY + log_qdl("Query used: [sql]") Close() . = _dm_db_execute(_db_query, sql_query, db_connection._db_con, cursor_handler, null) if(!. && log_error) log_sql("[ErrorMsg()] | Query used: [sql]") + log_qdl("Query execution ended at [SQLtime()] | [REALTIMEOFDAY]") + if((REALTIMEOFDAY - stime) > 70) + log_qdl("Possible query overrun detected.") + bother_admins() + +/proc/bother_admins() + message_admins("HEY! A database query may have overrun. Did the server just hang? \[YES\]|\[NO\]") /datum/DBQuery/proc/NextRow() return _dm_db_next_row(_db_query,item,conversions) diff --git a/code/game/world.dm b/code/game/world.dm index 9ea419bb3ba..f950efc2c98 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -20,7 +20,7 @@ GLOBAL_PROTECT(security_mode) TgsNew() GLOB.revdata = new - + config.Load() //SetupLogs depends on the RoundID, so lets check @@ -92,6 +92,7 @@ GLOBAL_PROTECT(security_mode) GLOB.sql_error_log = "[GLOB.log_directory]/sql.log" GLOB.world_qdel_log = "[GLOB.log_directory]/qdel.log" GLOB.world_runtime_log = "[GLOB.log_directory]/runtime.log" + GLOB.query_debug_log = "[GLOB.log_directory]/qdl.log" #ifdef UNIT_TESTS GLOB.test_log = file("[GLOB.log_directory]/tests.log") diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 4115b730b29..c0be09ac5b7 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -2461,6 +2461,19 @@ usr.client.cmd_admin_mod_antag_rep(C, href_list["modantagrep"]) show_player_panel(M) + else if(href_list["slowquery"]) + if(!check_rights(R_ADMIN)) + return + var/a = href_list["slowquery"] + if(a == "yes") + log_qdl("[usr.key] | reported hang") + if(alert(usr, "Had you just press any admin buttons?", "Query hang report", "Yes", "No") == "Yes") + var/s = input(usr,"What were you just doing?","Query hang report") as null|text + if(s) + log_qdl("[usr.key] | [s]") + else if(a == "no") + log_qdl("[usr.key] | reported no hang") + /datum/admins/proc/HandleCMode() if(!check_rights(R_ADMIN)) return