summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2020-10-05 03:28:02 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2020-10-05 11:53:27 -0400
commitef34126913978c7cd6e5b0831f78ac8355f053f0 (patch)
tree4a719e60a52d19031ed485d8c9e9fd64e446ef97 /apps/plugins/lua/rocklib.c
parent74258fca311b2d7e9d834ab8607f2bd326f67807 (diff)
downloadrockbox-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/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 5f0143efbb..8921c0a4c3 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -53,6 +53,8 @@
*
* -----------------------------
*/
+extern size_t rock_get_allocated_bytes(void); /* tlsf_helper.c */
+extern size_t rock_get_unused_bytes(void);
#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L)
#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; }
@@ -931,6 +933,19 @@ RB_WRAP(show_logo)
return 0;
}
+RB_WRAP(mem_stats)
+{
+ /* used, allocd, free = rb.mem_stats() */
+ /* note free is the high watermark */
+ size_t allocd = rock_get_allocated_bytes();
+ size_t free = rock_get_unused_bytes();
+
+ lua_pushinteger(L, allocd - free);
+ lua_pushinteger(L, allocd);
+ lua_pushinteger(L, free);
+ return 3;
+}
+
#define RB_FUNC(func) {#func, rock_##func}
#define RB_ALIAS(name, func) {name, rock_##func}
static const luaL_Reg rocklib[] =
@@ -1015,6 +1030,7 @@ static const luaL_Reg rocklib[] =
/* MISC */
RB_FUNC(restart_lua),
RB_FUNC(show_logo),
+ RB_FUNC(mem_stats),
{NULL, NULL}
};