From eeef07d05a7e53de469f19a23fe1e69f569fc924 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 5 Dec 2019 10:14:07 +0100 Subject: Add profiling instructions for advprofiler --- advtrains_line_automation/depends.txt | 3 ++- advtrains_line_automation/init.lua | 10 ++++++++++ advtrains_line_automation/scheduler.lua | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'advtrains_line_automation') 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 -- cgit v1.2.3