mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 21:14:15 +02:00
Legible Lua profiler (#14142)
This commit is contained in:
parent
8e9d7611ae
commit
a22b1700a4
@ -46,11 +46,18 @@ local register_functions = {
|
|||||||
register_on_mapblocks_changed = 0,
|
register_on_mapblocks_changed = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function regex_escape(s)
|
||||||
|
return s:gsub("(%W)", "%%%1")
|
||||||
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Create an unique instrument name.
|
-- Create an unique instrument name.
|
||||||
-- Generate a missing label with a running index number.
|
-- Generate a missing label with a running index number.
|
||||||
--
|
--
|
||||||
local counts = {}
|
local counts = {}
|
||||||
|
local worldmods_path = regex_escape(core.get_worldpath())
|
||||||
|
local user_path = regex_escape(core.get_user_path())
|
||||||
|
local builtin_path = regex_escape(core.get_builtin_path())
|
||||||
local function generate_name(def)
|
local function generate_name(def)
|
||||||
local class, label, func_name = def.class, def.label, def.func_name
|
local class, label, func_name = def.class, def.label, def.func_name
|
||||||
if label then
|
if label then
|
||||||
@ -65,7 +72,16 @@ local function generate_name(def)
|
|||||||
local index_id = def.mod .. (class or func_name)
|
local index_id = def.mod .. (class or func_name)
|
||||||
local index = counts[index_id] or 1
|
local index = counts[index_id] or 1
|
||||||
counts[index_id] = index + 1
|
counts[index_id] = index + 1
|
||||||
return format("%s[%d] %s", class or func_name, index, class and func_name or ""):trim()
|
local info = debug.getinfo(def.func)
|
||||||
|
local modpath = regex_escape(core.get_modpath(def.mod) or "")
|
||||||
|
local source = info.source
|
||||||
|
if modpath ~= "" then
|
||||||
|
source = source:gsub(modpath, def.mod)
|
||||||
|
end
|
||||||
|
source = source:gsub(worldmods_path, "")
|
||||||
|
source = source:gsub(builtin_path, "builtin" .. DIR_DELIM)
|
||||||
|
source = source:gsub(user_path, "")
|
||||||
|
return format("%s[%d] %s#%s", class or func_name, index, source, info.linedefined)
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -77,7 +77,7 @@ local Formatter = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local widths = { 55, 9, 9, 9, 5, 5, 5 }
|
local widths = { 80, 9, 9, 9, 5, 5, 5 }
|
||||||
local txt_row_format = sprintf(" %%-%ds | %%%ds | %%%ds | %%%ds | %%%ds | %%%ds | %%%ds", unpack(widths))
|
local txt_row_format = sprintf(" %%-%ds | %%%ds | %%%ds | %%%ds | %%%ds | %%%ds | %%%ds", unpack(widths))
|
||||||
|
|
||||||
local HR = {}
|
local HR = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user