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 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",