diff --git a/apps/ios/SimpleXChat/hs_init.c b/apps/ios/SimpleXChat/hs_init.c index 83056fccfe..7ec270e554 100644 --- a/apps/ios/SimpleXChat/hs_init.c +++ b/apps/ios/SimpleXChat/hs_init.c @@ -10,16 +10,32 @@ extern void hs_init_with_rtsopts(int * argc, char **argv[]); -void haskell_init(void) { - int argc = 5; - char *argv[] = { - "simplex", - "+RTS", // requires `hs_init_with_rtsopts` - "-A16m", // chunk size for new allocations - "-H64m", // initial heap size - "-xn", // non-moving GC - 0 - }; +void haskell_init(const char *eventlog, const char *heap_profile) { + // setup static arena for bump allocation and passing to RTS + char *argv[32] = {0,}; + int argc = 0; // number of arguments used so far, always stands at the first NULL in argv + // common args + argv[argc++] = "simplex"; // fake program name + argv[argc++] = "+RTS"; // start adding RTS options + argv[argc++] = "-T"; // make GC counters available from inside the program + argv[argc++] = "-A16m"; // chunk size for new allocations (less frequent GC) + argv[argc++] = "-H64m"; // larger heap size on start (faster boot) + // argv[argc++] = "-M8G"; // keep memory usage under 8G, collecting more aggressively when approaching it (and crashing sooner rather than taking down the whole system) + if (eventlog) { + static char ol[1024] = "-ol"; + (void)strncpy(ol[3], eventlog, sizeof(ol) - 3); + argv[argc++] = "-olsimplex.eventlog"; // produce file relative to "current" directory + argv[argc++] = "-l-agu"; // collect GC and user events + } + if (heap_profile) { + static char po[1024] = "-po"; + (void)strncpy(po[3], heap_profile, sizeof(po) - 3); + argv[argc++] = po; // produce .hp relative to "current" directory + argv[argc++] = "-hT"; // emit heap profile by closure type + } + int non_moving_gc = !heap_profile; // not compatible with heap profile + if (non_moving_gc) argv[argc++] = "-xn"; + // wrap args as expected by RTS char **pargv = argv; hs_init_with_rtsopts(&argc, &pargv); } diff --git a/apps/ios/SimpleXChat/hs_init.h b/apps/ios/SimpleXChat/hs_init.h index a732fd7113..7c3cfea548 100644 --- a/apps/ios/SimpleXChat/hs_init.h +++ b/apps/ios/SimpleXChat/hs_init.h @@ -9,7 +9,7 @@ #ifndef hs_init_h #define hs_init_h -void haskell_init(void); +void haskell_init(const char *eventlog, const char *heap_profile); void haskell_init_nse(void);