Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 7fe776c

Browse files
Makes our master far less dumpy in private (#21488)
* maybe that will help? * main server will profile but private servers won't unless enabled
1 parent 8e2b15c commit 7fe776c

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

code/__DEFINES/subsystems.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@
173173
#define INIT_ORDER_PATH -50
174174
#define INIT_ORDER_DISCORD -60
175175
#define INIT_ORDER_EXPLOSIONS -69
176-
#define INIT_ORDER_STATPANELS -98
176+
#define INIT_ORDER_STATPANELS -97
177+
#define INIT_ORDER_INIT_PROFILER -98 //Near the end, logs the costs of initialize
177178
#define INIT_ORDER_DEMO -99 // To avoid a bunch of changes related to initialization being written, do this last
178179
#define INIT_ORDER_CHAT -100 //Should be last to ensure chat remains smooth during init.
179180

code/controllers/master.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
474474
var/newdrift = ((REALTIMEOFDAY - init_timeofday) - (world.time - init_time)) / world.tick_lag
475475
tickdrift = max(0, MC_AVERAGE_FAST(tickdrift, newdrift))
476476
var/starting_tick_usage = TICK_USAGE
477-
478-
if(newdrift - olddrift >= CONFIG_GET(number/drift_dump_threshold))
477+
//Yog: profile dumping was throttling lower performance computers, so we're going to have it disabled by default but you can enable it via config flags
478+
if(newdrift - olddrift >= CONFIG_GET(number/drift_dump_threshold) && CONFIG_GET(flag/auto_profile))
479479
AttemptProfileDump(CONFIG_GET(number/drift_profile_delay))
480480
olddrift = newdrift
481481

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#define INIT_PROFILE_NAME "init_profiler.json"
2+
3+
///Subsystem exists so we can separately log init time costs from the costs of general operation
4+
///Hopefully this makes sorting out what causes problems when easier
5+
SUBSYSTEM_DEF(init_profiler)
6+
name = "Init Profiler"
7+
init_order = INIT_ORDER_INIT_PROFILER
8+
init_stage = INITSTAGE_MAX
9+
flags = SS_NO_FIRE
10+
11+
/datum/controller/subsystem/init_profiler/Initialize()
12+
if(CONFIG_GET(flag/auto_profile))
13+
write_init_profile()
14+
return SS_INIT_SUCCESS
15+
16+
/datum/controller/subsystem/init_profiler/proc/write_init_profile()
17+
var/current_profile_data = world.Profile(PROFILE_REFRESH, format = "json")
18+
CHECK_TICK
19+
20+
if(!length(current_profile_data)) //Would be nice to have explicit proc to check this
21+
stack_trace("Warning, profiling stopped manually before dump.")
22+
var/prof_file = file("[GLOB.log_directory]/[INIT_PROFILE_NAME]")
23+
if(fexists(prof_file))
24+
fdel(prof_file)
25+
WRITE_FILE(prof_file, current_profile_data)
26+
world.Profile(PROFILE_CLEAR) //Now that we're written this data out, dump it. We don't want it getting mixed up with our current round data
27+
28+
#undef INIT_PROFILE_NAME

config/config.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ DEFAULT_VIEW 19x15
422422
## You probably shouldn't ever be changing this, but it's here if you want to.
423423
DEFAULT_VIEW_SQUARE 15x15
424424

425+
426+
## Enable automatic profiling - Byond 513.1506 and newer only.
427+
#AUTO_PROFILE
428+
429+
## Threshold (in deciseconds) for real time between ticks before we start dumping profiles
430+
DRIFT_DUMP_THRESHOLD 40
431+
432+
## How long to wait (in deciseconds) after a profile dump before logging another tickdrift sourced one
433+
DRIFT_PROFILE_DELAY 150
434+
425435
## Comment this out if you want to use the SQL based mentor system, the legacy system uses mentors.txt.
426436
## You need to set up your database to use the SQL based system.
427437
## This flag is automatically enabled if SQL_ENABLED isn't

config/private_default.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ VOICE_ANNOUNCE_DIR ../Yogstation.net/voice_announce_tmp
8686
## Enable the demo subsystem
8787
#DEMOS_ENABLED
8888

89-
## Starlight for exterior walls and breaches. Uncomment for starlight!
90-
## This is disabled by default to make testing quicker, should be enabled on production servers or testing servers messing with lighting
91-
#STARLIGHT
89+
## Enable automatic profiling - Byond 513.1506 and newer only.
90+
#AUTO_PROFILE
9291

9392

9493
## Assets can opt-in to caching their results into `tmp`.

config/private_server.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ VOICE_ANNOUNCE_DIR data/voice_announcements
9797
## Enable the demo subsystem
9898
DEMOS_ENABLED
9999

100+
## Enable automatic profiling - Byond 513.1506 and newer only.
101+
AUTO_PROFILE
102+
100103
## Starlight for exterior walls and breaches. Uncomment for starlight!
101104
## This is disabled by default to make testing quicker, should be enabled on production servers or testing servers messing with lighting
102105
STARLIGHT

yogstation.dme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@
422422
#include "code\controllers\subsystem\garbage.dm"
423423
#include "code\controllers\subsystem\icon_smooth.dm"
424424
#include "code\controllers\subsystem\idlenpcpool.dm"
425+
#include "code\controllers\subsystem\init_profiler.dm"
425426
#include "code\controllers\subsystem\input.dm"
426427
#include "code\controllers\subsystem\ipintel.dm"
427428
#include "code\controllers\subsystem\job.dm"

0 commit comments

Comments
 (0)