Hey all
I'm trying to so find some performance leaks in my addons code. My first thought was to hook everything and to see how long it takes.
So I came up with this:
Lua Code:
_, ProfilerTestAddon= ...
function ProfilerTestAddon:Test1()
print("Test1")
end
function ProfilerTestAddon:Test2()
print("Test2")
end
local function Profiler(self, fName, func)
print("profiler:",fName, GetTime(), func)
end
for i, v in pairs(ProfilerTestAddon) do
if type(v) == "function" then
hooksecurefunc(ProfilerTestAddon, i, function(self) Profiler(self, i, v) end)
end
end
Works as expected.
But ... to see how much time function needs a post-hook via hooksecurefunc obv. isn't enough. So I tried this:
Lua Code:
_, ProfilerTestAddon= ...
function ProfilerTestAddon:Test1()
print("Test1")
end
function ProfilerTestAddon:Test2()
print("Test2")
end
local function Profiler(self, fName, func)
print("profiler IN:",fName, GetTime())
func()
print("profiler OUT:",fName, GetTime())
end
for i, v in pairs(ProfilerTestAddon) do
if type(v) == "function" then
print("hooking", i)
local tmp = v
v = function(self)
Profiler(self, i, v)
end
print(tmp == v)
end
end
To my surprise that didn't worked.
It iterates the functions. The line
print(tmp == v) returns
false. I can call ProfilerTestAddon:Test1() and it does print "Test2". But that's it. Profiler() is not called.
What the hell could be wrong with it?
[e]
Even
Lua Code:
for i, v in pairs(ProfilerTestAddon) do
if type(v) == "function" then
print("hooking", i)
local tmp = v
v = nil
print(tmp == v)
end
end
doesn't break something. ProfilerTestAddon:Test1() does still work.