SSprofiler

This commit is contained in:
AffectedArc07
2021-01-28 10:59:54 +00:00
parent 3e3b7ff1fd
commit f28fd2eae5
6 changed files with 63 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
// This file exists so that world.Profile() is THE FIRST PROC TO RUN in the init sequence. This allows us to get the real details of everything lagging at server start.
// We don't actually care about storing the output here, this is just an easy way to ensure the profile runs first.
GLOBAL_REAL_VAR(world_init_profiler) = world.Profile(PROFILE_START)
+2 -1
View File
@@ -44,7 +44,8 @@
// Subsystem init_order, from highest priority to lowest priority
// Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise.
#define INIT_ORDER_TITLE 100 // This **MUST** load first or people will se blank lobby screens
#define INIT_ORDER_PROFILER 101
#define INIT_ORDER_TITLE 100 // Load this quickly so people dont see a blank lobby screen
#define INIT_ORDER_GARBAGE 21
#define INIT_ORDER_DBCORE 20
#define INIT_ORDER_BLACKBOX 19
+5
View File
@@ -272,6 +272,9 @@
/// Max amount of CIDs that one ckey can have attached to them before they trip a warning
var/max_client_cid_history = 3
/// Enable auto profiler of rounds
var/auto_profile = FALSE
/datum/configuration/New()
for(var/T in subtypesof(/datum/game_mode))
var/datum/game_mode/M = T
@@ -765,6 +768,8 @@
centcom_ban_db_url = value
if("max_client_cid_history")
max_client_cid_history = text2num(value)
if("enable_auto_profiler")
auto_profile = TRUE
else
log_config("Unknown setting in configuration: '[name]'")
+48
View File
@@ -0,0 +1,48 @@
SUBSYSTEM_DEF(profiler)
name = "Profiler"
init_order = INIT_ORDER_PROFILER
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
wait = 3000
flags = SS_NO_TICK_CHECK
var/fetch_cost = 0
var/write_cost = 0
/datum/controller/subsystem/profiler/stat_entry()
..("F:[round(fetch_cost,1)]ms | W:[round(write_cost,1)]ms")
/datum/controller/subsystem/profiler/Initialize()
if(!config.auto_profile)
StopProfiling() //Stop the early start profiler if we dont want it on in the config
return ..()
/datum/controller/subsystem/profiler/fire()
if(config.auto_profile)
DumpFile()
/datum/controller/subsystem/profiler/Shutdown()
if(config.auto_profile)
DumpFile()
return ..()
// These procs may seem useless, but they exist like this so we can proc call them on and off
// You cant proc-call onto /world
/datum/controller/subsystem/profiler/proc/StartProfiling()
world.Profile(PROFILE_START)
/datum/controller/subsystem/profiler/proc/StopProfiling()
world.Profile(PROFILE_STOP)
// Write the file while also cost tracking
/datum/controller/subsystem/profiler/proc/DumpFile()
var/timer = TICK_USAGE_REAL
var/current_profile_data = world.Profile(PROFILE_REFRESH,format="json")
fetch_cost = MC_AVERAGE(fetch_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
CHECK_TICK
if(!length(current_profile_data)) //Would be nice to have explicit proc to check this
stack_trace("Warning, profiling stopped manually before dump.")
var/json_file = file("[GLOB.log_directory]/profile.json")
if(fexists(json_file))
fdel(json_file)
timer = TICK_USAGE_REAL
WRITE_FILE(json_file, current_profile_data)
write_cost = MC_AVERAGE(write_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
+3
View File
@@ -474,3 +474,6 @@ CENTCOM_BAN_DB_URL https://centcom.melonmesa.com/ban/search/
## Max amount of CIDs that one ckey can have attached to them before they trip a warning. Set to 0 to disable.
MAX_CLIENT_CID_HISTORY 2
## Uncomment to enable automatic performance profiling of rounds
#ENABLE_AUTO_PROFILER
+2
View File
@@ -16,6 +16,7 @@
#include "code\hub.dm"
#include "code\world.dm"
#include "code\__DEFINES\_globals.dm"
#include "code\__DEFINES\_profile.dm"
#include "code\__DEFINES\_protection.dm"
#include "code\__DEFINES\_readme.dm"
#include "code\__DEFINES\_spacemandmm.dm"
@@ -253,6 +254,7 @@
#include "code\controllers\subsystem\overlays.dm"
#include "code\controllers\subsystem\parallax.dm"
#include "code\controllers\subsystem\persistent_data.dm"
#include "code\controllers\subsystem\profiler.dm"
#include "code\controllers\subsystem\radiation.dm"
#include "code\controllers\subsystem\radio.dm"
#include "code\controllers\subsystem\runechat.dm"