Skip to content

Commit

Permalink
add /globalstep_table_{show/reset} commands
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Nov 23, 2020
1 parent 20f39b3 commit 5cbae30
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
31 changes: 31 additions & 0 deletions builtin/globalstep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ local metric_time_max = monitoring.gauge(
{ autoflush=true }
)

-- per mod/globalstep time table
-- mod-name[n] => time in microseconds
local time_table = {}

-- modname -> bool
local globalsteps_disabled = {}

Expand All @@ -31,6 +35,12 @@ minetest.register_on_mods_loaded(function()
metric_time.inc(diff)
metric_time_max.setmax(diff)

-- increment globalstep time table entry
local entr_key = "globalstep_" .. i .. "_" .. (info.mod or "<unknown>")
local tt_entry = time_table[entr_key] or 0
tt_entry = tt_entry + diff
time_table[entr_key] = tt_entry

if diff > 75000 then
minetest.log("warning", "[monitoring] globalstep took " .. diff .. " us in mod " .. (info.mod or "<unknown>"))
end
Expand Down Expand Up @@ -98,3 +108,24 @@ minetest.register_chatcommand("globalstep_status", {
return true, list
end
})

-- time table commands

minetest.register_chatcommand("globalstep_table_reset", {
description = "resets the globalstep time table",
func = function()
time_table = {}
return true, "time table reset"
end
})

minetest.register_chatcommand("globalstep_table_show", {
description = "shows the globalstep time table",
func = function()
local str = ""
for modname, micros in pairs(time_table) do
str = str .. "+ " .. modname .. " = " .. micros .. " us\n"
end
return true, str
end
})
8 changes: 8 additions & 0 deletions doc/chatcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ Use with care!
## /globalstep_status

* shows all disabled globalsteps

## /globalstep_table_reset

* Resets the globalstep time tracking table

## /globalstep_table_show

* Shows the globalstep time tracking table

0 comments on commit 5cbae30

Please sign in to comment.