@@ -170,10 +170,12 @@ static void update_memory_statistics(void)
170170 statistics .totalMemoryExt = heap_info .total_free_bytes + heap_info .total_allocated_bytes ;
171171 statistics .freeMemoryExt = heap_info .total_free_bytes ;
172172 statistics .freeBlockExt = heap_info .largest_free_block ;
173- // FIXME: We should check all the tasks' HWM to be better informed!
174- statistics .freeStackMain = uxTaskGetStackHighWaterMark (tasks [0 ].handle );
173+ for ( size_t i = 0 ; i < RG_COUNT ( tasks ); ++ i )
174+ statistics .freeStack [ i ] = tasks [ i ]. handle ? uxTaskGetStackHighWaterMark (tasks [i ].handle ) : -1 ;
175175#else
176176 statistics .freeMemoryInt = statistics .freeBlockInt = statistics .totalMemoryInt = 0x40000000 ;
177+ for (size_t i = 0 ; i < RG_COUNT (tasks ); ++ i )
178+ statistics .freeStack [i ] = 0xFFFF ;
177179#endif
178180 statistics .totalMemory = statistics .totalMemoryInt + statistics .totalMemoryExt ;
179181 statistics .freeMemory = statistics .freeMemoryInt + statistics .freeMemoryExt ;
@@ -267,8 +269,8 @@ static void system_monitor_task(void *arg)
267269 update_indicators (false);
268270
269271 // Try to avoid complex conversions that could allocate, prefer rounding/ceiling if necessary.
270- rg_system_log (RG_LOG_DEBUG , NULL , "STACK:%d, HEAP:%d+%d (%d+%d), BUSY:%d%%, FPS:%d (%d+ %d+%d), BATT:%d\n " ,
271- statistics .freeStackMain ,
272+ rg_system_log (RG_LOG_DEBUG , NULL , "STACK:%d, HEAP:%d+%d (%d+%d), BUSY:%d%%, FPS:%d (S:%d R: %d+%d), BATT:%d" ,
273+ statistics .freeStack [ 0 ] ,
272274 statistics .freeMemoryInt / 1024 ,
273275 statistics .freeMemoryExt / 1024 ,
274276 statistics .freeBlockInt / 1024 ,
@@ -280,6 +282,14 @@ static void system_monitor_task(void *arg)
280282 (int )roundf (statistics .fullFPS ),
281283 (int )roundf ((battery .volts * 1000 ) ?: battery .level ));
282284
285+ for (size_t i = 0 ; i < RG_COUNT (tasks ); ++ i )
286+ {
287+ if (tasks [i ].handle && statistics .freeStack [i ] >= 0 && statistics .freeStack [i ] < 300 )
288+ RG_LOGW ("Task %.15s HWM = %d" , tasks [i ].name , statistics .freeStack [i ]);
289+ // if (tasks[i].handle && statistics.freeStack[i] >= 0)
290+ // rg_system_log(statistics.freeStack[i] < 1024 ? RG_LOG_WARN : RG_LOG_DEBUG, NULL, "Stack HWM: %s = %d", tasks[i].name, statistics.freeStack[i]);
291+ }
292+
283293 // Auto frameskip
284294 // TODO: Use a rolling average of frameTimes instead of this mess
285295 if (app .tickRate > 0 && statistics .ticks > app .tickRate * 2 && app .frameskip > -1 ) // -1 disables auto frameskip
@@ -1041,7 +1051,8 @@ bool rg_system_save_trace(const char *filename, bool panic_trace)
10411051 fprintf (fp , "Total memory: %d + %d\n" , stats -> totalMemoryInt , stats -> totalMemoryExt );
10421052 fprintf (fp , "Free memory: %d + %d\n" , stats -> freeMemoryInt , stats -> freeMemoryExt );
10431053 fprintf (fp , "Free block: %d + %d\n" , stats -> freeBlockInt , stats -> freeBlockExt );
1044- fprintf (fp , "Stack HWM: %d\n" , stats -> freeStackMain );
1054+ for (int i = 0 ; i < RG_COUNT (stats -> freeStack ); ++ i )
1055+ fprintf (fp , "Task %d HWM: %d\n" , i , stats -> freeStack [i ]);
10451056 fprintf (fp , "Uptime: %ds (%d ticks)\n" , stats -> uptime , stats -> ticks );
10461057 if (panic_trace && panicTrace .configNs [0 ])
10471058 fprintf (fp , "Panic configNs: %.16s\n" , panicTrace .configNs );
0 commit comments