From patchwork Fri Sep 17 10:15:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 33091 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 88D1127BBE3; Fri, 17 Sep 2021 11:16:16 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 50A9C27BBE1 for ; Fri, 17 Sep 2021 11:16:16 +0100 (BST) Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRAul-0004HK-Bl for patchwork@mira.cbaines.net; Fri, 17 Sep 2021 06:16:15 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 ()