Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-01-14, 06:25 PM   #1
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Hooking my own functions

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:
  1. _, ProfilerTestAddon= ...
  2.  
  3. function ProfilerTestAddon:Test1()
  4.     print("Test1")
  5. end
  6. function ProfilerTestAddon:Test2()
  7.     print("Test2")
  8. end
  9.  
  10. local function Profiler(self, fName, func)
  11.     print("profiler:",fName, GetTime(), func)
  12. end
  13.  
  14. for i, v in pairs(ProfilerTestAddon) do
  15.     if type(v) == "function" then
  16.         hooksecurefunc(ProfilerTestAddon, i, function(self) Profiler(self, i, v) end)
  17.     end
  18. 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:
  1. _, ProfilerTestAddon= ...
  2.  
  3. function ProfilerTestAddon:Test1()
  4.     print("Test1")
  5. end
  6. function ProfilerTestAddon:Test2()
  7.     print("Test2")
  8. end
  9.  
  10. local function Profiler(self, fName, func)
  11.     print("profiler IN:",fName, GetTime())
  12.     func()
  13.     print("profiler OUT:",fName, GetTime())
  14. end
  15.  
  16. for i, v in pairs(ProfilerTestAddon) do
  17.     if type(v) == "function" then
  18.         print("hooking", i)
  19.         local tmp = v
  20.         v = function(self)
  21.             Profiler(self, i, v)
  22.         end
  23.         print(tmp == v)
  24.     end
  25. 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:
  1. for i, v in pairs(ProfilerTestAddon) do
  2.     if type(v) == "function" then
  3.         print("hooking", i)
  4.         local tmp = v
  5.         v = nil
  6.         print(tmp == v)
  7.     end
  8. end
doesn't break something. ProfilerTestAddon:Test1() does still work.

Last edited by Duugu : 09-01-14 at 06:33 PM.
  Reply With Quote
 

WoWInterface » Developer Discussions » General Authoring Discussion » Hooking my own functions


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off