aboutsummaryrefslogtreecommitdiff
path: root/advtrains_line_automation
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_line_automation
parent9c1d3565058799f21b6985c100ccf1abe045d3da (diff)
downloadadvtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.tar.gz
advtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.tar.bz2
advtrains-eeef07d05a7e53de469f19a23fe1e69f569fc924.zip
Add profiling instructions for advprofiler
Diffstat (limited to 'advtrains_line_automation')
-rw-r--r--advtrains_line_automation/depends.txt3
-rw-r--r--advtrains_line_automation/init.lua10
-rw-r--r--advtrains_line_automation/scheduler.lua7
3 files changed, 19 insertions, 1 deletions
diff --git a/advtrains_line_automation/depends.txt b/advtrains_line_automation/depends.txt
index 53500ee..0f69091 100644
--- a/advtrains_line_automation/depends.txt
+++ b/advtrains_line_automation/depends.txt
@@ -1,2 +1,3 @@
advtrains_interlocking
-advtrains_train_track \ No newline at end of file
+advtrains_train_track
+advprofiler? \ No newline at end of file
diff --git a/advtrains_line_automation/init.lua b/advtrains_line_automation/init.lua
index 7b758bc..2275f49 100644
--- a/advtrains_line_automation/init.lua
+++ b/advtrains_line_automation/init.lua
@@ -15,6 +15,16 @@ advtrains.lines = {
stops = {},
}
+if advprofiler then
+ advtrains.lines.profiler = advprofiler.new_profiler("advtrains_lines")
+else
+ advtrains.lines.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_line_automation/scheduler.lua b/advtrains_line_automation/scheduler.lua
index 8afaa55..27cb528 100644
--- a/advtrains_line_automation/scheduler.lua
+++ b/advtrains_line_automation/scheduler.lua
@@ -48,6 +48,7 @@ function sched.save()
end
function sched.run()
+ advtrains.lines.profiler:enter("scheduler_run")
local ctime = ln.rwt.get_time()
local cnt = 0
local ucn, elem
@@ -57,7 +58,9 @@ function sched.run()
table.remove(queue, 1)
if callbacks[elem.e] then
-- run it
+ advtrains.lines.profiler:enter("scheduler_run_single_schedule")
callbacks[elem.e](elem.d)
+ advtrains.lines.profiler:leave("scheduler_run_single_schedule")
else
atwarn("[lines][scheduler] No callback to handle schedule",elem)
end
@@ -70,6 +73,7 @@ function sched.run()
break
end
end
+ advtrains.lines.profiler:leave("scheduler_run")
end
-- Enqueue a new scheduled item to be executed at "rwtime"
@@ -79,6 +83,7 @@ end
-- used to prevent expotentially growing "scheduler bombs"
-- unitlim: Custom override for UNITS_THRESH (see there)
function sched.enqueue(rwtime, handler, evtdata, unitid, unitlim)
+ advtrains.lines.profiler:enter("scheduler_enqueue")
local qtime = ln.rwt.to_secs(rwtime)
assert(type(handler)=="string")
assert(type(unitid)=="string")
@@ -91,6 +96,7 @@ function sched.enqueue(rwtime, handler, evtdata, unitid, unitlim)
local ulim=(unitlim or UNITS_THRESH)
if ucn >= ulim then
atlog("[lines][scheduler] discarding enqueue for",handler,"(limit",ulim,") because unit",unitid,"has already",ucn,"schedules enqueued")
+ advtrains.lines.profiler:leave("scheduler_enqueue")
return false
end
@@ -104,6 +110,7 @@ function sched.enqueue(rwtime, handler, evtdata, unitid, unitlim)
u=unitid,
})
units_cnt[unitid] = ucn + 1
+ advtrains.lines.profiler:leave("scheduler_enqueue")
return true
end
cnt = cnt+1