From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id oCzkMPFqRGE01gAAgWs5BA (envelope-from ) for ; Fri, 17 Sep 2021 12:16:17 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id WLOpLPFqRGGidAAA1q6Kng (envelope-from ) for ; Fri, 17 Sep 2021 10:16:17 +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 E618713582 for ; Fri, 17 Sep 2021 12:16:16 +0200 (CEST) Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRAul-0004HK-Vy for larch@yhetil.org; Fri, 17 Sep 2021 06:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRAuY-0004Gu-JH for guix-patches@gnu.org; Fri, 17 Sep 2021 06:16:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRAuY-0002sG-Bi for guix-patches@gnu.org; Fri, 17 Sep 2021 06:16:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mRAuY-0004fN-79 for guix-patches@gnu.org; Fri, 17 Sep 2021 06:16:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50634] [PATCH] progress: Rate limit drawing in the progress-reporter/bar. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 17 Sep 2021 10:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50634 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50634@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163187376117926 (code B ref -1); Fri, 17 Sep 2021 10:16:02 +0000 Received: (at submit) by debbugs.gnu.org; 17 Sep 2021 10:16:01 +0000 Received: from localhost ([127.0.0.1]:58570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRAuX-0004f4-5I for submit@debbugs.gnu.org; Fri, 17 Sep 2021 06:16:01 -0400 Received: from lists.gnu.org ([209.51.188.17]:35180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRAuW-0004ew-9T for submit@debbugs.gnu.org; Fri, 17 Sep 2021 06:16:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRAuW-0004Gl-3j for guix-patches@gnu.org; Fri, 17 Sep 2021 06:16:00 -0400 Received: from mira.cbaines.net ([2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27]:36301) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRAuU-0002p0-8L for guix-patches@gnu.org; Fri, 17 Sep 2021 06:15:59 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id B9EF327BBE1 for ; Fri, 17 Sep 2021 11:15:56 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id a8a3a10f for ; Fri, 17 Sep 2021 10:15:56 +0000 (UTC) From: Christopher Baines Date: Fri, 17 Sep 2021 11:15:56 +0100 Message-Id: <20210917101556.13071-1-mail@cbaines.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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=1631873777; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wqSUMZFHuIeauRtipw5n8N0jK+KJG/80+cDidIQNgvs=; b=GRgF3AVuMcwg73cngR1S0SPnPLXcjjd6Z009lDLqBrFrt0eoh9VDtUv7I7a2RMLcQaalaH TRHPxfxwwxnmlh4SxfpEEryAXqvT8aHJOlmr6ETepGE58H1XFMiKPccanSo7/+HnXKXyKh jLywArzYHXExVDT+XixdAjFsmfJ1DT4aU0FMp2wZdGCJudjJ78R4Dajfb96ZkGiESnQ3wG JkCc/kvTMFBjEH5j3BKg+plktREP91um7t6Xcyk9IM6di6GckZ9O8XiuUCDMiw+89Jp95/ lb1iOKUtX84/ha5h/2fAZkfEu9qQwvTqrjLdwkKxfszInxa8sevA1j7UG8L57w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1631873777; a=rsa-sha256; cv=none; b=ZXP+TRyAu4guw9D2JSuzwau4q4ZR4smfeJKxrpT2RcDTCReP0VrdR3/IRF8xSydqmvLrA7 1spVs5Ntx6b7usV1XZw616SHLkMzCA5YeZRo7ynPqiWWJg/9jfskowrUI7WpNxUBwJXbbs THufTePTuoDLKxfA3eDiJdeGzE4A2WQS1+zUywc1xO0tOt1sPM6tHACcgnLefik30E+Ojd nGW4ANS8ThWlwWzYBgw4QwzUFsaj42981E1uSHbdAIc9BS2+81noUAtyFQjlPx0ducLTjO GlwqF+Ddo7p/V99X/fLa5wqWdm4TboT71To/lHRL5sHc3OYHUkQSOphLHh0NNw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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.61 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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: E618713582 X-Spam-Score: 2.61 X-Migadu-Scanner: scn0.migadu.com X-TUID: q3FbMv+v1JX6 This helps smooth the output in cases where the bar is updated very quickly, for example in guix weather where it's computing derivations. * guix/progress.scm (progress-reporter/bar): Wrap the drawing code with the rate-limited procedure. --- guix/progress.scm | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/guix/progress.scm b/guix/progress.scm index 0cbc804ec1..4f8e98edc0 100644 --- a/guix/progress.scm +++ b/guix/progress.scm @@ -270,19 +270,25 @@ ABBREVIATION used to shorten FILE for display." tasks is performed. Write PREFIX at the beginning of the line." (define done 0) + (define (draw-bar) + (let* ((ratio (* 100. (/ done total)))) + (erase-current-line port) + (if (string-null? prefix) + (display (progress-bar ratio (current-terminal-columns)) port) + (let ((width (- (current-terminal-columns) + (string-length prefix) 3))) + (display prefix port) + (display " " port) + (display (progress-bar ratio width) port))) + (force-output port))) + + (define draw-bar/rate-limited + (rate-limited draw-bar %progress-interval)) + (define (report-progress) (set! done (+ 1 done)) (unless (> done total) - (let* ((ratio (* 100. (/ done total)))) - (erase-current-line port) - (if (string-null? prefix) - (display (progress-bar ratio (current-terminal-columns)) port) - (let ((width (- (current-terminal-columns) - (string-length prefix) 3))) - (display prefix port) - (display " " port) - (display (progress-bar ratio width) port))) - (force-output port)))) + (draw-bar/rate-limited))) (progress-reporter (start (lambda () -- 2.33.0