aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index d6b2dce..ca5eb20 100644
--- a/init.lua
+++ b/init.lua
@@ -5,6 +5,8 @@
advprofiler = {}
+local WINDOW_SIZE = 2048
+
--[[
Unit table:
@@ -33,6 +35,10 @@ local _profs = {}
advprofiler._profilers = _profs
+local function logs(t)
+ minetest.log("action", "[advprofiler] "..t)
+end
+
local function warning(prof, unit, text)
minetest.log("warning", "[advprofiler] ("..prof.name..":"..unit..") "..text
end
@@ -153,6 +159,7 @@ function advprofiler.new_profiler(name)
}
setmetatable(new, prof_mt)
table.insert(_profs, new)
+ logs("Registered profiler "..name)
return new
end
@@ -164,6 +171,19 @@ function advprofiler.step()
end
end
+function advprofiler.end_window_and_report(cyc)
+ local print_table = {
+ "--- Profiling report for cycle "..cyc.." ---"
+ }
+ for _,prof in ipairs(_profs) do
+ prof:end_window(print_table)
+ end
+
+ for _,l in ipairs(print_table) do
+ logs(l)
+ end
+end
+
--[[
Report table:
@@ -180,4 +200,22 @@ function advprofiler.report(rep)
end
+--===========--
+
+local stepcnt = 0
+local cyccnt = 0
+
+minetest.register_globalstep(function(dtime)
+
+ advprofiler.step()
+
+ stepcnt = (stepcnt + 1) % WINDOW_SIZE
+
+ if stepcnt == 0 then
+ cyccnt = cyccnt + 1
+ advprofiler.end_window_and_report(cyccnt)
+ end
+
+end)
+