From 8bae9061586d99111819ea2b88ec9bac17ff2f2b Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Fri, 2 Sep 2022 17:31:17 -0700 Subject: [PATCH] Lemon's Profiling Macros (#69631) Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/__DEFINES/stat_tracking.dm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/code/__DEFINES/stat_tracking.dm b/code/__DEFINES/stat_tracking.dm index d7d207469d8..5e3947d83e1 100644 --- a/code/__DEFINES/stat_tracking.dm +++ b/code/__DEFINES/stat_tracking.dm @@ -13,5 +13,34 @@ STAT_ENTRY[STAT_ENTRY_COUNT] += STAT_INCR_AMOUNT;\ };\ +// Cost tracking macros, to be used in one proc +#define INIT_COST(costs, counting) \ + var/list/_costs = costs; \ + var/list/_counting = counting; \ + var/usage = TICK_USAGE; +// Cost tracking macro for global lists, prevents erroring if GLOB has not yet been initialized +#define INIT_COST_GLOBAL(costs, counting) \ + var/static/list/hidden_static_list_for_fun1 = list(); \ + var/static/list/hidden_static_list_for_fun2 = list(); \ + if(GLOB){\ + costs = hidden_static_list_for_fun1; \ + counting = hidden_static_list_for_fun2 ; \ + } \ + INIT_COST(hidden_static_list_for_fun1, hidden_static_list_for_fun2) +#define SET_COST(category) \ + do { \ + var/cost = TICK_USAGE; \ + _costs[category] += TICK_DELTA_TO_MS(cost - usage);\ + _counting[category] += 1;\ + } while(FALSE) \ + usage = TICK_USAGE; + +#define SET_COST_LINE(...) \ + do { \ + var/cost = TICK_USAGE; \ + _costs["[__LINE__ ]"] += TICK_DELTA_TO_MS(cost - usage);\ + _counting["[__LINE__ ]"] += 1;\ + usage = TICK_USAGE; \ + } while(FALSE)