ef34126913
lua gives you a memory used number that only reflects the current allocations if fact it doesn't even give you a way to get the amount of ram free rb.mem_stats() seeks to fill this gap by marking the memory allocated for lua with a sentinel value which can later be checked to get a high water mark of the ram used by lua and a pretty good idea of how much ram is available Also includes an example script usage: used, allocd, free = rb.mem_stats() Change-Id: Ia282869f989848324d7d88c7df4827fdbce4fb4e
32 lines
1.3 KiB
Lua
32 lines
1.3 KiB
Lua
--[[
|
|
__________ __ ___.
|
|
Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
\/ \/ \/ \/ \/
|
|
$Id$
|
|
Example Lua Memory Use
|
|
Copyright (C) 2020 William Wilgus
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
KIND, either express or implied.
|
|
]]--
|
|
|
|
local used, allocd, free = rb.mem_stats()
|
|
local lu = collectgarbage("count")
|
|
local fmt = function(t, v) return string.format("%s: %d Kb\n", t, v /1024) end
|
|
|
|
-- this is how lua recommends to concat strings rather than ..
|
|
local s_t = {}
|
|
s_t[1] = "rockbox:\n"
|
|
s_t[2] = fmt("Used ", used)
|
|
s_t[3] = fmt("Allocd ", allocd)
|
|
s_t[4] = fmt("Free ", free)
|
|
s_t[5] = "\nlua:\n"
|
|
s_t[6] = fmt("Used", lu * 1024)
|
|
s_t[7] = "\n\nNote that the rockbox used count is a high watermark"
|
|
rb.splash_scroller(10 * rb.HZ, table.concat(s_t))
|