record max times for abm and gs
This commit is contained in:
parent
44befb2ead
commit
d8f052b19f
|
@ -1,16 +1,19 @@
|
|||
local count={}
|
||||
local times={}
|
||||
local max_times={}
|
||||
local total=0
|
||||
local nabm=0
|
||||
minetest.register_on_mods_loaded(function()
|
||||
|
||||
|
||||
for k,v in pairs(minetest.registered_abms) do
|
||||
local n=v.label
|
||||
local olda=v.action
|
||||
max_times[n] = 0
|
||||
minetest.registered_abms[k].action=function(pos, node, aoc, aocw)
|
||||
local t1=os.clock()
|
||||
local r=olda(pos, node, aoc, aocw)
|
||||
times[n]=os.clock()-t1
|
||||
if times[n] > max_times[n] then max_times[n] = times[n] end
|
||||
if not count[n] then count[n] = 0 end
|
||||
count[n]=count[n]+1
|
||||
total=total+times[n]
|
||||
|
@ -26,7 +29,8 @@ minetest.register_chatcommand("abmp",{privs={debug=true},
|
|||
table.sort(count)
|
||||
table.sort(times)
|
||||
minetest.chat_send_player(p,"counts:"..dump(count))
|
||||
minetest.chat_send_player(p,"times:"..dump(times))
|
||||
minetest.chat_send_player(p,"=== times:"..dump(times))
|
||||
minetest.chat_send_player(p,"=== max times:"..dump(max_times))
|
||||
minetest.chat_send_player(p,"total abm time last interval:"..dump(total))
|
||||
minetest.chat_send_player(p,"total abms registered:"..dump(#times))
|
||||
end})
|
||||
|
|
40
gsp/init.lua
40
gsp/init.lua
|
@ -1,27 +1,63 @@
|
|||
local times={}
|
||||
local max_times = {}
|
||||
local total=0
|
||||
local ngs=0
|
||||
local function roundN(n, d)
|
||||
if type(n) ~= "number" then return n end
|
||||
local m = 10^d
|
||||
return math.floor(n * m + 0.5) / m
|
||||
end
|
||||
|
||||
local function get_out(inp)
|
||||
local out = {}
|
||||
for k,v in pairs(inp) do
|
||||
out[k] = v
|
||||
end
|
||||
return out
|
||||
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
|
||||
max_times[n] = 0
|
||||
minetest.registered_globalsteps[i]=function(dtime)
|
||||
local t1=os.clock()
|
||||
local r=gs(dtime)
|
||||
local t2=os.clock()
|
||||
times[n]=os.clock()-t1
|
||||
times[n]=roundN(os.clock()-t1,12)
|
||||
if times[n] > max_times[n] then max_times[n] = times[n] end
|
||||
total=total+times[n]
|
||||
return r
|
||||
end
|
||||
end
|
||||
minetest.register_globalstep(function(dtime)
|
||||
--minetest.log(tostring(dtime))
|
||||
minetest.after(0, function()
|
||||
if dtime > 0.5 then
|
||||
local d = get_out(times)
|
||||
local m = get_out(max_times)
|
||||
table.sort(d,function(a,b)
|
||||
return a > b
|
||||
end)
|
||||
table.sort(m,function(a,b)
|
||||
return a > b
|
||||
end)
|
||||
--minetest.log("LONGSTEP: "..dtime)
|
||||
--minetest.log("times:"..dump(d))
|
||||
--minetest.log("LONGSTEP")
|
||||
end
|
||||
end)
|
||||
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,"=== times: \n"..dump(times))
|
||||
minetest.chat_send_player(p,"=== maxtimes: \n"..dump(max_times))
|
||||
minetest.chat_send_player(p,"total globalstep time last interval:"..dump(total))
|
||||
minetest.chat_send_player(p,"total globalsteps registered:"..dump(ngs))
|
||||
end})
|
||||
|
|
Loading…
Reference in New Issue