From 9ea4002b6bfa8b26be9a3a31978c05e865177a97 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 5 Dec 2019 08:21:25 +0100 Subject: Make implementation complete --- init.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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) + -- cgit v1.2.3