Don't use the after-gc-hook for monitoring garbage collection

This seems to be happening not in the thread I expect, so avoid using the
hook.
This commit is contained in:
Christopher Baines 2025-06-29 23:22:31 +02:00
parent 90cec0d8ac
commit 4210699949

View file

@ -231,31 +231,34 @@
(set-thread-name "gc watcher")
(add-hook!
after-gc-hook
(let ((last-gc-time-taken
(let loop ((last-gc-times
(or (assq-ref (gc-stats) 'times) 0))
(last-gc-time-taken
(assq-ref (gc-stats) 'gc-time-taken)))
(lambda ()
(let* ((stats
(gc-stats))
(gc-time-taken
(let* ((stats (gc-stats))
(gc-times (or (assq-ref stats 'gc-times) 0))
(gc-time-taken (assq-ref stats 'gc-time-taken)))
(when (> gc-times last-gc-times)
(let ((gc-time-taken
(assq-ref stats 'gc-time-taken))
(time-since-last
(/ (- gc-time-taken
last-gc-time-taken)
internal-time-units-per-second)))
(when (> time-since-last 0.1)
internal-time-units-per-second))
(gcs
(- gc-times
last-gc-times)))
(format (current-error-port)
"after gc (additional time taken: ~f, times: ~d, heap-allocated-since-gc: ~d, heap size: ~d, heap free: ~d)\n"
time-since-last
(assq-ref stats 'gc-times)
"~d gc's (time taken: ~f, heap-allocated-since-gc: ~d, heap size: ~d, heap free: ~d)\n"
gcs
(/ time-since-last
gcs)
(assq-ref stats 'heap-allocated-since-gc)
(assq-ref stats 'heap-size)
(assq-ref stats 'heap-free-size)))
(set! last-gc-time-taken
(assq-ref (gc-stats) 'gc-time-taken))))))
(while #t
(usleep 100000))))
(assq-ref stats 'heap-free-size))))
(sleep 5)
(loop gc-times
gc-time-taken)))))
;; Provide some visual space between the startup output and the
;; server starting