]> git.lizzy.rs Git - minetest.git/blobdiff - builtin/profiler/instrumentation.lua
Translated using Weblate (Lojban)
[minetest.git] / builtin / profiler / instrumentation.lua
index 4311215b299e7fa4c07be141ee7799ff20611e80..6b951a2c2d57647b3068e531b27213a128566bfb 100644 (file)
@@ -17,8 +17,9 @@
 
 local format, pairs, type = string.format, pairs, type
 local core, get_current_modname = core, core.get_current_modname
-local profiler, sampler = ...
-local instrument_builtin = core.setting_getbool("instrument.builtin") or false
+local profiler, sampler, get_bool_default = ...
+
+local instrument_builtin = get_bool_default("instrument.builtin", false)
 
 local register_functions = {
        register_globalstep = 0,
@@ -87,7 +88,7 @@ local function instrument(def)
        if not def or not def.func then
                return
        end
-       def.mod = def.mod or get_current_modname()
+       def.mod = def.mod or get_current_modname() or "??"
        local modname = def.mod
        local instrument_name = generate_name(def)
        local func = def.func
@@ -116,7 +117,8 @@ end
 local function assert_can_be_called(func, func_name, level)
        if not can_be_called(func) then
                -- Then throw an *helpful* error, by pointing on our caller instead of us.
-               error(format("Invalid argument to %s. Expected function-like type instead of '%s'.", func_name, type(func)), level + 1)
+               error(format("Invalid argument to %s. Expected function-like type instead of '%s'.",
+                               func_name, type(func)), level + 1)
        end
 end
 
@@ -132,12 +134,12 @@ local function instrument_register(func, func_name)
                return func(instrument {
                        func = callback,
                        func_name = register_name
-               }), ...
+               }, ...)
        end
 end
 
 local function init_chatcommand()
-       if core.setting_getbool("instrument.chatcommand") or true then
+       if get_bool_default("instrument.chatcommand", true) then
                local orig_register_chatcommand = core.register_chatcommand
                core.register_chatcommand = function(cmd, def)
                        def.func = instrument {
@@ -153,15 +155,15 @@ end
 -- Start instrumenting selected functions
 --
 local function init()
-       local is_set = core.setting_getbool
-       if is_set("instrument.entity") or true then
+       if get_bool_default("instrument.entity", true) then
                -- Explicitly declare entity api-methods.
                -- Simple iteration would ignore lookup via __index.
                local entity_instrumentation = {
                        "on_activate",
+                       "on_deactivate",
                        "on_step",
                        "on_punch",
-                       "rightclick",
+                       "on_rightclick",
                        "get_staticdata",
                }
                -- Wrap register_entity() to instrument them on registration.
@@ -180,7 +182,7 @@ local function init()
                end
        end
 
-       if is_set("instrument.abm") or true then
+       if get_bool_default("instrument.abm", true) then
                -- Wrap register_abm() to automatically instrument abms.
                local orig_register_abm = core.register_abm
                core.register_abm = function(spec)
@@ -193,7 +195,7 @@ local function init()
                end
        end
 
-       if is_set("instrument.lbm") or true then
+       if get_bool_default("instrument.lbm", true) then
                -- Wrap register_lbm() to automatically instrument lbms.
                local orig_register_lbm = core.register_lbm
                core.register_lbm = function(spec)
@@ -206,13 +208,13 @@ local function init()
                end
        end
 
-       if is_set("instrument.global_callback") or true then
+       if get_bool_default("instrument.global_callback", true) then
                for func_name, _ in pairs(register_functions) do
                        core[func_name] = instrument_register(core[func_name], func_name)
                end
        end
 
-       if is_set("instrument.profiler") or false then
+       if get_bool_default("instrument.profiler", false) then
                -- Measure overhead of instrumentation, but keep it down for functions
                -- So keep the `return` for better optimization.
                profiler.empty_instrument = instrument {