-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.lua
More file actions
35 lines (32 loc) · 821 Bytes
/
Copy pathprofile.lua
File metadata and controls
35 lines (32 loc) · 821 Bytes
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
local counter = {}
local names = {}
local function hook()
local func = debug.getinfo(2, "f").func;
if(not counter[func]) then
counter[func] = 1;
names[func] = debug.getinfo(2, "Sn");
else
counter[func] = counter[func] + 1;
end
end
local function getName(func)
local info = names[func];
if(info.what == "C") then
return "C:" .. (info.name or "");
else
local lc = string.format("[%s]:%s", info.short_src, info.linedefined)
if(info.namewhat ~= "") then
return string.format("%s(%s)", lc, info.name);
else
return lc;
end
end
end
local entry = ...
local f = assert(loadfile(entry));
debug.sethook(hook, "c");
f()
debug.sethook();
for func, count in pairs(counter) do
print(getName(func), count)
end