-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtabSnapshotLogger.lua
More file actions
88 lines (69 loc) · 2.46 KB
/
tabSnapshotLogger.lua
File metadata and controls
88 lines (69 loc) · 2.46 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
_tabSnapshotLoggerInstance = nil
tabSnapshotLogger = {}
local function saveErrorInfoToFile(filename, errorMsg)
local file,err = io.open( filename, "wb" )
if err then return err end
file:write(errorMsg)
local fileSize = file:seek()
file:close()
return fileSize
end
function tabSnapshotLogger:getInstance()
if _tabSnapshotLoggerInstance == nil then
_tabSnapshotLoggerInstance = tabSnapshotLogger.new()
end
return _tabSnapshotLoggerInstance
end
function tabSnapshotLogger.new()
local l = {}
setmetatable(l, {__index = tabSnapshotLogger})
l.reportPool = {}
return l
end
function tabSnapshotLogger:dumpTabSnapshot( errorMsg, errorStack, tabStack )
local md5Key = CS.Utils.GetMD5(errorMsg .. errorStack)
local info = self.reportPool[md5Key]
if info then
local count = info.count
local frameIndex = info.frameIndex
info.count = count + 1
info.frameIndex = g_frameIndex
if count > 20 or frameIndex >= g_frameIndex - 1 then
print("tabSnapshotLogger:dumpTabSnapshot 频繁触发,暂时忽略")
return
end
else
info = {
count = 1,
frameIndex = g_frameIndex
}
self.reportPool[md5Key] = info
end
local tabSerialization = require("tabMachine.tabSerialization")
local rootContext = g_root
local snapshotName = md5Key .. os.date('_%Y-%m-%d-%H-%M-%S_') .. g_frameIndex
local filename = CS.UnityEngine.Application.persistentDataPath .. "/err_snapshots/" .. snapshotName
print("creating snapshot ", filename)
CS.SystemIOUtils.EnsureFileDirectoryExists(filename)
local socket = require("socket")
local t0 = socket.gettime()
local detailControl = {
addPath = false,
-- addStat = {
-- statTreeSize = true,
-- },
addTableAddress = false,
extraExcludeKeys = {
class = true,
sprotos = true,
},
}
local snapshot = tabSerialization.createSnapshot(rootContext, detailControl)
snapshot.errorMsgs = string.split(errorStack, "\n")
local t1 = socket.gettime()
print("tabSnapshotLogger create snapshot using time: ", t1 - t0)
local fileSize = tabSerialization.saveSnapshotToFile(snapshot, filename)
local t2 = socket.gettime()
print("tabSnapshotLogger save snapshot to file using time: ", t2 - t1, "/", t2 - t0)
print("tabSnapshotLogger fileSize ", fileSize / (1024*1024), "M")
end