From 1f7afa72b68477fd7c1ed25680e1425d00152c99 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 2 Apr 2022 05:20:28 +0200 Subject: [PATCH] fix globalstep profiler to always catch all gs --- gsp/init.lua | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/gsp/init.lua b/gsp/init.lua index 0274661..e53a13b 100644 --- a/gsp/init.lua +++ b/gsp/init.lua @@ -1,26 +1,22 @@ --- This probably needs some hack to be loaded first. --- It seems to be working at least to a degree though. --- unlike abms globalsteps don't have a label attached --- to them so unless we overwrite so the register --- function we will have no idea where we're coming from. - local times={} local total=0 local ngs=0 -local oldgs=minetest.register_globalstep -function minetest.register_globalstep(func) - local n=debug.getinfo(2).short_src - ngs=ngs+1 - oldgs(function(dtime) - local t1=os.clock() - local r=func(dtime) - times[n]=os.clock()-t1 - total=total+times[n] - return r - - end) -end +minetest.register_on_mods_loaded(function() + for i, gs in ipairs(minetest.registered_globalsteps) do + local info = minetest.callback_origins[gs] + local n=info.mod + if n == mesecons + minetest.registered_globalsteps[i]=function(dtime) + local t1=os.clock() + local r=gs(dtime) + local t2=os.clock() + times[n]=os.clock()-t1 + total=total+times[n] + return r + end + end +end) minetest.register_chatcommand("gsp",{privs={debug=true}, description="Give an overview of the registered globalsteps and how long they each take",