hiby: debug_menu: Add RAM info for hosted targets

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 0484b46165117681782282059884f38795a7d0ba
Author: Roman Artiukhin <[email protected]>
Date:   Wed Feb 4 13:25:56 2026 +0200

    hiby: debug_menu: Add RAM info for hosted targets
    
    Change-Id: I627cdd71fc7c923b2e917c395d6c2d1111147b17

diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 61788fe559..8f4e1d673c 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -143,6 +143,10 @@
 #include "iap.h"
 #endif
 
+#ifdef HIBY_LINUX
+#include <sys/sysinfo.h>
+#endif
+
 #define SCREEN_MAX_CHARS (LCD_WIDTH / SYSFONT_WIDTH)
 
 static const char* threads_getname(int selected_item, void *data,
@@ -2800,6 +2804,55 @@ static bool dbg_bootflash_dump(void) {
 }
 #endif
 
+#ifdef HIBY_LINUX
+static bool view_ram_info(void)
+{
+    struct simplelist_info info;
+    simplelist_info_init(&info, "RAM Info", 0, NULL);
+
+    simplelist_reset_lines();
+    simplelist_addline("Rockbox: %d MB", MEMORYSIZE);
+
+    struct sysinfo sys_info;
+    if (sysinfo(&sys_info) == 0) {
+        long total_ram = sys_info.totalram * sys_info.mem_unit / 1024 / 1024;
+        long free_ram = sys_info.freeram * sys_info.mem_unit / 1024 / 1024;
+        long buffer_ram = sys_info.bufferram * sys_info.mem_unit / 1024 / 1024;
+        simplelist_addline("Total RAM: %ld MB", total_ram);
+        simplelist_addline("Free RAM: %ld MB", free_ram);
+        simplelist_addline("Buffer RAM: %ld MB", buffer_ram);
+
+        /* Try to read MemAvailable from /proc/meminfo for a better "free" estimate */
+        FILE *fp = fopen("/proc/meminfo", "r");
+        if (fp) {
+            char line[128];
+            long mem_avail = -1;
+            long cached = -1;
+            while (fgets(line, sizeof(line), fp)) {
+                if (sscanf(line, "MemAvailable: %ld kB", &mem_avail) == 1) {
+                        mem_avail /= 1024;
+                }
+                else if (sscanf(line, "Cached: %ld kB", &cached) == 1) {
+                        cached /= 1024;
+                }
+            }
+            fclose(fp);
+
+            if (mem_avail != -1) {
+                /* Estimate of how much memory is available for starting new applications */
+                simplelist_addline("Available: %ld MB", mem_avail);
+            }
+            if (cached != -1) {
+                /* Memory used by the page cache. */
+                simplelist_addline("Cached: %ld MB", cached);
+            }
+        }
+    }
+
+    return simplelist_show_list(&info);
+}
+#endif
+
 /****** The menu *********/
 static const struct {
     unsigned char *desc; /* string or ID */
@@ -2839,6 +2892,9 @@ static const struct {
 #ifdef __linux__
         { "View CPU stats", dbg_cpuinfo },
 #endif
+#ifdef HIBY_LINUX
+        { "View RAM info", view_ram_info },
+#endif
 #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
         { "View battery", view_battery },
 #endif
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.