Created
August 21, 2014 08:55
-
-
Save akirayu101/5603d3979ca6c094c4b2 to your computer and use it in GitHub Desktop.
hook timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "src/third/socket.lua" | |
local time_table = {} | |
local function hook_timer(o, key, value) | |
if type(value) == "function" and value ~= "summary" then | |
local function inner( ... ) | |
time_table[key] = time_table[key] or 0.0 | |
print("in function ",key) | |
local start = socket.gettime() | |
value(...) | |
local stop = socket.gettime() | |
time_table[key] = time_table[key] + stop - start | |
local i = 3 | |
while debug.getinfo(i) ~= nil and time_table[debug.getinfo(i).name] ~= nil do | |
time_table[debug.getinfo(i).name] = time_table[debug.getinfo(i).name] - stop + start | |
i = i + 1 | |
end | |
end | |
rawset(o, key, inner) | |
else | |
rawset(o, key, value) | |
end | |
end | |
setmetatable(_G,{__newindex = hook_timer }) | |
function fuck() | |
local sum = 0 | |
for i = 1, 1000000000 do | |
sum = sum + i | |
end | |
return sum | |
end | |
function main() | |
fuck() | |
end | |
function summary() | |
for k, v in pairs(time_table) do | |
print(k,"=>",v) | |
end | |
end | |
main() | |
summary() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment