mcl_devtest/gsp/init.lua

33 lines
983 B
Lua

-- 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_chatcommand("gsp",{privs={debug=true},
description="Give an overview of the registered globalsteps and how long they each take",
func=function(p)
table.sort(times)
minetest.chat_send_player(p,"times:"..dump(times))
minetest.chat_send_player(p,"total globalstep time last interval:"..dump(total))
minetest.chat_send_player(p,"total globalsteps registered:"..dump(ngs))
end})