cs: fix GC:major logging on exit

Also, add `PLT_GCS_ON_EXIT` to force 2 major GCs on exit, which
is useful for checking peak and end memory use.
This commit is contained in:
Matthew Flatt 2020-02-15 09:11:44 -08:00
parent e63433c4fd
commit cdd0659438
2 changed files with 23 additions and 5 deletions

View File

@ -676,17 +676,24 @@
(let ([orig (exit-handler)]
[root-logger (current-logger)])
(lambda (v)
(when (log-level? root-logger 'info 'GC)
(log-message root-logger 'info 'GC
(chez:format "0:atexit peak ~a; alloc ~a; major ~a; minor ~a; ~ams"
(when gcs-on-exit?
(collect-garbage)
(collect-garbage))
(let ([debug-GC? (log-level?* root-logger 'debug 'GC)]
[debug-GC:major? (log-level?* root-logger 'debug 'GC:major)])
(when (or debug-GC? debug-GC:major?)
(let ([msg (chez:format "GC: 0:atexit peak ~a; alloc ~a; major ~a; minor ~a; ~ams"
(K "" peak-mem)
(K "" (- (+ (bytes-deallocated) (bytes-allocated)) (initial-bytes-allocated)))
major-gcs
minor-gcs
(let ([t (sstats-gc-cpu (statistics))])
(+ (* (time-second t) 1000)
(quotient (time-nanosecond t) 1000000))))
#f))
(quotient (time-nanosecond t) 1000000))))])
(when debug-GC?
(log-message root-logger 'info 'GC msg #f #f))
(when debug-GC:major?
(log-message root-logger 'info 'GC:major msg #f #f)))))
(linklet-performance-report!)
(|#%app| orig v)))))
@ -711,6 +718,8 @@
(parse-logging-spec "syslog" spec "in PLTSYSLOG environment variable" #f)
'()))))
(define gcs-on-exit? (and (getenv "PLT_GCS_ON_EXIT")))
(define (initialize-place!)
(current-command-line-arguments remaining-command-line-arguments)
(use-compiled-file-paths compiled-file-paths)

View File

@ -147,6 +147,7 @@ ROSYM Scheme_Object *scheme_break_enabled_key;
THREAD_LOCAL_DECL(static Scheme_Object *configuration_callback_cache[2]);
static int gcs_on_exit;
THREAD_LOCAL_DECL(intptr_t scheme_total_gc_time);
THREAD_LOCAL_DECL(static intptr_t start_this_gc_time);
THREAD_LOCAL_DECL(static intptr_t end_this_gc_time);
@ -617,6 +618,9 @@ void scheme_init_thread(Scheme_Startup_Env *env)
ADD_PRIM_W_ARITY("phantom-bytes?", phantom_bytes_p, 1, 1, env);
ADD_PRIM_W_ARITY("make-phantom-bytes", make_phantom_bytes, 1, 1, env);
ADD_PRIM_W_ARITY("set-phantom-bytes!", set_phantom_bytes, 2, 2, env);
if (scheme_getenv("PLT_GCS_ON_EXIT"))
gcs_on_exit = 1;
}
void
@ -1954,6 +1958,11 @@ void scheme_run_atexit_closers_on_all(Scheme_Exit_Closer_Func alt)
will have terminated everything else anyway. For a
polite exit, other threads can run. */
if (gcs_on_exit) {
scheme_collect_garbage();
scheme_collect_garbage();
}
log_peak_memory_use();
savebuf = scheme_current_thread->error_buf;