Getting memory usage of a single widget
Posted: 23 Sep 2021, 17:00
While the profiler is nice to get the ram usage delta, I have found no way of accessing what local variables a widget has inside its own 'scope', to calculate how much ram its using in mostly table data.
Example widget:
In this case, I dont know how to get the variable BigTable, as it does not appear in the getlocal list. How should I iterate through all the variables that have been declared in the widget's scope?
EDIT: I have tried sifting recursively through all the variables returned by debug.getlocal at both stack levels 1 and 2, but BigTable is never in it
Example widget:
Code: Select all
function widget:GetInfo()
return {
name = "*GETMEMORYUSAGE",
desc = "Tries to print ram usage",
author = "Beherith",
date = "2021 Sept",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
local BigTable = {1,2,3,4}
local IWantThisOne = true
function widget:Initialize()
local IDontWantThisOne = true
end
function widget:GameFrame()
BigTable[ #BigTable + 1 ] = #BigTable
local ThisVariableActualllyGetsFoundByGetLocal = true
while true do
local i = 1
local n, v = debug.getlocal(1, i)
if not n then break end
Spring.Echo(n)
i = i+1
end
end
EDIT: I have tried sifting recursively through all the variables returned by debug.getlocal at both stack levels 1 and 2, but BigTable is never in it