Skip to content

Instantly share code, notes, and snippets.

@Niklp09
Created March 19, 2023 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Niklp09/0bcf6851b7cb9a957711adc2ffb2993e to your computer and use it in GitHub Desktop.
Save Niklp09/0bcf6851b7cb9a957711adc2ffb2993e to your computer and use it in GitHub Desktop.
-- Based on https://gitea.your-land.de/your-land/bugtracker/issues/3723 (Thanks to Alias/Bastrabun)
-- detect slow find_nodes_in_area calls
local old_find_nodes_in_area = core.find_nodes_in_area
local most_called = {}
core.find_nodes_in_area = function(pos1, pos2, nodenames, grouped)
local from = debug.getinfo(2, "nS")
local t0 = core.get_us_time()
local ret, ret2 = old_find_nodes_in_area(pos1, pos2, nodenames, grouped)
local t1 = core.get_us_time()
local spos = core.pos_to_string(vector.round(pos1)) or ""
local source = from.source or "unknown"
local line = from.linedefined or "unknown"
local time = (t1-t0)/1000
local s = source .. "@" .. line
most_called[s] = (most_called[s] or 0) + 1
local logme = table.concat({"[DEBUG] FNIA time=",time,"ms at ",spos," from=",source,"@",line})
core.log("action",logme)
return ret, ret2
end
minetest.register_chatcommand("fnia", {
privs = {interact = true},
func = function(name)
print(dump(most_called))
end
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment