[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
C
C
Christopher Baines wrote on 17 Sep 2021 12:15
(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
L
L
Ludovic Courtès wrote on 30 Sep 2021 23:05
(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’.
C
C
Christopher Baines wrote on 12 Dec 2021 16:23
(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
?