From: "Ludovic Courtès" <ludo@gnu.org>
To: 48806@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#48806] [PATCH 2/7] store: Generalize cache lookup recording.
Date: Thu, 3 Jun 2021 09:33:56 +0200 [thread overview]
Message-ID: <20210603073401.13629-2-ludo@gnu.org> (raw)
In-Reply-To: <20210603073401.13629-1-ludo@gnu.org>
* guix/store.scm (cache-lookup-recorder): New procedure.
(record-cache-lookup!): Define in terms of it.
---
guix/store.scm | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/guix/store.scm b/guix/store.scm
index 897062efff..38d12ac5d7 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -69,6 +69,7 @@
nix-server-socket
current-store-protocol-version ;for internal use
+ cache-lookup-recorder ;for internal use
mcached
&store-error store-error?
@@ -1898,21 +1899,24 @@ and RESULT is typically its derivation."
(vhash-cons object (cons result keys)
(store-connection-cache store cache))))))
-(define record-cache-lookup!
- (if (profiled? "object-cache")
+(define (cache-lookup-recorder component title)
+ "Return a procedure of two arguments to record cache lookups, hits, and
+misses for COMPONENT. The procedure must be passed a Boolean indicating
+whether the cache lookup was a hit, and the actual cache (a vhash)."
+ (if (profiled? component)
(let ((fresh 0)
(lookups 0)
(hits 0)
(size 0))
(register-profiling-hook!
- "object-cache"
+ component
(lambda ()
- (format (current-error-port) "Store object cache:
+ (format (current-error-port) "~a:
fresh caches: ~5@a
lookups: ~5@a
hits: ~5@a (~,1f%)
cache size: ~5@a entries~%"
- fresh lookups hits
+ title fresh lookups hits
(if (zero? lookups)
100.
(* 100. (/ hits lookups)))
@@ -1920,9 +1924,9 @@ and RESULT is typically its derivation."
(lambda (hit? cache)
(set! fresh
- (if (eq? cache vlist-null)
- (+ 1 fresh)
- fresh))
+ (if (eq? cache vlist-null)
+ (+ 1 fresh)
+ fresh))
(set! lookups (+ 1 lookups))
(set! hits (if hit? (+ hits 1) hits))
(set! size (+ (if hit? 0 1)
@@ -1930,6 +1934,9 @@ and RESULT is typically its derivation."
(lambda (x y)
#t)))
+(define record-cache-lookup!
+ (cache-lookup-recorder "object-cache" "Store object cache"))
+
(define-inlinable (lookup-cached-object object keys vhash-fold*)
"Return the cached object in the store connection corresponding to OBJECT
and KEYS; use VHASH-FOLD* to look for OBJECT in the cache. KEYS is a list of
--
2.31.1
next prev parent reply other threads:[~2021-06-03 7:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-03 7:29 [bug#48806] [PATCH 0/7] Generalized cache support and improved graft caching Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 1/7] store: Support dynamic allocation of per-connection caches Ludovic Courtès
2021-06-03 7:33 ` Ludovic Courtès [this message]
2021-06-03 7:33 ` [bug#48806] [PATCH 3/7] grafts: Record cache lookups for profiling Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 4/7] grafts: Use SRFI-71 instead of SRFI-11 Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 5/7] store: Remove 'references/substitutes' Ludovic Courtès
2021-06-03 7:34 ` [bug#48806] [PATCH 6/7] store: 'references/cached' now uses a per-session cache Ludovic Courtès
2021-06-03 7:34 ` [bug#48806] [PATCH 7/7] grafts: Cache the derivation/graft mapping for the whole session Ludovic Courtès
2021-06-03 11:59 ` [bug#48806] [PATCH 0/7] Generalized cache support and improved graft caching Lars-Dominik Braun
2021-06-03 20:39 ` Ludovic Courtès
2021-06-08 7:34 ` bug#48806: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210603073401.13629-2-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=48806@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).