-
Notifications
You must be signed in to change notification settings - Fork 7
/
frameAverage.lua
57 lines (49 loc) · 1.46 KB
/
frameAverage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local util = require("util")
local function addNode(intoNode, node)
intoNode.deltaTime = intoNode.deltaTime + node.deltaTime
intoNode.memoryDelta = intoNode.memoryDelta + node.memoryDelta
intoNode.samples = intoNode.samples + 1
for _, child in ipairs(node.children) do
local intoChild = util.getChildByPath(intoNode, child.path[#child.path])
if not intoChild then
intoChild = {
name = child.name,
deltaTime = 0,
memoryDelta = 0,
parent = intoNode,
samples = 0,
children = {},
}
intoChild.path = {unpack(child.path)}
table.insert(intoNode.children, intoChild)
end
addNode(intoChild, child)
end
end
local function normalizeNode(node)
node.deltaTime = node.deltaTime / node.samples
node.memoryDelta = node.memoryDelta / node.samples
for _, child in ipairs(node.children) do
normalizeNode(child)
end
end
local function getFrameAverage(frames, fromFrame, toFrame)
local frame = {
fromIndex = fromFrame,
toIndex = toFrame,
name = "frame",
deltaTime = 0,
memoryDelta = 0,
parent = nil,
children = {},
path = {},
samples = 0,
pathCache = {},
}
for i = fromFrame, toFrame do
addNode(frame, frames[i])
end
normalizeNode(frame)
return frame
end
return getFrameAverage