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:
parent
90cec0d8ac
commit
4210699949
1 changed files with 24 additions and 21 deletions
|
|
@ -231,31 +231,34 @@
|
|||
|
||||
(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
|
||||
(let loop ((last-gc-times
|
||||
(or (assq-ref (gc-stats) 'times) 0))
|
||||
(last-gc-time-taken
|
||||
(assq-ref (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)
|
||||
(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))))
|
||||
internal-time-units-per-second))
|
||||
(gcs
|
||||
(- gc-times
|
||||
last-gc-times)))
|
||||
(format (current-error-port)
|
||||
"~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))))
|
||||
(sleep 5)
|
||||
(loop gc-times
|
||||
gc-time-taken)))))
|
||||
|
||||
;; Provide some visual space between the startup output and the
|
||||
;; server starting
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue