-
Notifications
You must be signed in to change notification settings - Fork 6
/
debugExtend.lua
41 lines (34 loc) · 1.12 KB
/
debugExtend.lua
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
local DEBUG={}
local loadTimeList,lastTimeStamp={},ZENITHA.timer.getTime()
---Use this a few times in main.lua to mark time used for loading,
---then use `DEBUG.logLoadTime()` to log the times
---@param msg string
function DEBUG.checkLoadTime(msg)
table.insert(loadTimeList,("%-26s \t%.3fs"):format(tostring(msg)..":",ZENITHA.timer.getTime()-lastTimeStamp))
lastTimeStamp=ZENITHA.timer.getTime()
end
---Log the times marked by `DEBUG.checkLoadTime()`
function DEBUG.logLoadTime()
for i=1,#loadTimeList do LOG('info',loadTimeList[i]) end
end
---Set metatable for _G, print messages when a new variable is created
function DEBUG.runVarMonitor()
setmetatable(_G,{__newindex=function(self,k,v)
print(">>"..k)
print(debug.traceback():match("\n.-\n\t(.-): "))
rawset(self,k,v)
end})
end
---Set Visible collectgarbage call
function DEBUG.setCollectGarbageVisible()
local _gc=collectgarbage
collectgarbage=function()
_gc()
print(debug.traceback())
end
end
---Shortcut for `print(debug.traceback())`
function DEBUG.trace()
print(debug.traceback("DEBUG",2))
end
return DEBUG