aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-12-05 08:21:25 +0100
committerorwell96 <orwell@bleipb.de>2019-12-05 08:21:25 +0100
commit9ea4002b6bfa8b26be9a3a31978c05e865177a97 (patch)
tree5f179c80ea7b0dbedb5cf959b0a9bcf61b8f7e55
parentfbbed0899327a1d70676775c2bdeb42b9f06e980 (diff)
downloadadvprofiler-9ea4002b6bfa8b26be9a3a31978c05e865177a97.zip
advprofiler-9ea4002b6bfa8b26be9a3a31978c05e865177a97.tar.gz
advprofiler-9ea4002b6bfa8b26be9a3a31978c05e865177a97.tar.bz2
Make implementation complete
-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)
+