@@ -43,6 +43,8 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
43
43
var /init_timeofday
44
44
var /init_time
45
45
var /tickdrift = 0
46
+ // / Tickdrift as of last tick, w no averaging going on
47
+ var /olddrift = 0
46
48
47
49
// / How long is the MC sleeping between runs, read only (set by Loop() based off of anti-tick-contention heuristics)
48
50
var /sleep_delta = 1
@@ -71,6 +73,10 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
71
73
// / Outside of initialization, returns null.
72
74
var /current_initializing_subsystem = null
73
75
76
+ // / The last decisecond we force dumped profiling information
77
+ // / Used to avoid spamming profile reads since they can be expensive (string memes)
78
+ var /last_profiled = 0
79
+
74
80
var /static /restart_clear = 0
75
81
var /static /restart_timeout = 0
76
82
var /static /restart_count = 0
@@ -388,9 +394,14 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
388
394
canary. use_variable()
389
395
// the actual loop.
390
396
while (1 )
391
- tickdrift = max(0 , MC_AVERAGE_FAST (tickdrift, (((REALTIMEOFDAY - init_timeofday) - (world . time - init_time)) / world . tick_lag)))
397
+ var /newdrift = ((REALTIMEOFDAY - init_timeofday) - (world . time - init_time)) / world . tick_lag
398
+ tickdrift = max(0 , MC_AVERAGE_FAST (tickdrift, newdrift))
392
399
var /starting_tick_usage = TICK_USAGE
393
400
401
+ if (newdrift - olddrift >= CONFIG_GET (number/ drift_dump_threshold))
402
+ AttemptProfileDump (CONFIG_GET (number/ drift_profile_delay))
403
+ olddrift = newdrift
404
+
394
405
if (init_stage != init_stage_completed)
395
406
return MC_LOOP_RTN_NEWSTAGES
396
407
if (processing <= 0 )
@@ -763,3 +774,11 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
763
774
for (var /thing in subsystems)
764
775
var /datum /controller/subsystem/SS = thing
765
776
SS . OnConfigLoad()
777
+
778
+ // / Attempts to dump our current profile info into a file, triggered if the MC thinks shit is going down
779
+ // / Accepts a delay in deciseconds of how long ago our last dump can be, this saves causing performance problems ourselves
780
+ / datum / controller/ master/ proc / AttemptProfileDump(delay)
781
+ if (REALTIMEOFDAY - last_profiled <= delay)
782
+ return FALSE
783
+ last_profiled = REALTIMEOFDAY
784
+ SSprofiler. DumpFile(allow_yield = FALSE )
0 commit comments