From 5cbae30f77f45b54839777d0199db637f7a53a8b Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 23 Nov 2020 18:06:24 +0100 Subject: [PATCH] add /globalstep_table_{show/reset} commands --- builtin/globalstep.lua | 31 +++++++++++++++++++++++++++++++ doc/chatcommands.md | 8 ++++++++ 2 files changed, 39 insertions(+) diff --git a/builtin/globalstep.lua b/builtin/globalstep.lua index 56f03ac..918b859 100644 --- a/builtin/globalstep.lua +++ b/builtin/globalstep.lua @@ -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 = {} @@ -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 "") + 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 "")) end @@ -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 +}) diff --git a/doc/chatcommands.md b/doc/chatcommands.md index 834a922..1ca67b6 100644 --- a/doc/chatcommands.md +++ b/doc/chatcommands.md @@ -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