From ff77fe86f347b1a3f7ce5db573574ee6937afea1 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 26 Dec 2020 23:40:01 +0100 Subject: [PATCH] [MIRROR] Simple proc profiler that just times stuff in TESTING (#2333) * Added simple profiler (#55613) * Simple proc profiler that just times stuff in TESTING Co-authored-by: WarlockD --- code/__HELPERS/_logging.dm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/code/__HELPERS/_logging.dm b/code/__HELPERS/_logging.dm index 0d872e46678..18a12c1c6ce 100644 --- a/code/__HELPERS/_logging.dm +++ b/code/__HELPERS/_logging.dm @@ -25,10 +25,32 @@ //print a testing-mode debug message to world.log and world #ifdef TESTING #define testing(msg) log_world("## TESTING: [msg]"); to_chat(world, "## TESTING: [msg]") + +GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global")) +// we don't really check if a word or name is used twice, be aware of that +#define testing_profile_start(NAME, LIST) LIST[NAME] = world.timeofday +#define testing_profile_current(NAME, LIST) round((world.timeofday - LIST[NAME])/10,0.1) +#define testing_profile_output(NAME, LIST) testing("[LIST["_PROFILE_NAME"]] profile of [NAME] is [testing_profile_current(NAME,LIST)]s") +#define testing_profile_output_all(LIST) { for(var/_NAME in LIST) { testing_profile_current(,_NAME,LIST); }; }; #else #define testing(msg) +#define testing_profile_start(NAME, LIST) +#define testing_profile_current(NAME, LIST) +#define testing_profile_output(NAME, LIST) +#define testing_profile_output_all(LIST) #endif +#define testing_profile_global_start(NAME) testing_profile_start(NAME,GLOB.testing_global_profiler) +#define testing_profile_global_current(NAME) testing_profile_current(NAME, GLOB.testing_global_profiler) +#define testing_profile_global_output(NAME) testing_profile_output(NAME, GLOB.testing_global_profiler) +#define testing_profile_global_output_all testing_profile_output_all(GLOB.testing_global_profiler) + +#define testing_profile_local_init(PROFILE_NAME) var/list/_timer_system = list( "_PROFILE_NAME" = PROFILE_NAME, "_start_of_proc" = world.timeofday ) +#define testing_profile_local_start(NAME) testing_profile_start(NAME, _timer_system) +#define testing_profile_local_current(NAME) testing_profile_current(NAME, _timer_system) +#define testing_profile_local_output(NAME) testing_profile_output(NAME, _timer_system) +#define testing_profile_local_output_all testing_profile_output_all(_timer_system) + #if defined(UNIT_TESTS) || defined(SPACEMAN_DMM) /proc/log_test(text) WRITE_LOG(GLOB.test_log, text)