From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65700: time when gcs-done is updated needs to be clarified Date: Thu, 07 Sep 2023 09:38:35 -0400 Message-ID: References: <83pm2uz6nv.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20773"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Shynur Xie , 65700@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 07 15:39:17 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qeFE4-0005Av-FG for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Sep 2023 15:39:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeFDs-0003jN-83; Thu, 07 Sep 2023 09:39:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeFDp-0003hN-VK for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 09:39:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeFDp-0004DN-Mn for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 09:39:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeFDr-0007Gs-Ay for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 09:39:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Sep 2023 13:39:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65700 X-GNU-PR-Package: emacs Original-Received: via spool by 65700-submit@debbugs.gnu.org id=B65700.169409393127905 (code B ref 65700); Thu, 07 Sep 2023 13:39:03 +0000 Original-Received: (at 65700) by debbugs.gnu.org; 7 Sep 2023 13:38:51 +0000 Original-Received: from localhost ([127.0.0.1]:38894 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeFDe-0007G1-La for submit@debbugs.gnu.org; Thu, 07 Sep 2023 09:38:50 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:56096) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeFDZ-0007Fg-6a for 65700@debbugs.gnu.org; Thu, 07 Sep 2023 09:38:48 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 73FB910006B; Thu, 7 Sep 2023 09:38:37 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1694093916; bh=xVIjIHvDsjomD3TTEGM3/Lgne3vhoQXJ9mVjudAu7IM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=ObAL0S5pv5Uxmnvt9svj+nByGIVmLIxmLtHga2rWGVG/NnYLwKMFRb1ONpg64tYiN FDmzxPmI9B22lKdcJqnoXkQ6ru6Oj1dayLc2VU26687xPx6KlG/DQksCDZa9aHB8y6 kBhymOUDrOt3wBZ9xJRtMI1E+rUXZ48VoQ8SmOtYNi5UojFkQ8dCKEJ0pp4nU4iWF4 xCovNIaaEctcLyyzFYlak+Gmk5VI7M3BsVT8eib/4EEZ5QtM5iN/3eNrHjW0+R40jU z0x3MOH+N1hgvo+aPiNeWTqssLcBO8Zh8EXnfibRJh5r97kHtVcBo5M1Ex/foLnjRh Pv+08THe7EIsA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 768C0100046; Thu, 7 Sep 2023 09:38:36 -0400 (EDT) Original-Received: from pastel (69-165-136-223.dsl.teksavvy.com [69.165.136.223]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2D3C212030B; Thu, 7 Sep 2023 09:38:36 -0400 (EDT) In-Reply-To: <83pm2uz6nv.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 07 Sep 2023 12:14:44 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269655 Archived-At: >> I wrote a function which runs each time Emacs collects garbage, so I >> added it to `post-gc-hook'. >> >> That function cares about the value of `gcs-done' and the value of >> `gc-elapsed'. But it seems that `gcs-done' is updated after >> `post-gc-hook' is executed? Indeed, from what I see in the code, `gc-elapsed` and `gcs-done` are updated *after* running `post-gc-hook`. This means for example that the time to run `post-gc-hook` is included in the `gc-elapsed` time. >> Is this an intended behavior? Good question. AFAICT this was added by the following commit: commit 2c5bd60800ce4f2702f263eda2145be342208ffe Author: Dave Love Date: Thu Jan 30 14:15:58 2003 +0000 (Vgc_elapsed, gcs_done): New variables. (Fgarbage_collect): Use them. (init_alloc, syms_of_alloc): Set them up. diff --git a/src/alloc.c b/src/alloc.c --- a/src/alloc.c +++ b/src/alloc.c @@ -4367,7 +4373,15 @@ if (!NILP (Vpost_gc_hook)) { int count = inhibit_garbage_collection (); safe_run_hooks (Qpost_gc_hook); unbind_to (count, Qnil); } - + + /* Accumulate statistics. */ + EMACS_GET_TIME (t2); + EMACS_SUB_TIME (t3, t2, t1); + if (FLOATP (Vgc_elapsed)) + XSETFLOAT (Vgc_elapsed, make_float (XFLOAT_DATA (Vgc_elapsed) + + EMACS_SECS (t3) + + EMACS_USECS (t3) * 1.0e-6)); + gcs_done++; The only related commit I see around that time is the associated NEWS message: ** New variables `gc-elapsed' and `gcs-done' provide extra information on garbage collection. So I strongly suspect that it was largely accidental. "Philosophically", both choices make sense (either consider `post-gc-hook` as being part of the GC or consider it as external to the GC). I'd be curious to know how it affects your code. Stefan