From 275fb6fc41daaf92864b8af5d8aa621530e08319 Mon Sep 17 00:00:00 2001
From: kevinz000 <2003111+kevinz000@users.noreply.github.com>
Date: Tue, 11 Feb 2020 07:54:17 -0700
Subject: [PATCH 1/4] auto profiler
---
code/__DEFINES/profile.dm | 4 +-
code/__DEFINES/subsystems.dm | 1 +
.../configuration/entries/general.dm | 2 +
code/controllers/subsystem/profiler.dm | 50 +++++++++++++++++++
code/game/world.dm | 4 ++
code/modules/admin/verbs/debug.dm | 4 +-
config/config.txt | 11 ++++
tgstation.dme | 1 +
8 files changed, 73 insertions(+), 4 deletions(-)
create mode 100644 code/controllers/subsystem/profiler.dm
diff --git a/code/__DEFINES/profile.dm b/code/__DEFINES/profile.dm
index 28fc7782ce..8929e0f05e 100644
--- a/code/__DEFINES/profile.dm
+++ b/code/__DEFINES/profile.dm
@@ -1,5 +1,5 @@
-#define PROFILE_START ;PROFILE_STORE = list();PROFILE_SET;
-#define PROFILE_STOP ;PROFILE_STORE = null;
+#define LINE_PROFILE_START ;PROFILE_STORE = list();PROFILE_SET;
+#define LINE_PROFILE_STOP ;PROFILE_STORE = null;
#define PROFILE_SET ;PROFILE_TIME = TICK_USAGE_REAL; PROFILE_LINE = __LINE__; PROFILE_FILE = __FILE__; PROFILE_SLEEPCHECK = world.time;
diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm
index 5c54843df2..162c898917 100644
--- a/code/__DEFINES/subsystems.dm
+++ b/code/__DEFINES/subsystems.dm
@@ -47,6 +47,7 @@
// Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise.
+#define INIT_ORDER_PROFILER 101
#define INIT_ORDER_FAIL2TOPIC 22
#define INIT_ORDER_TITLE 20
#define INIT_ORDER_GARBAGE 19
diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm
index 2e5b8a1852..ceb55144d5 100644
--- a/code/controllers/configuration/entries/general.dm
+++ b/code/controllers/configuration/entries/general.dm
@@ -1,3 +1,5 @@
+/datum/config_entry/flag/auto_profile // Automatically start profiler on server start
+
/datum/config_entry/flag/autoadmin // if autoadmin is enabled
protection = CONFIG_ENTRY_LOCKED
diff --git a/code/controllers/subsystem/profiler.dm b/code/controllers/subsystem/profiler.dm
new file mode 100644
index 0000000000..2136f3cace
--- /dev/null
+++ b/code/controllers/subsystem/profiler.dm
@@ -0,0 +1,50 @@
+#define PROFILER_FILENAME "profiler.json"
+
+SUBSYSTEM_DEF(profiler)
+ name = "Profiler"
+ init_order = INIT_ORDER_PROFILER
+ runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
+ wait = 600
+
+/datum/controller/subsystem/profiler/Initialize()
+ if(CONFIG_GET(flag/auto_profile))
+ StartProfiling()
+ else
+ StopProfiling() //Stop the early start from world/New
+ return ..()
+
+/datum/controller/subsystem/profiler/fire()
+ if(CONFIG_GET(flag/auto_profile))
+ DumpFile()
+
+/datum/controller/subsystem/profiler/Shutdown()
+ if(CONFIG_GET(flag/auto_profile))
+ DumpFile()
+ return ..()
+
+/datum/controller/subsystem/profiler/proc/StartProfiling()
+#if DM_BUILD < 1506 || DM_VERSION < 513
+ stack_trace("Auto profiling unsupported on this byond version")
+ CONFIG_SET(flag/auto_profile, FALSE)
+#else
+ world.Profile(PROFILE_START)
+#endif
+
+/datum/controller/subsystem/profiler/proc/StopProfiling()
+#if DM_BUILD >= 1506 && DM_VERSION >= 513
+ world.Profile(PROFILE_STOP)
+#endif
+
+/datum/controller/subsystem/profiler/proc/DumpFile()
+#if DM_BUILD < 1506 || DM_VERSION < 513
+ stack_trace("Auto profiling unsupported on this byond version")
+ CONFIG_SET(flag/auto_profile, FALSE)
+#else
+ var/current_profile_data = world.Profile(PROFILE_REFRESH,format="json")
+ 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]/[PROFILER_FILENAME]")
+ if(fexists(json_file))
+ fdel(json_file)
+ WRITE_FILE(json_file, current_profile_data)
+#endif
diff --git a/code/game/world.dm b/code/game/world.dm
index 6b380e0f94..8d2218deab 100644
--- a/code/game/world.dm
+++ b/code/game/world.dm
@@ -10,6 +10,10 @@ GLOBAL_LIST(topic_status_cache)
/world/New()
enable_debugger()
+#if DM_VERSION >= 513 && DM_BUILD >= 1506
+ world.Profile(PROFILE_START)
+#endif
+
log_world("World loaded at [TIME_STAMP("hh:mm:ss", FALSE)]!")
SetupExternalRSC()
diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm
index ad2eeb7289..cf6d54336e 100644
--- a/code/modules/admin/verbs/debug.dm
+++ b/code/modules/admin/verbs/debug.dm
@@ -1058,7 +1058,7 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention)
set name = "Start Line Profiling"
set desc = "Starts tracking line by line profiling for code lines that support it"
- PROFILE_START
+ LINE_PROFILE_START
message_admins("[key_name_admin(src)] started line by line profiling.")
SSblackbox.record_feedback("tally", "admin_verb", 1, "Start Line Profiling")
@@ -1069,7 +1069,7 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention)
set name = "Stops Line Profiling"
set desc = "Stops tracking line by line profiling for code lines that support it"
- PROFILE_STOP
+ LINE_PROFILE_STOP
message_admins("[key_name_admin(src)] stopped line by line profiling.")
SSblackbox.record_feedback("tally", "admin_verb", 1, "Stop Line Profiling")
diff --git a/config/config.txt b/config/config.txt
index b91e8fce33..32127d4939 100644
--- a/config/config.txt
+++ b/config/config.txt
@@ -500,3 +500,14 @@ FAIL2TOPIC_MAX_FAILS 5
## Firewall rule name used on physical server
FAIL2TOPIC_RULE_NAME _dd_fail2topic
+<<<<<<< ours
+=======
+##Default view size, in tiles. Should *always* be square.
+## The alternative square viewport size if you're using a widescreen view size
+## You probably shouldn't ever be changing this, but it's here if you want to.
+DEFAULT_VIEW_SQUARE 15x15
+
+
+## Enable automatic profiling - Byond 513.1506 and newer only.
+#AUTO_PROFILE
+>>>>>>> theirs
diff --git a/tgstation.dme b/tgstation.dme
index a747c823db..555e4172cb 100755
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -273,6 +273,7 @@
#include "code\controllers\subsystem\pathfinder.dm"
#include "code\controllers\subsystem\persistence.dm"
#include "code\controllers\subsystem\ping.dm"
+#include "code\controllers\subsystem\profiler.dm"
#include "code\controllers\subsystem\radiation.dm"
#include "code\controllers\subsystem\radio.dm"
#include "code\controllers\subsystem\research.dm"
From 3848da5b6bfddb578a618dbfdf0c4981d024bf1d Mon Sep 17 00:00:00 2001
From: kevinz000 <2003111+kevinz000@users.noreply.github.com>
Date: Tue, 11 Feb 2020 07:55:00 -0700
Subject: [PATCH 2/4] mso
---
code/controllers/subsystem/profiler.dm | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/code/controllers/subsystem/profiler.dm b/code/controllers/subsystem/profiler.dm
index 2136f3cace..ec8b243073 100644
--- a/code/controllers/subsystem/profiler.dm
+++ b/code/controllers/subsystem/profiler.dm
@@ -4,7 +4,15 @@ SUBSYSTEM_DEF(profiler)
name = "Profiler"
init_order = INIT_ORDER_PROFILER
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
- wait = 600
+ wait = 3000
+ flags = SS_NO_TICK_CHECK
+ var/fetch_cost = 0
+ var/write_cost = 0
+
+/datum/controller/subsystem/profiler/stat_entry(msg)
+ msg += "F:[round(fetch_cost,1)]ms"
+ msg += "|W:[round(write_cost,1)]ms"
+ ..(msg)
/datum/controller/subsystem/profiler/Initialize()
if(CONFIG_GET(flag/auto_profile))
@@ -40,11 +48,16 @@ SUBSYSTEM_DEF(profiler)
stack_trace("Auto profiling unsupported on this byond version")
CONFIG_SET(flag/auto_profile, FALSE)
#else
+ 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]/[PROFILER_FILENAME]")
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))
#endif
From 1ec098b39ed5e25b478ce89346cc81b788c237b1 Mon Sep 17 00:00:00 2001
From: kevinz000 <2003111+kevinz000@users.noreply.github.com>
Date: Tue, 11 Feb 2020 08:00:56 -0700
Subject: [PATCH 3/4] shhhh
---
config/config.txt | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/config/config.txt b/config/config.txt
index 32127d4939..c114e1ebf1 100644
--- a/config/config.txt
+++ b/config/config.txt
@@ -500,14 +500,5 @@ FAIL2TOPIC_MAX_FAILS 5
## Firewall rule name used on physical server
FAIL2TOPIC_RULE_NAME _dd_fail2topic
-<<<<<<< ours
-=======
-##Default view size, in tiles. Should *always* be square.
-## The alternative square viewport size if you're using a widescreen view size
-## You probably shouldn't ever be changing this, but it's here if you want to.
-DEFAULT_VIEW_SQUARE 15x15
-
-
## Enable automatic profiling - Byond 513.1506 and newer only.
#AUTO_PROFILE
->>>>>>> theirs
From 3d0f3b79a3a0099a95232c1757305bbc77709492 Mon Sep 17 00:00:00 2001
From: kevinz000 <2003111+kevinz000@users.noreply.github.com>
Date: Tue, 11 Feb 2020 08:38:21 -0700
Subject: [PATCH 4/4] renormalize
---
tgstation.dme | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tgstation.dme b/tgstation.dme
index 555e4172cb..e54bee2985 100755
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -273,7 +273,7 @@
#include "code\controllers\subsystem\pathfinder.dm"
#include "code\controllers\subsystem\persistence.dm"
#include "code\controllers\subsystem\ping.dm"
-#include "code\controllers\subsystem\profiler.dm"
+#include "code\controllers\subsystem\profiler.dm"
#include "code\controllers\subsystem\radiation.dm"
#include "code\controllers\subsystem\radio.dm"
#include "code\controllers\subsystem\research.dm"