aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking
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_interlocking
parent9c1d3565058799f21b6985c100ccf1abe045d3da (diff)
downloadadvtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.tar.gz
advtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.tar.bz2
advtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.zip
Add profiling instructions for advprofiler
Diffstat (limited to 'advtrains_interlocking')
-rw-r--r--advtrains_interlocking/depends.txt3
-rw-r--r--advtrains_interlocking/init.lua10
-rw-r--r--advtrains_interlocking/routesetting.lua7
-rw-r--r--advtrains_interlocking/train_sections.lua4
4 files changed, 23 insertions, 1 deletions
diff --git a/advtrains_interlocking/depends.txt b/advtrains_interlocking/depends.txt
index 6f00bf6..960989c 100644
--- a/advtrains_interlocking/depends.txt
+++ b/advtrains_interlocking/depends.txt
@@ -1 +1,2 @@
-advtrains \ No newline at end of file
+advtrains
+advprofiler? \ No newline at end of file
diff --git a/advtrains_interlocking/init.lua b/advtrains_interlocking/init.lua
index a2f5882..0cdea8e 100644
--- a/advtrains_interlocking/init.lua
+++ b/advtrains_interlocking/init.lua
@@ -9,6 +9,16 @@ function advtrains.interlocking.sigd_equal(sigd, cmp)
return vector.equals(sigd.p, cmp.p) and sigd.s==cmp.s
end
+-- Profiler boilerplate
+if advprofiler then
+ advtrains.interlocking.profiler = advprofiler.new_profiler("advtrains_interlocking")
+else
+ advtrains.interlocking.profiler = {
+ count=function() end,
+ enter=function() end,
+ leave=function() end,
+ }
+end
local modpath = minetest.get_modpath(minetest.get_current_modname()) .. DIR_DELIM
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index 7c4d14c..7b52902 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -224,6 +224,7 @@ end
-- note that this does not clear the routesetting status from the entry signal,
-- only from the ts's
function ilrs.cancel_route_from(sigd)
+ advtrains.interlocking.profiler:enter("cancel_route_from")
-- we start at the tc designated by signal
local c_sigd = sigd
local c_tcbs, c_ts_id, c_ts, c_rseg, c_lckp
@@ -232,6 +233,7 @@ function ilrs.cancel_route_from(sigd)
c_tcbs = ildb.get_tcbs(c_sigd)
if not c_tcbs then
atwarn("Failed to cancel route, no TCBS at",c_sigd)
+ advtrains.interlocking.profiler:leave("cancel_route_from")
return false
end
@@ -248,6 +250,7 @@ function ilrs.cancel_route_from(sigd)
c_ts_id = c_tcbs.ts_id
if not c_tcbs then
atwarn("Failed to cancel route, end of interlocking at",c_sigd)
+ advtrains.interlocking.profiler:leave("cancel_route_from")
return false
end
c_ts = ildb.get_ts(c_ts_id)
@@ -256,6 +259,7 @@ function ilrs.cancel_route_from(sigd)
or not c_ts.route
or not sigd_equal(c_ts.route.entry, c_sigd) then
--atdebug("cancel_route_from: abort (eoi/no route):")
+ advtrains.interlocking.profiler:leave("cancel_route_from")
return false
end
@@ -271,6 +275,7 @@ function ilrs.cancel_route_from(sigd)
minetest.after(0, advtrains.interlocking.route.update_waiting, "ts", c_ts_id)
end
--atdebug("cancel_route_from: done (no final sigd)")
+ advtrains.interlocking.profiler:leave("cancel_route_from")
return true
end
@@ -303,7 +308,9 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
end
if newrte then tcbs.routeset = newrte end
--atdebug("Setting:",tcbs.routeset)
+ advtrains.interlocking.profiler:enter("set_route")
local succ, rsn, cbts, cblk = ilrs.set_route(sigd, tcbs.routes[tcbs.routeset])
+ advtrains.interlocking.profiler:leave("set_route")
if not succ then
tcbs.route_rsn = rsn
--atdebug("Routesetting failed:",rsn)
diff --git a/advtrains_interlocking/train_sections.lua b/advtrains_interlocking/train_sections.lua
index 757f36a..5e5945a 100644
--- a/advtrains_interlocking/train_sections.lua
+++ b/advtrains_interlocking/train_sections.lua
@@ -62,6 +62,7 @@ local function itkremove(tbl, ikey, com)
end
local function setsection(tid, train, ts_id, ts, sigd)
+ advtrains.interlocking.profiler:enter("train_setsection")
-- train
if not train.il_sections then train.il_sections = {} end
if not itkexist(train.il_sections, "ts_id", ts_id) then
@@ -106,9 +107,11 @@ local function setsection(tid, train, ts_id, ts, sigd)
if tcbs.signal then
advtrains.interlocking.route.update_route(sigd, tcbs)
end
+ advtrains.interlocking.profiler:leave("train_setsection")
end
local function freesection(tid, train, ts_id, ts)
+ advtrains.interlocking.profiler:enter("train_freesection")
-- train
if not train.il_sections then train.il_sections = {} end
itkremove(train.il_sections, "ts_id", ts_id)
@@ -129,6 +132,7 @@ local function freesection(tid, train, ts_id, ts)
-- This must be delayed, because this code is executed in-between a train step
-- TODO use luaautomation timers?
minetest.after(0, advtrains.interlocking.route.update_waiting, "ts", ts_id)
+ advtrains.interlocking.profiler:leave("train_freesection")
end