From 6bd1352a4c2868a2392f14cb0f1b9aea4d96e8c4 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Tue, 1 Nov 2022 19:39:31 +0100 Subject: [PATCH] [MIRROR] Add defines for byond-tracy support [MDB IGNORE] (#17301) * Add defines for byond-tracy support (#70931) Adds `USE_BYOND_TRACY`, which automatically loads a given prof.dll/libprof.so using https://github.com/mafemergency/byond-tracy/. Not intended for use in production, and we do not ship a copy of byond-tracy. It is extremely easy to compile yourself, but if you're someone interesting enough to play around with this then let me know and I can just give you a build. I'm going to be using this for init profiling. * Add defines for byond-tracy support Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- .gitignore | 4 ++++ code/_compile_options.dm | 8 +++++++- code/game/world.dm | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43b1cc1e4d3..cc053a633ae 100644 --- a/.gitignore +++ b/.gitignore @@ -219,6 +219,10 @@ aux*.dll libaux*.so aux*.pdb +# byond-tracy, we intentionally do not ship this and do not want to maintain it +prof.dll +libprof.so + # JavaScript tools **/node_modules diff --git a/code/_compile_options.dm b/code/_compile_options.dm index bec5e18d856..95293ef5c05 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -49,9 +49,15 @@ #define GC_FAILURE_HARD_LOOKUP #endif // REFERENCE_DOING_IT_LIVE +// If this is uncommented, we do a single run though of the game setup and tear down process with unit tests in between +// #define UNIT_TESTS + +// If this is uncommented, will attempt to load and initialize prof.dll/libprof.so. +// We do not ship byond-tracy. Build it yourself here: https://github.com/mafemergency/byond-tracy/ +// #define USE_BYOND_TRACY + // If defined, we will NOT defer asset generation till later in the game, and will instead do it all at once, during initiialize //#define DO_NOT_DEFER_ASSETS -//#define UNIT_TESTS //If this is uncommented, we do a single run though of the game setup and tear down process with unit tests in between /// If this is uncommented, Autowiki will generate edits and shut down the server. /// Prefer the autowiki build target instead. diff --git a/code/game/world.dm b/code/game/world.dm index 8db9af7ee89..0a4470c5d32 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -34,6 +34,10 @@ GLOBAL_VAR(restart_counter) * All atoms in both compiled and uncompiled maps are initialized() */ /world/New() +#ifdef USE_BYOND_TRACY + #warn USE_BYOND_TRACY is enabled + init_byond_tracy() +#endif log_world("World loaded at [time_stamp()]!") @@ -395,6 +399,22 @@ GLOBAL_VAR(restart_counter) /world/proc/on_tickrate_change() SStimer?.reset_buckets() +/world/proc/init_byond_tracy() + var/library + + switch (system_type) + if (MS_WINDOWS) + library = "prof.dll" + if (UNIX) + library = "libprof.so" + else + CRASH("Unsupported platform: [system_type]") + + var/init_result = call(library, "init")() + if (init_result != "0") + CRASH("Error initializing byond-tracy: [init_result]") + + /world/Profile(command, type, format) if((command & PROFILE_STOP) || !global.config?.loaded || !CONFIG_GET(flag/forbid_all_profiling)) . = ..()