Move the gc watcher to start earlier

This means it doesn't use the fibers sleep, don't know if this makes a
difference.
This commit is contained in:
Christopher Baines 2025-06-29 21:14:33 +02:00
parent ae6d7621d1
commit fc6f78ca9a
2 changed files with 31 additions and 25 deletions

View file

@ -26,12 +26,14 @@
(use-modules (srfi srfi-1)
(srfi srfi-37)
(ice-9 match)
(ice-9 format)
(ice-9 atomic)
(ice-9 threads)
(ice-9 textual-ports)
(system repl server)
(system repl repl)
(gcrypt pk-crypto)
((knots thread-pool) #:select (set-thread-name))
(guix pki)
(guix-data-service utils)
(guix-data-service config)
@ -225,7 +227,35 @@
"poll-startup"
all-git-repositories))
(atomic-box-set! startup-completed #t)))))
(atomic-box-set! startup-completed #t)))
(set-thread-name "gc watcher")
(add-hook!
after-gc-hook
(let ((last-gc-time-taken
(assq-ref (gc-stats) 'gc-time-taken)))
(lambda ()
(let* ((stats
(gc-stats))
(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)
(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)
(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))))
;; Provide some visual space between the startup output and the
;; server starting