Skip to content

memstatus

Background task that prints Lua and bitmap RAM every few seconds.

This is a very simple script that can be run as a background task on your model config.

It is useful within the simulator when tracking memory usage of your script.

Install: copy the folder to SCRIPTS:/memstatus/ on the radio (or the simulator's scripts/ folder) and restart.

main.lua
-- Simple script that can run as a background task.
-- it will print out memory status to the console every 
-- 5 seconds (or whatever interval you set)
-- this is helpfull when building memory sensitive scripts
-- as it can aid tracking down memory intensive code.
local config = {}
config.taskName = "MemStatus"
config.taskKey = "memstat"

local interval = 5
local wakeupScheduler = os.clock()
local mem

prevluaRamAvailable = 0
prevluaBitmapsRamAvailable = 0

function wakeup()

    local now = os.clock()

    if (now - wakeupScheduler) >= interval then
        wakeupScheduler = now

        mem = system.getMemoryUsage()

        local ramDiff = (mem.luaRamAvailable - prevluaRamAvailable) / 1000 .. 'kB'
        local bmpDiff = (mem.luaBitmapsRamAvailable - prevluaBitmapsRamAvailable) / 1000 .. 'kB'

        prevluaRamAvailable = mem.luaRamAvailable
        prevluaBitmapsRamAvailable = mem.luaBitmapsRamAvailable

        print("-------------------------------------------------------")
        print("luaRamAvailable..........: " .. mem.luaRamAvailable / 1000 .. "kB" .. " [" .. ramDiff .. "]")
        print("luaBitmapsRamAvailable...: " .. mem.luaBitmapsRamAvailable / 1000 .. "kB" .. " [" .. bmpDiff .. "]")
        print("------------------------------------------------------\r\n")

    end

end

local function init()
    system.registerTask({name = config.taskName, key = config.taskKey, wakeup = wakeup})
end

return {init = init}