From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WGnHMDCGuGAsVwAAgWs5BA (envelope-from ) for ; Thu, 03 Jun 2021 09:35:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CKDlKzCGuGAGLgAAbx9fmQ (envelope-from ) for ; Thu, 03 Jun 2021 07:35:12 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 758E61D477 for ; Thu, 3 Jun 2021 09:35:12 +0200 (CEST) Received: from localhost ([::1]:46494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lohsl-0004hU-IY for larch@yhetil.org; Thu, 03 Jun 2021 03:35:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lohsd-0004e8-6e for guix-patches@gnu.org; Thu, 03 Jun 2021 03:35:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lohsc-0001tW-TL for guix-patches@gnu.org; Thu, 03 Jun 2021 03:35:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lohsc-0001Wc-RK for guix-patches@gnu.org; Thu, 03 Jun 2021 03:35:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48806] [PATCH 2/7] store: Generalize cache lookup recording. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 03 Jun 2021 07:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48806 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48806@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 48806-submit@debbugs.gnu.org id=B48806.16227056855774 (code B ref 48806); Thu, 03 Jun 2021 07:35:02 +0000 Received: (at 48806) by debbugs.gnu.org; 3 Jun 2021 07:34:45 +0000 Received: from localhost ([127.0.0.1]:42009 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lohsL-0001V3-4W for submit@debbugs.gnu.org; Thu, 03 Jun 2021 03:34:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36898) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lohsJ-0001UP-9K for 48806@debbugs.gnu.org; Thu, 03 Jun 2021 03:34:43 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:60210) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lohsE-0001WN-2m; Thu, 03 Jun 2021 03:34:38 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=57488 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lohsD-0005sA-Mz; Thu, 03 Jun 2021 03:34:37 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 3 Jun 2021 09:33:56 +0200 Message-Id: <20210603073401.13629-2-ludo@gnu.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603073401.13629-1-ludo@gnu.org> References: <20210603073401.13629-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1622705712; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=i3MwqeDg6X0BivVLReNGhPbNowFFGnkeoWDyg1+P3n0=; b=geDkefYpwPw6igQ25oSqAsCsP9D+kTOnDC4GCJCqmB4lARzLu6C258UrfRsKJ8YnUt+epA Q81VKHLNKNmf6C1p5Zl6hTjeyRD5Xc865Fcm5YRYoRm2lBnMif/lajLbkzm1ILLknPbVnE B8UTpRPioxXPS2QPAFwtVZp+JesVeVqWx2zOEgks1nt/QTsmTUbiX3h36Xio10hNUtK0To abhadNW1i3eqGtWPZc98a8AZ+R19hFVfJsjc1sjly8KZqkuLbNYY0EaIkSKWvvxGUeJcWi DhMZJurVXRgBZCkgmZlL1valedrTuc95xOrsItrgPAOA8wH3irSsT6FNn571xw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1622705712; a=rsa-sha256; cv=none; b=NqL8p/rZ20YNrufNDfhUXLRm+X4y2xXXh0pA4qwGE39tVdnw+jSMaMfA0T9Ze4MzPX/4tt X/SvsSZkUfEQmLakpcXwXVT/cq3S0MaTo0wWCd8jGVVltIkFX80eJg4kTfSD5S1S3Ek/+a yj8xLAS4buujNIAdEcjcvAmmRS4qOqdpckSJZUnMobD2YTJFyBA87GMkvLmg3/fGWkKvxs 9jy11ny76U8Q6rdCZhNxumIq2fxYbJndJcZ5UwsWnRM2M8N74UUkEgkE6vW6kYlROYOKrH 0rNL8Ap+CgJncgXZ2eEmqlS/BBEygYA8vSiESJMH9YmlKe0hGPjEBP6VUxOUzQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 2.07 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 758E61D477 X-Spam-Score: 2.07 X-Migadu-Scanner: scn0.migadu.com X-TUID: OnM5eJISwOaI * 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