Also show values of local variables in top 50

This commit is contained in:
FPtje 2016-04-27 22:32:22 +02:00
parent ee5ffa6965
commit bf3c56454f

View File

@ -2,7 +2,7 @@ local timeMeasurementFunc = SysTime
-- Helper function, created by some ancient Lua dev
-- Retrieves the local variables and their values of a function
function getupvalues(f)
local function getupvalues(f)
local t, i, k, v = {}, 1, debug.getupvalue(f, 1)
while k do
t[k] = v
@ -12,6 +12,28 @@ function getupvalues(f)
return t
end
-- Helper function
-- Get all local variables
local NIL = {}
setmetatable(NIL, {__tostring = function() return "nil" end})
local function getlocals(level)
local i = 1
local name, value
local vars = {}
while true do
name, value = debug.getlocal(level, i)
if not name then break end
value = value == nil and NIL or value
vars[name] = value
i = i + 1
end
return vars
end
--[[-------------------------------------------------------------------------
Call counts:
@ -164,7 +186,8 @@ local function registerReturn(funcInfo)
-- Update the entry
mostExpensiveSingleCalls[i].runtime = runtime
mostExpensiveSingleCalls[i].state = getupvalues(func)
mostExpensiveSingleCalls[i].upvalues = getupvalues(func)
mostExpensiveSingleCalls[i].locals = getlocals(5)
mostExpensiveSingleCalls[i].info = funcInfo
mostExpensiveSingleCalls[i].func = func
@ -198,7 +221,8 @@ local function registerReturn(funcInfo)
func = func,
runtime = runtime,
info = funcInfo,
state = getupvalues(func)
upvalues = getupvalues(func),
locals = getlocals(5)
})