mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
unify init_haskell to allow nse profiling
This commit is contained in:
@@ -23,11 +23,7 @@ struct SimpleXApp: App {
|
||||
init() {
|
||||
DispatchQueue.global(qos: .background).sync {
|
||||
// we have to use debug profile file name without extension here because .hp extension is added by profiler
|
||||
haskell_init(
|
||||
getAppEventLogPath().path,
|
||||
getAppDebugProfilePrefixPath().path
|
||||
)
|
||||
// hs_init(0, nil)
|
||||
haskell_init(0, getAppEventLogPath().path, nil)
|
||||
}
|
||||
UserDefaults.standard.register(defaults: appDefaults)
|
||||
setGroupDefaults()
|
||||
|
||||
@@ -396,7 +396,7 @@ func startChat() -> DBMigrationResult? {
|
||||
|
||||
startLock.wait()
|
||||
defer { startLock.signal() }
|
||||
|
||||
|
||||
if hasChatCtrl() {
|
||||
return switch NSEChatState.shared.value {
|
||||
case .created: doStartChat()
|
||||
@@ -415,7 +415,7 @@ func startChat() -> DBMigrationResult? {
|
||||
|
||||
func doStartChat() -> DBMigrationResult? {
|
||||
logger.debug("NotificationService: doStartChat")
|
||||
haskell_init_nse()
|
||||
haskell_init(1, nil, getAppDebugProfilePrefixPath().path)
|
||||
let (_, dbStatus) = chatMigrateInit(confirmMigrations: defaultMigrationConfirmation(), backgroundMode: true)
|
||||
logger.debug("NotificationService: doStartChat \(String(describing: dbStatus))")
|
||||
if dbStatus != .ok {
|
||||
|
||||
@@ -11,16 +11,29 @@
|
||||
|
||||
extern void hs_init_with_rtsopts(int * argc, char **argv[]);
|
||||
|
||||
void haskell_init(const char *eventlog, const char *heap_profile) {
|
||||
void haskell_init(int nse, 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
|
||||
if (nse) {
|
||||
argv[argc++] = "simplex-nse"; // fake program name
|
||||
} else {
|
||||
argv[argc++] = "simplex";
|
||||
}
|
||||
argv[argc++] = "+RTS"; // start adding RTS options
|
||||
argv[argc++] = "-T"; // make GC counters available from inside the program
|
||||
argv[argc++] = "-A64m"; // chunk size for new allocations (less frequent GC)
|
||||
argv[argc++] = "-H64m"; // larger heap size on start (faster boot)
|
||||
if (nse) {
|
||||
argv[argc++] = "-S"; // spam stdout with GC stats
|
||||
argv[argc++] = "-A1m"; // chunk size for new allocations (less frequent GC)
|
||||
argv[argc++] = "-H2m"; // larger heap size on start (faster boot)
|
||||
argv[argc++] = "-M12m"; // hard limit on heap
|
||||
argv[argc++] = "-F0.5"; // heap growth triggering GC
|
||||
argv[argc++] = "-Fd1"; // memory return
|
||||
} else {
|
||||
argv[argc++] = "-T"; // make GC counters available from inside the program
|
||||
argv[argc++] = "-A64m"; // 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";
|
||||
@@ -34,8 +47,12 @@ void haskell_init(const char *eventlog, const char *heap_profile) {
|
||||
argv[argc++] = po; // adds ".hp" extension
|
||||
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";
|
||||
if (nse) {
|
||||
argv[argc++] = "-c"; // compacting garbage collector
|
||||
} else {
|
||||
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);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef hs_init_h
|
||||
#define hs_init_h
|
||||
|
||||
void haskell_init(const char *eventlog, const char *heap_profile);
|
||||
void haskell_init(int nse, const char *eventlog, const char *heap_profile);
|
||||
|
||||
void haskell_init_nse(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user