aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-12-05 10:14:07 +0100
committerorwell96 <orwell@bleipb.de>2019-12-05 10:15:36 +0100
commiteeef07d05a7e53de469f19a23fe1e69f569fc924 (patch)
tree6330ae717f337ec1a039004349d9c4c045ab632c /advtrains_luaautomation
parent9c1d3565058799f21b6985c100ccf1abe045d3da (diff)
downloadadvtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.tar.gz
advtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.tar.bz2
advtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.zip
Add profiling instructions for advprofiler
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r--advtrains_luaautomation/active_common.lua3
-rw-r--r--advtrains_luaautomation/depends.txt3
-rw-r--r--advtrains_luaautomation/environment.lua5
-rw-r--r--advtrains_luaautomation/init.lua16
-rw-r--r--advtrains_luaautomation/interrupt.lua4
5 files changed, 28 insertions, 3 deletions
diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua
index c17c6e9..4337122 100644
--- a/advtrains_luaautomation/active_common.lua
+++ b/advtrains_luaautomation/active_common.lua
@@ -114,6 +114,8 @@ function ac.run_in_env(pos, evtdata, customfct_p)
return false
end
+ atlatc.profiler:enter("ac_run_in_env")
+
local customfct=customfct_p or {}
-- add interrupt function
customfct.interrupt=function(t, imesg)
@@ -152,6 +154,7 @@ function ac.run_in_env(pos, evtdata, customfct_p)
if meta then
meta:set_string("formspec", ac.getform(pos, meta))
end
+ atlatc.profiler:leave("ac_run_in_env")
end
function ac.on_digiline_receive(pos, node, channel, msg)
diff --git a/advtrains_luaautomation/depends.txt b/advtrains_luaautomation/depends.txt
index d5523e1..ced5087 100644
--- a/advtrains_luaautomation/depends.txt
+++ b/advtrains_luaautomation/depends.txt
@@ -1,4 +1,5 @@
advtrains
advtrains_interlocking?
advtrains_line_automation?
-mesecons_switch? \ No newline at end of file
+mesecons_switch?
+advprofiler? \ No newline at end of file
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 3e7787b..5276a99 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -265,6 +265,7 @@ local proxy_env={}
-- returns: true, fenv if successful; nil, error if error
function env_proto:execute_code(localenv, code, evtdata, customfct)
+ atlatc.profiler:enter("env_execute_code")
local metatbl ={
__index = function(t, i)
if i=="S" then
@@ -291,6 +292,7 @@ function env_proto:execute_code(localenv, code, evtdata, customfct)
setmetatable(proxy_env, metatbl)
local fun, err=loadstring(code)
if not fun then
+ atlatc.profiler:leave("env_execute_code")
return false, err
end
@@ -299,10 +301,12 @@ function env_proto:execute_code(localenv, code, evtdata, customfct)
if succ then
data=localenv
end
+ atlatc.profiler:leave("env_execute_code")
return succ, data
end
function env_proto:run_initcode()
+ atlatc.profiler:enter("env_run_initcode")
if self.init_code and self.init_code~="" then
local old_fdata=self.fdata
self.fdata = {}
@@ -317,6 +321,7 @@ function env_proto:run_initcode()
end
end
end
+ atlatc.profiler:leave("env_run_initcode")
end
function env_proto:run_stepcode()
if self.step_code and self.step_code~="" then
diff --git a/advtrains_luaautomation/init.lua b/advtrains_luaautomation/init.lua
index 75cf30a..643823b 100644
--- a/advtrains_luaautomation/init.lua
+++ b/advtrains_luaautomation/init.lua
@@ -9,11 +9,23 @@ else
atltrans = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
end
+atlatc = { envs = {}}
+
+-- Profiler boilerplate
+if advprofiler then
+ atlatc.profiler = advprofiler.new_profiler("atlatc")
+else
+ atlatc.profiler = {
+ count=function() end,
+ enter=function() end,
+ leave=function() end,
+ }
+end
+
+
--Privilege
--Only trusted players should be enabled to build stuff which can break the server.
-atlatc = { envs = {}}
-
minetest.register_privilege("atlatc", { description = "Player can place and modify LUA ATC components. Grant with care! Allows to execute bad LUA code.", give_to_singleplayer = false, default= false })
--assertt helper. error if a variable is not of a type
diff --git a/advtrains_luaautomation/interrupt.lua b/advtrains_luaautomation/interrupt.lua
index 525c3b4..3f7aba4 100644
--- a/advtrains_luaautomation/interrupt.lua
+++ b/advtrains_luaautomation/interrupt.lua
@@ -22,6 +22,7 @@ function iq.add(t, pos, evtdata)
end
function iq.mainloop(dtime)
+ atlatc.profiler:enter("iq_mainloop")
timer=timer + math.min(dtime, 0.2)
for i=1,#queue do
local qe=queue[i]
@@ -33,7 +34,9 @@ function iq.mainloop(dtime)
local node=advtrains.ndb.get_node(pos)
local ndef=minetest.registered_nodes[node.name]
if ndef and ndef.luaautomation and ndef.luaautomation.fire_event then
+ atlatc.profiler:enter("iq_run_single_event")
ndef.luaautomation.fire_event(pos, evtdata)
+ atlatc.profiler:leave("iq_run_single_event")
else
atwarn("[atlatc][interrupt] Couldn't run event",evtdata.type,"on",pos,", something wrong with the node",node)
end
@@ -41,6 +44,7 @@ function iq.mainloop(dtime)
i=i-1
end
end
+ atlatc.profiler:leave("iq_mainloop")
end