Add tracy annotations

This commit is contained in:
Y. Wang 2024-09-15 15:45:41 +02:00
parent 9ada994d5b
commit b5d2c23b32
No known key found for this signature in database
GPG Key ID: 39EC2419DF97489A
6 changed files with 47 additions and 4 deletions

View File

@ -456,6 +456,7 @@ advtrains.save_component = function (tbl, name)
end end
advtrains.avt_save = function(remove_players_from_wagons) advtrains.avt_save = function(remove_players_from_wagons)
tracy.ZoneBeginN("advtrains.avt_save")
--atdebug("Saving advtrains files (version 4)") --atdebug("Saving advtrains files (version 4)")
if remove_players_from_wagons then if remove_players_from_wagons then
@ -551,6 +552,7 @@ advtrains.avt_save = function(remove_players_from_wagons)
if DUMP_DEBUG_SAVE then if DUMP_DEBUG_SAVE then
local file, err = io.open(advtrains.fpath.."_DUMP", "w") local file, err = io.open(advtrains.fpath.."_DUMP", "w")
if err then if err then
tracy.ZoneEnd()
return return
end end
file:write(dump(parts_table)) file:write(dump(parts_table))
@ -566,6 +568,7 @@ advtrains.avt_save = function(remove_players_from_wagons)
-- store version -- store version
advtrains.save_component(4, "version") advtrains.save_component(4, "version")
end end
tracy.ZoneEnd()
end end
--## MAIN LOOP ##-- --## MAIN LOOP ##--
@ -582,6 +585,7 @@ minetest.register_globalstep(function(dtime_mt)
-- the advtrains globalstep is skipped by command. Return immediately -- the advtrains globalstep is skipped by command. Return immediately
return return
end end
tracy.ZoneBeginN("advtrains.globalstep")
within_mainstep = true within_mainstep = true
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1 advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
@ -638,7 +642,7 @@ minetest.register_globalstep(function(dtime_mt)
end end
within_mainstep = false within_mainstep = false
tracy.ZoneEnd()
end) end)
--if something goes wrong in these functions, there is no help. no pcall here. --if something goes wrong in these functions, there is no help. no pcall here.
@ -647,6 +651,7 @@ end)
-- Causes the loading of everything -- Causes the loading of everything
-- first time called in main loop (after the init phase) because luaautomation has to initialize first. -- first time called in main loop (after the init phase) because luaautomation has to initialize first.
function advtrains.load() function advtrains.load()
tracy.ZoneBeginN("advtrains.load")
advtrains.avt_load() --loading advtrains. includes ndb at advtrains.ndb.load_data() advtrains.avt_load() --loading advtrains. includes ndb at advtrains.ndb.load_data()
--if atlatc then --if atlatc then
-- atlatc.load() --includes interrupts -- atlatc.load() --includes interrupts
@ -657,6 +662,7 @@ function advtrains.load()
init_load=true init_load=true
no_action=false no_action=false
atlog("[load_all]Loaded advtrains save files") atlog("[load_all]Loaded advtrains save files")
tracy.ZoneEnd()
end end
--## MAIN SAVE ROUTINE ## --## MAIN SAVE ROUTINE ##

View File

@ -81,6 +81,7 @@ local function look_ahead(id, train)
-- in order to not trigger approach callbacks on the wrong path -- in order to not trigger approach callbacks on the wrong path
return return
end end
tracy.ZoneBeginN("advtrains.lzb_look_ahead")
local acc = advtrains.get_acceleration(train, 1) local acc = advtrains.get_acceleration(train, 1)
-- worst-case: the starting point is maximum speed -- worst-case: the starting point is maximum speed
@ -122,6 +123,7 @@ local function look_ahead(id, train)
lzb.trav_index = trav lzb.trav_index = trav
tracy.ZoneEnd()
end end
advtrains.lzb_look_ahead = look_ahead advtrains.lzb_look_ahead = look_ahead

View File

@ -201,6 +201,7 @@ function advtrains.path_get(train, index)
if index ~= atfloor(index) then if index ~= atfloor(index) then
error("For train "..train.id..": Called path_get() but index="..index.." is not a round number") error("For train "..train.id..": Called path_get() but index="..index.." is not a round number")
end end
tracy.ZoneBeginN("advtrains.path_get")
local pef = train.path_ext_f local pef = train.path_ext_f
-- generate forward (front of train, positive) -- generate forward (front of train, positive)
@ -286,8 +287,8 @@ function advtrains.path_get(train, index)
train.path_req_f = index train.path_req_f = index
end end
tracy.ZoneEnd()
return train.path[index], (index<=train.path_trk_f and index>=train.path_trk_b) return train.path[index], (index<=train.path_trk_f and index>=train.path_trk_b)
end end
-- interpolated position to fractional index given, and angle based on path_dir -- interpolated position to fractional index given, and angle based on path_dir

View File

@ -67,6 +67,7 @@ local LZB_ZERO_APPROACH_SPEED = 0.2
tp_player_tmr = 0 tp_player_tmr = 0
advtrains.mainloop_trainlogic=function(dtime, stepno) advtrains.mainloop_trainlogic=function(dtime, stepno)
tracy.ZoneBeginN("advtrains.mainloop_trainlogic")
--build a table of all players indexed by pts. used by damage and door system. --build a table of all players indexed by pts. used by damage and door system.
advtrains.playersbypts={} advtrains.playersbypts={}
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
@ -120,6 +121,7 @@ advtrains.mainloop_trainlogic=function(dtime, stepno)
atprintbm("trainsteps", t) atprintbm("trainsteps", t)
endstep() endstep()
tracy.ZoneEnd()
end end
function advtrains.tp_player_to_train(player) function advtrains.tp_player_to_train(player)
@ -241,9 +243,11 @@ local function mkcallback(name)
table.insert(callt, func) table.insert(callt, func)
end end
return callt, function(id, train, param1, param2, param3) return callt, function(id, train, param1, param2, param3)
tracy.ZoneBegin("advtrains.run_callbacks_" .. name)
for _,f in ipairs(callt) do for _,f in ipairs(callt) do
f(id, train, param1, param2, param3) f(id, train, param1, param2, param3)
end end
tracy.ZoneEnd()
end end
end end
@ -282,7 +286,8 @@ function advtrains.train_ensure_init(id, train)
assertdef(train, "acceleration", 0) assertdef(train, "acceleration", 0)
assertdef(train, "id", id) assertdef(train, "id", id)
tracy.ZoneBeginN("advtrains.train_ensure_init")
if not train.drives_on or not train.max_speed then if not train.drives_on or not train.max_speed then
--atprint("in ensure_init: missing properties, updating!") --atprint("in ensure_init: missing properties, updating!")
advtrains.update_trainpart_properties(id) advtrains.update_trainpart_properties(id)
@ -294,6 +299,7 @@ function advtrains.train_ensure_init(id, train)
if not train.last_pos then if not train.last_pos then
atlog("Train",id,": Restoring path failed, no last_pos set! Train will be disabled. You can try to fix the issue in the save file.") atlog("Train",id,": Restoring path failed, no last_pos set! Train will be disabled. You can try to fix the issue in the save file.")
train.no_step = true train.no_step = true
tracy.ZoneEnd()
return nil return nil
end end
if not train.last_connid then if not train.last_connid then
@ -318,12 +324,14 @@ function advtrains.train_ensure_init(id, train)
if result==false then if result==false then
atlog("Train",id,": Restoring path failed, node at",train.last_pos,"is gone! Train will be disabled. You can try to place a rail at this position and restart the server.") atlog("Train",id,": Restoring path failed, node at",train.last_pos,"is gone! Train will be disabled. You can try to place a rail at this position and restart the server.")
train.no_step = true train.no_step = true
tracy.ZoneEnd()
return nil return nil
elseif result==nil then elseif result==nil then
if not train.wait_for_path then if not train.wait_for_path then
atlog("Train",id,": Can't initialize: Waiting for the (yet unloaded) node at",train.last_pos," to be loaded.") atlog("Train",id,": Can't initialize: Waiting for the (yet unloaded) node at",train.last_pos," to be loaded.")
end end
train.wait_for_path = true train.wait_for_path = true
tracy.ZoneEnd()
return false return false
end end
-- by now, we should have a working initial path -- by now, we should have a working initial path
@ -339,6 +347,7 @@ function advtrains.train_ensure_init(id, train)
end end
train.dirty = false -- TODO einbauen! train.dirty = false -- TODO einbauen!
tracy.ZoneEnd()
return true return true
end end
@ -348,6 +357,7 @@ end
function advtrains.train_step_b(id, train, dtime) function advtrains.train_step_b(id, train, dtime)
if train.no_step or train.wait_for_path or not train.path then return end if train.no_step or train.wait_for_path or not train.path then return end
tracy.ZoneBeginN("advtrains.train_step_b")
-- in this code, we check variables such as path_trk_? and path_dist. We need to ensure that the path is known for the whole 'Train' zone -- in this code, we check variables such as path_trk_? and path_dist. We need to ensure that the path is known for the whole 'Train' zone
advtrains.path_get(train, atfloor(train.index + 2)) advtrains.path_get(train, atfloor(train.index + 2))
@ -367,7 +377,7 @@ function advtrains.train_step_b(id, train, dtime)
]]-- ]]--
--- 3. handle velocity influences --- --- 3. handle velocity influences ---
tracy.ZoneBeginN("advtrains.train_step_b:sit_v_cap")
local v0 = train.velocity local v0 = train.velocity
local sit_v_cap = train.max_speed -- Maximum speed in current situation (multiple limit factors) local sit_v_cap = train.max_speed -- Maximum speed in current situation (multiple limit factors)
-- The desired speed change issued by the active control (user or atc) -- The desired speed change issued by the active control (user or atc)
@ -410,11 +420,14 @@ function advtrains.train_step_b(id, train, dtime)
--atprint("in train_step_b: applying front_off_track") --atprint("in train_step_b: applying front_off_track")
sit_v_cap = 0 sit_v_cap = 0
end end
tracy.ZoneEnd()
--interpret ATC command and apply auto-lever control when not actively controlled --interpret ATC command and apply auto-lever control when not actively controlled
local userc = train.ctrl_user local userc = train.ctrl_user
if userc then if userc then
tracy.ZoneBeginN("advtrains.train_step_b:ctrl_user")
--atprint("in train_step_b: ctrl_user active",userc) --atprint("in train_step_b: ctrl_user active",userc)
advtrains.atc.train_reset_command(train) advtrains.atc.train_reset_command(train)
@ -424,7 +437,9 @@ function advtrains.train_step_b(id, train, dtime)
ctrl_braking = true ctrl_braking = true
end end
ctrl_lever = userc ctrl_lever = userc
tracy.ZoneEnd()
else else
tracy.ZoneBeginN("advtrains.train_step_b:ctrl_atc")
if train.atc_command then if train.atc_command then
if (not train.atc_delay or train.atc_delay<=0) if (not train.atc_delay or train.atc_delay<=0)
and not train.atc_wait_finish and not train.atc_wait_finish
@ -480,6 +495,7 @@ function advtrains.train_step_b(id, train, dtime)
ctrl_lever = VLEVER_ROLL ctrl_lever = VLEVER_ROLL
end end
end end
tracy.ZoneEnd()
end end
--- 2b. look at v_target, determine the effective v_target and desired acceleration --- --- 2b. look at v_target, determine the effective v_target and desired acceleration ---
@ -491,6 +507,7 @@ function advtrains.train_step_b(id, train, dtime)
-- Iterates over the path nodes we WOULD pass if we were continuing with the current speed -- Iterates over the path nodes we WOULD pass if we were continuing with the current speed
-- and determines the MINIMUM of path_speed in this range. -- and determines the MINIMUM of path_speed in this range.
-- Then, determines acceleration so that we can reach this 'overridden' target speed in this step (but short-circuited) -- Then, determines acceleration so that we can reach this 'overridden' target speed in this step (but short-circuited)
tracy.ZoneBeginN("advtrains.train_step_b:lzb_v_cap")
local lzb_next_zero_barrier -- if defined, train should not pass this point as it's a 0-LZB local lzb_next_zero_barrier -- if defined, train should not pass this point as it's a 0-LZB
local new_index_curr_tv -- pre-calculated new train index in lzb check local new_index_curr_tv -- pre-calculated new train index in lzb check
local lzb_v_cap -- the maximum speed that LZB dictates local lzb_v_cap -- the maximum speed that LZB dictates
@ -528,8 +545,10 @@ function advtrains.train_step_b(id, train, dtime)
train.hud_lzb_effect_tmr = train.hud_lzb_effect_tmr - 1 train.hud_lzb_effect_tmr = train.hud_lzb_effect_tmr - 1
end end
end end
tracy.ZoneEnd()
-- We now need to bring ctrl_*, sit_v_cap and lzb_v_cap together to determine the final controls. -- We now need to bring ctrl_*, sit_v_cap and lzb_v_cap together to determine the final controls.
tracy.ZoneBeginN("advtrains.train_step_b:v_cap")
local v_cap = sit_v_cap -- always defined, by default train.max_speed local v_cap = sit_v_cap -- always defined, by default train.max_speed
if lzb_v_cap and lzb_v_cap < v_cap then if lzb_v_cap and lzb_v_cap < v_cap then
v_cap = lzb_v_cap v_cap = lzb_v_cap
@ -557,6 +576,7 @@ function advtrains.train_step_b(id, train, dtime)
lever = ctrl_lever lever = ctrl_lever
end end
train.lever = lever train.lever = lever
tracy.ZoneEnd()
--atprint("in train_step_b: final control: accelerating",accelerating,"braking",braking,"lever", lever, "target", v_tar) --atprint("in train_step_b: final control: accelerating",accelerating,"braking",braking,"lever", lever, "target", v_tar)
@ -567,6 +587,7 @@ function advtrains.train_step_b(id, train, dtime)
--- 3b. if braking, modify the velocity BEFORE the movement --- 3b. if braking, modify the velocity BEFORE the movement
if braking then if braking then
tracy.ZoneBeginN("advtrains.train_step_b:braking")
local dv = advtrains.get_acceleration(train, lever) * dtime local dv = advtrains.get_acceleration(train, lever) * dtime
local v1 = v0 + dv local v1 = v0 + dv
if v_tar and v1 < v_tar then if v_tar and v1 < v_tar then
@ -587,10 +608,12 @@ function advtrains.train_step_b(id, train, dtime)
--atprint("in train_step_b: Braking: New velocity",v1," (yields acceleration",train.acceleration,")") --atprint("in train_step_b: Braking: New velocity",v1," (yields acceleration",train.acceleration,")")
-- make saved new_index_curr_tv invalid because speed has changed -- make saved new_index_curr_tv invalid because speed has changed
new_index_curr_tv = nil new_index_curr_tv = nil
tracy.ZoneEnd()
end end
--- 4. move train --- --- 4. move train ---
-- if we have calculated the new end index before, don't do that again -- if we have calculated the new end index before, don't do that again
tracy.ZoneBeginN("advtrains.train_step_b:movement")
if not new_index_curr_tv then if not new_index_curr_tv then
local dst_curr_v = train.velocity * dtime local dst_curr_v = train.velocity * dtime
new_index_curr_tv = advtrains.path_get_index_by_offset(train, train.index, dst_curr_v) new_index_curr_tv = advtrains.path_get_index_by_offset(train, train.index, dst_curr_v)
@ -673,9 +696,11 @@ function advtrains.train_step_b(id, train, dtime)
recalc_end_index(train) recalc_end_index(train)
--atprint("in train_step_b: New index",train.index,"end",train.end_index,"vel",train.velocity) --atprint("in train_step_b: New index",train.index,"end",train.end_index,"vel",train.velocity)
tracy.ZoneEnd()
--- 4a. if accelerating, modify the velocity AFTER the movement --- 4a. if accelerating, modify the velocity AFTER the movement
if accelerating then if accelerating then
tracy.ZoneBeginN("advtrains.train_step_b:accelerating")
local dv = advtrains.get_acceleration(train, lever) * dtime local dv = advtrains.get_acceleration(train, lever) * dtime
local v1 = v0 + dv local v1 = v0 + dv
if v_tar and v1 > v_tar then if v_tar and v1 > v_tar then
@ -690,7 +715,9 @@ function advtrains.train_step_b(id, train, dtime)
train.acceleration = (v1 - v0) / dtime train.acceleration = (v1 - v0) / dtime
train.velocity = v1 train.velocity = v1
--atprint("in train_step_b: Accelerating: New velocity",v1," (yields acceleration",train.acceleration,")") --atprint("in train_step_b: Accelerating: New velocity",v1," (yields acceleration",train.acceleration,")")
tracy.ZoneEnd()
end end
tracy.ZoneEnd()
end end
function advtrains.train_step_c(id, train, dtime) function advtrains.train_step_c(id, train, dtime)
@ -702,6 +729,8 @@ function advtrains.train_step_c(id, train, dtime)
-- Return if something(TM) damaged the path -- Return if something(TM) damaged the path
if train.no_step or train.wait_for_path or not train.path then return end if train.no_step or train.wait_for_path or not train.path then return end
tracy.ZoneBeginN("advtrains.train_step_c")
advtrains.path_clear_unused(train) advtrains.path_clear_unused(train)
@ -811,6 +840,7 @@ function advtrains.train_step_c(id, train, dtime)
end end
end end
end end
tracy.ZoneEnd()
end end
-- Default occupation callbacks for node callbacks -- Default occupation callbacks for node callbacks

View File

@ -42,6 +42,8 @@ function advtrains.lines.save()
end end
function advtrains.lines.step(dtime) function advtrains.lines.step(dtime)
tracy.ZoneBeginN("advtrains.lines.step")
advtrains.lines.rwt.step(dtime) advtrains.lines.rwt.step(dtime)
advtrains.lines.sched.run() advtrains.lines.sched.run()
tracy.ZoneEnd()
end end

View File

@ -46,6 +46,7 @@ function iq.add(t, pos, evtdata)
end end
function iq.mainloop(dtime) function iq.mainloop(dtime)
tracy.ZoneBeginN("atlatc.interrupt.mainloop")
timer=timer + math.min(dtime, 0.2) timer=timer + math.min(dtime, 0.2)
local i=1 local i=1
while i<=#queue do while i<=#queue do
@ -66,6 +67,7 @@ function iq.mainloop(dtime)
i=i+1 i=i+1
end end
end end
tracy.ZoneEnd()
end end