Re-add debug ring buffer and print its contents on a lua crash

When the crash on linuxworks has been fixed, the ringbuffer will go into master and behind an option
also fix last commit
master
orwell96 2017-05-15 13:37:06 +02:00
parent 74c8784b21
commit e484654f89
6 changed files with 89 additions and 3 deletions

View File

@ -0,0 +1,44 @@
--so, some ringbuffers one for each train
local ringbuflen=1000
local ringbufs={}
local ringbufcnt={}
function advtrains.drb_record(tid, msg)
if not ringbufs[tid] then
ringbufs[tid]={}
ringbufcnt[tid]=0
end
ringbufs[tid][ringbufcnt[tid]]=msg
ringbufcnt[tid]=ringbufcnt[tid]+1
if ringbufcnt[tid] > ringbuflen then
ringbufcnt[tid]=0
end
end
function advtrains.drb_dump(tid)
atlog("Debug ring buffer output for '"..tid.."':")
local stopcnt=ringbufcnt[tid]
if not stopcnt then
atlog("ID unknown!")
return
end
repeat
atlog(ringbufs[tid][ringbufcnt[tid]])
ringbufcnt[tid]=ringbufcnt[tid]+1
if ringbufcnt[tid] > ringbuflen then
ringbufcnt[tid]=0
end
until ringbufcnt[tid]==stopcnt
end
minetest.register_chatcommand("atdebug_show",
{
params = "train sid", -- Short parameter description
description = "Dump debug log", -- Full description
privs = {train_operator=true}, -- Require the "privs" privilege to run
func = function(name, param)
advtrains.drb_dump(param)
end, -- Called when command is run.
-- Returns boolean success and text output.
})

View File

@ -170,6 +170,19 @@ function advtrains.minAngleDiffRad(r1, r2)
return try3
end
end
function advtrains.dumppath(path)
atlog("Dumping a path:")
if not path then atlog("dumppath: no path(nil)") return end
local temp_path={}
for ipt, iit in pairs(path) do
temp_path[#temp_path+1]={i=ipt, p=iit}
end
table.sort(temp_path, function (k1, k2) return k1.i < k2.i end)
for _,pit in ipairs(temp_path) do
atlog(pit.i.." > "..minetest.pos_to_string(pit.p))
end
end
function advtrains.merge_tables(a, ...)
local new={}

View File

@ -15,6 +15,13 @@ function advtrains.pcall(fun)
if no_action then return end
local succ, return1, return2, return3, return4=xpcall(fun, function(err)
if advtrains.atprint_context_tid then
local train=advtrains.trains[advtrains.atprint_context_tid_full]
advtrains.dumppath(train.path)
atwarn("Dumping last debug outputs: ", err)
atprint("Train state: index",train.index,"end_index", train.end_index,"| max_iot", train.max_index_on_track, "min_iot", train.min_index_on_track, "<> pe_min", train.path_extent_min,"pe_max", train.path_extent_max)
advtrains.drb_dump(advtrains.atprint_context_tid)
end
atwarn("Lua Error occured: ", err)
atwarn(debug.traceback())
end)
@ -72,7 +79,12 @@ function advtrains.print_concat_table(a)
return str
end
atprint=function() end
atprint=function(t, ...)
local context=advtrains.atprint_context_tid
if not context then return end
local text=advtrains.print_concat_table({t, ...})
advtrains.drb_record(context, text)
end
atlog=function(t, ...)
local context=advtrains.atprint_context_tid
if not context then return end
@ -104,6 +116,8 @@ advtrains.meseconrules =
{x=0, y=-1, z=-1},
{x=0, y=-2, z=0}}
dofile(advtrains.modpath.."/debugringbuffer.lua")
dofile(advtrains.modpath.."/trainlogic.lua")
dofile(advtrains.modpath.."/trainhud.lua")
@ -260,9 +274,12 @@ end
local init_load=false
local save_interval=20
local save_timer=save_interval
advtrains.mainloop_runcnt=0
minetest.register_globalstep(function(dtime_mt)
return advtrains.pcall(function()
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt)
--call load once. see advtrains.load() comment
if not init_load then
advtrains.load()

View File

@ -286,7 +286,7 @@ local ptime=0
minetest.register_chatcommand("at_restore_ndb",
{
params = "", -- Short parameter description
description = "Write node db back to map", -- Full description
description = "Write node db back to map and find ghost nodes", -- Full description
privs = {train_operator=true, worldedit=true}, -- Require the "privs" privilege to run
func = function(name, param)
return advtrains.pcall(function()
@ -298,5 +298,9 @@ minetest.register_chatcommand("at_restore_ndb",
return true
end)
end,
privs = {train_operator=true}, -- Require the "privs" privilege to run
func = function(name, param)
ndb.restore_all()
end, -- Called when command is run.
})

View File

@ -56,14 +56,17 @@ advtrains.mainloop_trainlogic=function(dtime)
advtrains.detector.on_node={}
for k,v in pairs(advtrains.trains) do
advtrains.atprint_context_tid=sid(k)
advtrains.atprint_context_tid_full=k
advtrains.train_step_a(k, v, dtime)
end
for k,v in pairs(advtrains.trains) do
advtrains.atprint_context_tid=sid(k)
advtrains.atprint_context_tid_full=k
advtrains.train_step_b(k, v, dtime)
end
advtrains.atprint_context_tid=nil
advtrains.atprint_context_tid_full=nil
atprintbm("trainsteps", t)
endstep()
@ -131,6 +134,10 @@ train step structure:
]]
function advtrains.train_step_a(id, train, dtime)
atprint("--- runcnt ",advtrains.mainloop_runcnt,": index",train.index,"end_index", train.end_index,"| max_iot", train.max_index_on_track, "min_iot", train.min_index_on_track, "<> pe_min", train.path_extent_min,"pe_max", train.path_extent_max)
if train.min_index_on_track then
assert(math.floor(train.min_index_on_track)==train.min_index_on_track)
end
--- 1. LEGACY STUFF ---
if not train.drives_on or not train.max_speed then
advtrains.update_trainpart_properties(id)
@ -235,6 +242,7 @@ function advtrains.train_step_a(id, train, dtime)
local t_info, train_pos=sid(id), train.path[math.floor(train.index)]
if train_pos then
t_info=t_info.." @"..minetest.pos_to_string(train_pos)
--atprint("train_pos:",train_pos)
end
--apply off-track handling:

View File

@ -286,7 +286,7 @@ function wagon:on_step(dtime)
--check infotext
local outside=self:train().text_outside or ""
if self.object:get_properties().infotext~=outside then
self.object:set_properties({infotext=outside})
self.object:set_properties({infotext=sid(self.train_id)})
end
local gp=self:train()