06a73a069f
- aggiunta libreria TimeLib per calcolare i tempi di esecuzione (sostituite chiamate a EgtStartCounter e Stop) - rimosse chiamate a EgtOutLog deprecate
71 lines
1.8 KiB
Lua
71 lines
1.8 KiB
Lua
-- BeamLib.lua by Egalware s.r.l. 2025/11/24
|
|
-- Libreria calcolo tempo automatismo
|
|
|
|
|
|
-- Tabella per definizione modulo
|
|
local TimeLib = {}
|
|
|
|
|
|
EgtOutLog( ' TimeLib started', 1)
|
|
|
|
|
|
TimeLib.__index = TimeLib
|
|
|
|
function TimeLib.new()
|
|
local self = setmetatable({}, TimeLib)
|
|
self.dStartTime = os.clock()
|
|
self.Checkpoints = {} -- each checkpoint stores first and last timestamps
|
|
return self
|
|
end
|
|
|
|
-- reset timer
|
|
function TimeLib:start()
|
|
self.dStartTime = os.clock()
|
|
self.Checkpoints = {}
|
|
end
|
|
|
|
-- setta un checkpoint con nome (default se non specificato)
|
|
function TimeLib:setCheckpoint( sName)
|
|
local sCpName = sName or "default"
|
|
local dNow = os.clock()
|
|
|
|
if not self.Checkpoints[sCpName] then
|
|
self.Checkpoints[sCpName] = { dFirst = dNow, dLast = dNow }
|
|
else
|
|
self.Checkpoints[sCpName].dLast = dNow
|
|
end
|
|
end
|
|
|
|
-- ritorna il tempo trascorso
|
|
-- se settato un checkpoint, ritorna anche il tempo di quel checkpoint, cumulativo (dal primo checkpoint settato con quel nome) e recente (dall'ultimo checkpoint settato)
|
|
function TimeLib:elapsed( sCheckpointName)
|
|
local dTotal = os.clock() - self.dStartTime
|
|
local sCpName = sCheckpointName or "default"
|
|
local Checkpoint = self.Checkpoints[sCpName]
|
|
|
|
if Checkpoint then
|
|
local dCumulative = os.clock() - Checkpoint.dFirst
|
|
local dRecent = os.clock() - Checkpoint.dLast
|
|
return dTotal, dCumulative, dRecent
|
|
else
|
|
return dTotal, nil, nil
|
|
end
|
|
end
|
|
|
|
-- log del tempo trascorso, come sopra
|
|
function TimeLib:logElapsed( sCheckpointName)
|
|
local dTotal, dCumulative, dRecent = self:elapsed( sCheckpointName)
|
|
local sCpName = sCheckpointName or "default"
|
|
|
|
if dCumulative then
|
|
EgtOutLog( string.format(
|
|
"%s time: recent %.3f, cumulative %.3f, total %.3f",
|
|
sCpName, dRecent, dCumulative, dTotal))
|
|
else
|
|
EgtOutLog( string.format("Total %.3f (no checkpoint '%s' set)",
|
|
dTotal, sCpName))
|
|
end
|
|
end
|
|
|
|
return TimeLib
|