grafts: Record cache lookups for profiling.

* guix/grafts.scm (record-cache-lookup!): New procedure.
(with-cache): Use it.
This commit is contained in:
Ludovic Courtès 2021-05-28 17:45:38 +02:00
parent 0a3c723e07
commit 6bd3d4fe06
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -172,10 +172,16 @@ (define (references* items)
items))))
(remove (cut member <> self) refs)))
(define record-cache-lookup!
(cache-lookup-recorder "derivation-graft-cache"
"Derivation graft cache"))
(define-syntax-rule (with-cache key exp ...)
"Cache the value of monadic expression EXP under KEY."
(mlet %state-monad ((cache (current-state)))
(match (vhash-assoc key cache)
(mlet* %state-monad ((cache (current-state))
(result -> (vhash-assoc key cache)))
(record-cache-lookup! result cache)
(match result
((_ . result) ;cache hit
(return result))
(#f ;cache miss