-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespaces.lua
65 lines (58 loc) · 1.93 KB
/
namespaces.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
58
59
60
61
62
63
64
65
local OUR_NAME, profiler = ...
local known = {}
function profiler.newGlobals()
-- traverse global namespace looking for unknown names
local new = {}
for key,value in pairs(_G) do
if type(key)=="string" and not known[key] then
known[key] = value
if type(value)=="function" or type(value)=="table" then
new[key] = value
end
end
end
return new
end
profiler.namespaces = {
[0] = {name="Root", title="Root", cpu=0, mem=0, value=profiler.namespaces}
}
function profiler.registerNamespace(name, namespace, parent, seen)
if not seen then
-- break cycles and avoid misattribution
seen = {
[_G] = true,
[profiler.namespaces] = true,
}
end
local this = {}
for key,value in pairs(namespace) do
if type(value)=="function" and type(key)=="string" then
this[key] = value
this[#this+1] = {name=key, title=key, fun=value, cpu=0, type="function"}
end
if type(value)=="table" and type(key)=="string" and not seen[value] then
seen[value] = true
local child = profiler.registerNamespace(key, value, this, seen)
if child then
this[key] = child
this[#this+1] = {name=key, title=key, namespace=child, type="table", cpu=0}
if rawget(value, 0) and type(rawget(value,0))=="userdata" then
this[#this].subtype = "frame"
end
end
seen[value] = nil
end
end
if #this>0 then
if not parent then
parent = profiler.namespaces
parent[#parent+1] = {name=name, title=name, namespace=this, type="addon", cpu=0, mem=0}
parent[name] = this
end
this[-1] = parent
this[0] = {name=name,title=name,namespace=this,type="table"}
return this
else
return nil
end
end