grafts: Record cache lookups for profiling.
authorLudovic Courtès <ludo@gnu.org>
Fri, 28 May 2021 15:45:38 +0000 (17:45 +0200)
committerLudovic Courtès <ludo@gnu.org>
Tue, 8 Jun 2021 07:25:49 +0000 (09:25 +0200)
* guix/grafts.scm (record-cache-lookup!): New procedure.
(with-cache): Use it.

guix/grafts.scm

index fd8a108..dff3d75 100644 (file)
@@ -172,10 +172,16 @@ references."
                  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