Files
Aurora.3/code/controllers/subsystems/profiler.dm
Matt Atlas cadd19beac Ports the TG globals controller and converts globals. (#18057)
* SDQL2 update

* fix that verb

* cl

* fix that

* toworld

* this is pointless

* update info

* siiiiick..

* vv edit update

* fix that

* fix editing vars

* fix VV

* Port the /TG/ globals controller.

* part 1

* part 2

* oops

* part 3

* Hollow Purple

* sadas

* bsbsdb

* muda na agaki ta

* ids 1-15

* 16-31

* 41-75

* bring me back to how things used to be before i lost it all

* the strength of mayhem

* final touches

* cl

* protect some vars

* update sdql2 to use glob

* stuff?

* forgot that is not defined there

* whoops

* observ

* but it never gets better

* a

---------

Co-authored-by: Matt Atlas <liermattia@gmail.com>
2023-12-26 01:16:02 +00:00

60 lines
1.6 KiB
Plaintext

SUBSYSTEM_DEF(profiler)
name = "Profiler"
wait = 1
priority = SS_PRIORITY_PROFILE
flags = SS_TICKER
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
var/last_fire_rt = 0
var/threshold = 0
var/next_restart = 0
var/restart_period = 0
/datum/controller/subsystem/profiler/Initialize()
if (!GLOB.config.profiler_is_enabled)
..()
flags |= SS_NO_FIRE
return
restart_period = GLOB.config.profiler_restart_period
threshold = GLOB.config.profiler_timeout_threshold
..()
/datum/controller/subsystem/profiler/Shutdown()
. = ..()
if (GLOB.config.profiler_is_enabled)
DumpData()
world.Profile(PROFILE_CLEAR, type="sendmaps")
/datum/controller/subsystem/profiler/fire()
. = world.timeofday
if (!last_fire_rt)
last_fire_rt = .
next_restart = world.time + restart_period
world.Profile(PROFILE_START)
world.Profile(PROFILE_START, type="sendmaps")
if (. - last_fire_rt > threshold)
DumpData()
else if (world.time > next_restart)
RestartProfiler()
last_fire_rt = .
/datum/controller/subsystem/profiler/proc/DumpData()
log_perf("Profiler: dump profile after CPU spike.")
admin_notice(SPAN_DANGER("Profiler: dump profile after CPU spike."), R_SERVER|R_DEV)
var/name = "[game_id]_[time2text(world.timeofday, "hh-mm-ss")]"
text2file(world.Profile(PROFILE_REFRESH, "json"), "data/logs/[game_id]/profiler/[name].json")
text2file(world.Profile(PROFILE_REFRESH, type = "sendmaps", format = "json"), "data/logs/[game_id]/profiler/[name]_sendmaps.json")
/datum/controller/subsystem/profiler/proc/RestartProfiler()
world.Profile(PROFILE_CLEAR)
world.Profile(PROFILE_CLEAR, type="sendmaps")
next_restart = world.time + restart_period