[PATCH] progress: Rate limit drawing in the progress-reporter/bar.

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Christopher Baines
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal

Debbugs page

Christopher Baines wrote 3 years ago
(address . guix-patches@gnu.org)
20210917101556.13071-1-mail@cbaines.net
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(-)

Toggle diff (42 lines)
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
Ludovic Courtès wrote 3 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 50634@debbugs.gnu.org)
87y27d22rd.fsf@gnu.org
Hi Christopher,

Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (6 lines)
> 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.

I hit that problem quite frequently lately in shell-mode so I’m grateful
you fixed it. Go for it!

Thanks,
Ludo’.
Christopher Baines wrote 3 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 50634-done@debbugs.gnu.org)
87y24pzw0t.fsf@cbaines.net
Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (13 lines)
> Hi Christopher,
>
> Christopher Baines <mail@cbaines.net> skribis:
>
>> 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.
>
> I hit that problem quite frequently lately in shell-mode so I’m grateful
> you fixed it. Go for it!

I seemingly forgot about this, but I've now pushed this patch as
604880ae22e1a7662acb1d3f282242470de0cd03.

Thanks,

Chris
-----BEGIN PGP SIGNATURE-----

iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmG2FCNfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh
aW5lcy5uZXQACgkQXiijOwuE9Xf17w/+PFsIASDI8qcqaBkU0+nkDK6RmWhJAr4C
dyiCaujjv8fJVqaNjW7NMcp8DkHA95ccM0TGKfg7kR88F7ApZ1AOMLGThFns++kO
b97PAsfpI2Tp25lb9mKcjHKUWpKSw402KVOngOzPHs/8y2ue95KcJVVoKsFsYGHO
zaAKEsTzLIFDElNnzovFL0rxE3lN33chEVxZMb8EytdA6mF88f9+fEtbYBNGubbb
FJHMsrco8YCy84CHXi1/Jl3Vi3U8cVeMYjxN8bUOp8BJDO6AR6jvdQcAeqvx9lrm
iZWTKEMwa4+zDAZQJXDfjAx3CpyRK7zFiGBXFQXxQzj0a4DH4+B+WGacb5MBSYtu
JnyG+j5fkvrXcN1RdcpHP/l20do08+Cln/nzmzXq1OVc5EvIZ3gsqjhLFMEmP7Uj
GqJQ6oBtvE4+55dEpOSD1jBvg7gRv+N7MO7wbZi8sPUZiWKO+RGdvKnXFXy8eORj
OiosStu3y8iQ7Z15qz+f0+nu5Q1nOLdksmsay3/uemUZ1dpchSWxCtTPrqvJfkNx
2h7ep6NQusJBZRBeyTcVmO2ZWAlsLrcjEhwz24nLvPLRxMDAp5mPk/NdAU4IRzRX
8LbIbTtMNdsEBOaocKs7CHD+HxSrRB4onxNIy07VifG91vq5H+5ym3KqNdAD1p8B
vxauUTJ4QyY=
=AKmX
-----END PGP SIGNATURE-----

Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 50634@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 50634
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help