Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[27.x backport] Buffer 'docker stats' text to avoid terminal flickering #5588

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

vvoland
Copy link
Collaborator

@vvoland vvoland commented Oct 31, 2024

This change reduces the flickering of the terminal when running docker stats by buffering the formatted stats text and printing it in one write.

Should also consume less CPU as we now only have to issue a single syscall to write the stats text to the terminal.

I suspect it fixes #4348, but I can not confirm since that issue was reported on WSL.

- What I did

On all of my Linux machines (Fedora Linux + GNOME) I can see terminal flickering when running 'docker stats'.

I've tested this with gnome-terminal/xfce4-terminal/xterm and it flickers on all. The only term that does not flicker is kitty.

I've also tested this on GNOME running Wayland and X11. I can see no difference in behaviour between Wayland/X11.

I've tested this on two machines: Thinkpad T14s gen1 running AMD zen, and a desktop PC running AMD zen chip with Radeon GPU. Both behave identically.

recording of the flickering:
https://github.com/user-attachments/assets/05f8278e-05c3-411e-bb32-dad262136937

'docker stats' used to issue multiple write calls to stdout. Starting with the "clear screen" command and following multiple small write requests.
I'm now bundling all of those into a single string that is then written out to the stdout as a single request.

This fixes the flickering (as well as reduces syscalls required for each update) on both of my machines.

I've tested this on Fedora 41 GNOME with the following terminal emulators: gnome-terminal/xfce4-terminal/xterm/kitty.

I've tried things like resizing the window as 'docker stats' was running. It all works flawlessly now :)

- Description for the changelog

`docker stats` output is now buffered to reduce flickering issues 

- A picture of a cute animal (not mandatory but encouraged)

A cat that sometimes roams outside my flat. Me and my flatmates call him Phantom 🐱

cat_phantom

This change reduces the flickering of the terminal when
running `docker stats` by buffering the formatted stats
text and printing it in one write.

Should also consume less CPU as we now only have to issue
a single syscall to write the stats text to the terminal.

Signed-off-by: Giedrius Jonikas <[email protected]>
(cherry picked from commit 0b16070)
Signed-off-by: Paweł Gronowski <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 58.65%. Comparing base (6736be7) to head (470ab05).
Report is 6 commits behind head on 27.x.

Additional details and impacted files
@@            Coverage Diff             @@
##             27.x    #5588      +/-   ##
==========================================
- Coverage   58.66%   58.65%   -0.02%     
==========================================
  Files         345      345              
  Lines       29047    29053       +6     
==========================================
  Hits        17040    17040              
- Misses      11036    11042       +6     
  Partials      971      971              

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit f4f328b into docker:27.x Oct 31, 2024
105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants