Files
CHOMPStation2/code/controllers/subsystems/processing/processing.dm
Neerti 9c6886395a Merge pull request #6118 from Novacat/nova-alerts
Ports Baystation's SS Debugging
2019-04-25 17:03:43 -04:00

66 lines
2.2 KiB
Plaintext

//Used to process objects. Fires once every second.
SUBSYSTEM_DEF(processing)
name = "Processing"
priority = FIRE_PRIORITY_PROCESS
flags = SS_BACKGROUND|SS_POST_FIRE_TIMING|SS_NO_INIT
wait = 10
var/stat_tag = "P" //Used for logging
var/list/processing = list()
var/list/currentrun = list()
var/process_proc = /datum/proc/process
var/debug_last_thing
var/debug_original_process_proc // initial() does not work with procs
/datum/controller/subsystem/processing/stat_entry()
..("[stat_tag]:[processing.len]")
/datum/controller/subsystem/processing/fire(resumed = 0)
if (!resumed)
currentrun = processing.Copy()
//cache for sanic speed (lists are references anyways)
var/list/current_run = currentrun
while(current_run.len)
var/datum/thing = current_run[current_run.len]
current_run.len--
if(QDELETED(thing))
processing -= thing
else if(thing.process(wait) == PROCESS_KILL)
// fully stop so that a future START_PROCESSING will work
STOP_PROCESSING(src, thing)
if (MC_TICK_CHECK)
return
/datum/controller/subsystem/processing/proc/toggle_debug()
if(!check_rights(R_DEBUG))
return
if(debug_original_process_proc)
process_proc = debug_original_process_proc
debug_original_process_proc = null
else
debug_original_process_proc = process_proc
process_proc = /datum/proc/DebugSubsystemProcess
to_chat(usr, "[name] - Debug mode [debug_original_process_proc ? "en" : "dis"]abled")
/datum/proc/DebugSubsystemProcess(var/wait, var/times_fired, var/datum/controller/subsystem/processing/subsystem)
subsystem.debug_last_thing = src
var/start_tick = world.time
var/start_tick_usage = world.tick_usage
. = call(src, subsystem.debug_original_process_proc)(wait, times_fired)
var/tick_time = world.time - start_tick
var/tick_use_limit = world.tick_usage - start_tick_usage - 100 // Current tick use - starting tick use - 100% (a full tick excess)
if(tick_time > 0)
crash_with("[log_info_line(subsystem.debug_last_thing)] slept during processing. Spent [tick_time] tick\s.")
if(tick_use_limit > 0)
crash_with("[log_info_line(subsystem.debug_last_thing)] took longer than a tick to process. Exceeded with [tick_use_limit]%")
/datum/proc/process()
set waitfor = 0
return PROCESS_KILL