diff --git a/code/__DEFINES/~monkestation/logging.dm b/code/__DEFINES/~monkestation/logging.dm index 11cf5192d0c3..97d0702cdae7 100644 --- a/code/__DEFINES/~monkestation/logging.dm +++ b/code/__DEFINES/~monkestation/logging.dm @@ -1,3 +1,6 @@ #define LOG_CATEGORY_GAME_LOOC "game-looc" #define LOG_CATEGORY_STORYTELLER "storyteller" -/* #define LOG_CATEGORY_ENQUEUE "enqueue" */ + +#ifdef ENABLE_ENQUEUE_LOGGING +#define LOG_CATEGORY_ENQUEUE "enqueue" +#endif diff --git a/code/__HELPERS/logging/debug.dm b/code/__HELPERS/logging/debug.dm index 0a027a1a5b9f..b9f6bd60f94f 100644 --- a/code/__HELPERS/logging/debug.dm +++ b/code/__HELPERS/logging/debug.dm @@ -62,7 +62,7 @@ #endif SEND_TEXT(world.log, text) -/* +#ifdef ENABLE_ENQUEUE_LOGGING /proc/log_enqueue(text, list/data) logger.Log(LOG_CATEGORY_ENQUEUE, text, data) -*/ +#endif diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 1ee208d5a536..4808c891a20b 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -173,6 +173,7 @@ GLOBAL_REAL(Master, /datum/controller/master) msg += "\t [varname] = [varval]\n" log_world(msg) +/* var/datum/controller/subsystem/BadBoy = Master.last_type_processed var/FireHim = FALSE if(istype(BadBoy)) @@ -188,10 +189,13 @@ GLOBAL_REAL(Master, /datum/controller/master) if(msg) to_chat(GLOB.admins, span_boldannounce("[msg]")) log_world(msg) +*/ if (istype(Master.subsystems)) + /* if(FireHim) Master.subsystems += new BadBoy.type //NEW_SS_GLOBAL will remove the old one + */ subsystems = Master.subsystems current_runlevel = Master.current_runlevel StartProcessing(10) diff --git a/code/controllers/subsystem.dm b/code/controllers/subsystem.dm index d959948ee0f4..a098140c8170 100644 --- a/code/controllers/subsystem.dm +++ b/code/controllers/subsystem.dm @@ -106,9 +106,17 @@ /// Previous subsystem in the queue of subsystems to run this tick var/datum/controller/subsystem/queue_prev +/* var/avg_iter_count = 0 var/avg_drift = 0 - /* var/list/enqueue_log = list() */ +*/ + + STATIC_COOLDOWN_DECLARE(plexora_alert_cooldown) + var/static/list/queued_plexora_alerts + +#ifdef ENABLE_ENQUEUE_LOGGING + var/list/enqueue_log = list() +#endif //Do not blindly add vars here to the bottom, put it where it goes above //If your var only has two values, put it in as a flag. @@ -197,14 +205,37 @@ var/iter_count = 0 - /* enqueue_log.Cut() */ +#ifdef ENABLE_ENQUEUE_LOGGING + enqueue_log.Cut() +#endif for (queue_node = Master.queue_head; queue_node; queue_node = queue_node.queue_next) iter_count++ if(iter_count >= ENQUEUE_SANITY) - /* log_enqueue(msg, list("enqueue_log" = enqueue_log.Copy())) */ - SSplexora.mc_alert("[src] has likely entered an infinite loop in enqueue(), we're restarting the MC immediately!") - stack_trace("enqueue() entered an infinite loop, we're restarting the MC!") - /* enqueue_log.Cut() */ +#ifdef ENABLE_ENQUEUE_LOGGING + log_enqueue(msg, list("enqueue_log" = enqueue_log.Copy())) +#endif + var/base_msg = "[src] (node = [queue_node], prev = [queue_node.queue_prev], next = [queue_node.queue_next])" + if(COOLDOWN_FINISHED(src, plexora_alert_cooldown)) + var/list/lines = list() + if(LAZYLEN(queued_plexora_alerts)) + lines += "[LAZYLEN(queued_plexora_alerts) + 1] enqueue loops have occured within the past minute." + lines += "## Details" + lines += " - [base_msg]" + for(var/queued_msg in queued_plexora_alerts) + lines += " - [queued_msg]" + LAZYNULL(queued_plexora_alerts) + else + lines += "MC restart triggered due to enqueue loop." + lines += "## Details" + lines += base_msg + SSplexora.mc_alert(jointext(lines, "\n")) + COOLDOWN_START(src, plexora_alert_cooldown, 1 MINUTES) + else + LAZYADD(queued_plexora_alerts, "[src] (node = [queue_node], prev = [queue_node.queue_prev], next = [queue_node.queue_next])") + stack_trace("MC restart triggered due to enqueue loop. Details: [base_msg]") +#ifdef ENABLE_ENQUEUE_LOGGING + enqueue_log.Cut() +#endif Recreate_MC() return @@ -212,12 +243,14 @@ queue_node_priority = queue_node.queued_priority queue_node_flags = queue_node.flags - /* enqueue_log["[iter_count]"] = list( +#ifdef ENABLE_ENQUEUE_LOGGING + enqueue_log["[iter_count]"] = list( "node" = "[queue_node]", "next" = "[queue_node.queue_next || "(none)"]", "priority" = queue_node_priority, "flags" = queue_node_flags, - ) */ + ) +#endif if (queue_node_flags & (SS_TICKER|SS_BACKGROUND) == SS_TICKER) if ((SS_flags & (SS_TICKER|SS_BACKGROUND)) != SS_TICKER) @@ -239,10 +272,12 @@ if (queue_node_priority < SS_priority) break +/* if(iter_count > 0) avg_iter_count = avg_iter_count ? ((avg_iter_count + iter_count) * 0.5) : iter_count var/drift = RELATIVE_ERROR(iter_count, avg_iter_count) avg_drift = avg_drift ? ((drift + avg_drift) * 0.5) : drift +*/ queued_time = world.time queued_priority = SS_priority diff --git a/monkestation/code/modules/logging/categories/log_category_debug.dm b/monkestation/code/modules/logging/categories/log_category_debug.dm index b93f1ae561f3..fa1255335e80 100644 --- a/monkestation/code/modules/logging/categories/log_category_debug.dm +++ b/monkestation/code/modules/logging/categories/log_category_debug.dm @@ -1,5 +1,5 @@ -/* +#ifdef ENABLE_ENQUEUE_LOGGING /datum/log_category/debug_enqueue category = LOG_CATEGORY_ENQUEUE debugger_visible = TRUE -*/ +#endif