aboutsummaryrefslogtreecommitdiff
path: root/builtin/profiler
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/profiler')
-rw-r--r--builtin/profiler/init.lua12
-rw-r--r--builtin/profiler/instrumentation.lua18
-rw-r--r--builtin/profiler/reporter.lua6
-rw-r--r--builtin/profiler/sampling.lua2
4 files changed, 23 insertions, 15 deletions
diff --git a/builtin/profiler/init.lua b/builtin/profiler/init.lua
index c1597d280..874950364 100644
--- a/builtin/profiler/init.lua
+++ b/builtin/profiler/init.lua
@@ -15,10 +15,18 @@
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+local function get_bool_default(name, default)
+ local val = core.settings:get_bool(name)
+ if val == nil then
+ return default
+ end
+ return val
+end
+
local profiler_path = core.get_builtin_path()..DIR_DELIM.."profiler"..DIR_DELIM
local profiler = {}
local sampler = assert(loadfile(profiler_path .. "sampling.lua"))(profiler)
-local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler)
+local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler, get_bool_default)
local reporter = dofile(profiler_path .. "reporter.lua")
profiler.instrument = instrumentation.instrument
@@ -27,7 +35,7 @@ profiler.instrument = instrumentation.instrument
-- Is called later, after `core.register_chatcommand` was set up.
--
function profiler.init_chatcommand()
- local instrument_profiler = core.setting_getbool("instrument.profiler") or false
+ local instrument_profiler = get_bool_default("instrument.profiler", false)
if instrument_profiler then
instrumentation.init_chatcommand()
end
diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua
index 4311215b2..be3a460e5 100644
--- a/builtin/profiler/instrumentation.lua
+++ b/builtin/profiler/instrumentation.lua
@@ -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,
@@ -137,7 +138,7 @@ local function instrument_register(func, func_name)
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,8 +154,7 @@ 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 = {
@@ -180,7 +180,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 +193,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 +206,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 {
diff --git a/builtin/profiler/reporter.lua b/builtin/profiler/reporter.lua
index 5b38ed4df..fed47a36b 100644
--- a/builtin/profiler/reporter.lua
+++ b/builtin/profiler/reporter.lua
@@ -18,7 +18,7 @@
local DIR_DELIM, LINE_DELIM = DIR_DELIM, "\n"
local table, unpack, string, pairs, io, os = table, unpack, string, pairs, io, os
local rep, sprintf, tonumber = string.rep, string.format, tonumber
-local core, setting_get = core, core.setting_get
+local core, settings = core, core.settings
local reporter = {}
---
@@ -229,7 +229,7 @@ end
local worldpath = core.get_worldpath()
local function get_save_path(format, filter)
- local report_path = setting_get("profiler.report_path") or ""
+ local report_path = settings:get("profiler.report_path") or ""
if report_path ~= "" then
core.mkdir(sprintf("%s%s%s", worldpath, DIR_DELIM, report_path))
end
@@ -249,7 +249,7 @@ end
--
function reporter.save(profile, format, filter)
if not format or format == "" then
- format = setting_get("profiler.default_report_format") or "txt"
+ format = settings:get("profiler.default_report_format") or "txt"
end
if filter == "" then
filter = nil
diff --git a/builtin/profiler/sampling.lua b/builtin/profiler/sampling.lua
index 1d1ef256d..4b53399a5 100644
--- a/builtin/profiler/sampling.lua
+++ b/builtin/profiler/sampling.lua
@@ -185,7 +185,7 @@ end
function sampler.init()
sampler.reset()
- if core.setting_getbool("instrument.profiler") then
+ if core.settings:get_bool("instrument.profiler") then
core.register_globalstep(function()
if logged_time == 0 then
return