mirror of
https://github.com/FPtje/FProfiler.git
synced 2025-03-04 03:03:14 -05:00
Also show values of local variables in top 50
This commit is contained in:
parent
ee5ffa6965
commit
bf3c56454f
@ -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)
|
||||
})
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user