diff options
author | William Wilgus <wilgus.william@gmail.com> | 2020-10-05 03:28:02 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2020-10-05 11:53:27 -0400 |
commit | ef34126913978c7cd6e5b0831f78ac8355f053f0 (patch) | |
tree | 4a719e60a52d19031ed485d8c9e9fd64e446ef97 /apps/plugins/lua_scripts/memchk.lua | |
parent | 74258fca311b2d7e9d834ab8607f2bd326f67807 (diff) | |
download | rockbox-ef34126913978c7cd6e5b0831f78ac8355f053f0.tar.gz rockbox-ef34126913978c7cd6e5b0831f78ac8355f053f0.zip |
lua add better memory stats
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
Diffstat (limited to 'apps/plugins/lua_scripts/memchk.lua')
-rw-r--r-- | apps/plugins/lua_scripts/memchk.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/apps/plugins/lua_scripts/memchk.lua b/apps/plugins/lua_scripts/memchk.lua new file mode 100644 index 0000000000..f7619fe3dd --- /dev/null +++ b/apps/plugins/lua_scripts/memchk.lua | |||
@@ -0,0 +1,32 @@ | |||
1 | --[[ | ||
2 | __________ __ ___. | ||
3 | Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | \/ \/ \/ \/ \/ | ||
8 | $Id$ | ||
9 | Example Lua Memory Use | ||
10 | Copyright (C) 2020 William Wilgus | ||
11 | This program is free software; you can redistribute it and/or | ||
12 | modify it under the terms of the GNU General Public License | ||
13 | as published by the Free Software Foundation; either version 2 | ||
14 | of the License, or (at your option) any later version. | ||
15 | This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | KIND, either express or implied. | ||
17 | ]]-- | ||
18 | |||
19 | local used, allocd, free = rb.mem_stats() | ||
20 | local lu = collectgarbage("count") | ||
21 | local fmt = function(t, v) return string.format("%s: %d Kb\n", t, v /1024) end | ||
22 | |||
23 | -- this is how lua recommends to concat strings rather than .. | ||
24 | local s_t = {} | ||
25 | s_t[1] = "rockbox:\n" | ||
26 | s_t[2] = fmt("Used ", used) | ||
27 | s_t[3] = fmt("Allocd ", allocd) | ||
28 | s_t[4] = fmt("Free ", free) | ||
29 | s_t[5] = "\nlua:\n" | ||
30 | s_t[6] = fmt("Used", lu * 1024) | ||
31 | s_t[7] = "\n\nNote that the rockbox used count is a high watermark" | ||
32 | rb.splash_scroller(10 * rb.HZ, table.concat(s_t)) | ||