fix globalstep profiler to always catch all gs

This commit is contained in:
cora 2022-04-02 05:20:28 +02:00
parent 8fed69703f
commit 1f7afa72b6
1 changed files with 15 additions and 19 deletions

View File

@ -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 times={}
local total=0 local total=0
local ngs=0 local ngs=0
local oldgs=minetest.register_globalstep minetest.register_on_mods_loaded(function()
function minetest.register_globalstep(func) for i, gs in ipairs(minetest.registered_globalsteps) do
local n=debug.getinfo(2).short_src local info = minetest.callback_origins[gs]
ngs=ngs+1 local n=info.mod
oldgs(function(dtime) if n == mesecons
local t1=os.clock() minetest.registered_globalsteps[i]=function(dtime)
local r=func(dtime) local t1=os.clock()
times[n]=os.clock()-t1 local r=gs(dtime)
total=total+times[n] local t2=os.clock()
return r times[n]=os.clock()-t1
total=total+times[n]
end) return r
end end
end
end)
minetest.register_chatcommand("gsp",{privs={debug=true}, minetest.register_chatcommand("gsp",{privs={debug=true},
description="Give an overview of the registered globalsteps and how long they each take", description="Give an overview of the registered globalsteps and how long they each take",