-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrace.lua
More file actions
94 lines (70 loc) · 2.25 KB
/
trace.lua
File metadata and controls
94 lines (70 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- ----------------------------------------------------------------------------
--
-- Trace
--
-- ----------------------------------------------------------------------------
local Trace = {}
local _write = io.write
local _flush = io.flush
local _format = string.format
local _concat = table.concat
local _clock = os.clock
local mLineCounter = 0
local mTickStart = _clock()
local mTickTimed = _clock()
-- ----------------------------------------------------------------------------
--
function Trace.msg(inMessage)
if not inMessage then return end
mLineCounter = mLineCounter + 1
_write(_format("%05d: ", mLineCounter))
_write(inMessage)
end
-- ----------------------------------------------------------------------------
--
function Trace.cat(inMessage)
if not inMessage then return end
_write(inMessage)
end
-- ----------------------------------------------------------------------------
--
function Trace.flushn()
_write("\n")
_flush()
end
-- ----------------------------------------------------------------------------
--
function Trace.numArray(inTable, inLabel)
local tStrings = {inLabel or ""}
for iIndex, number in ipairs(inTable) do
tStrings[iIndex + 1] = _format("%.04f", number)
end
Trace.line(_concat(tStrings, " "))
end
-- ----------------------------------------------------------------------------
--
function Trace.line(inMessage)
if not inMessage then return end
Trace.msg(inMessage)
_write("\n")
_flush()
end
-- ----------------------------------------------------------------------------
--
function Trace.lnTimeStart(inMessage)
if inMessage then Trace.line(inMessage) end
mTickStart = _clock()
end
-- ----------------------------------------------------------------------------
--
function Trace.lnTimeEnd(inMessage)
mTickTimed = _clock()
inMessage = inMessage or "Stopwatch at"
Trace.line(_format("%s (%.04f s.)", inMessage, (mTickTimed - mTickStart)))
mTickStart = mTickTimed
end
-- ----------------------------------------------------------------------------
--
return Trace
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------