Skip to content

docker stats: assorted fixes and optimizations in rendering#6876

Open
thaJeztah wants to merge 4 commits intodocker:masterfrom
thaJeztah:stats_optimize
Open

docker stats: assorted fixes and optimizations in rendering#6876
thaJeztah wants to merge 4 commits intodocker:masterfrom
thaJeztah:stats_optimize

Conversation

@thaJeztah
Copy link
Member

cli/command/container: stats: add snapshot method

Move logic to capture a snapshot of the current stats to the stats struct.

cli/command/container: RunStats: rename buffer var for brevity

cli/command/container: RunStats: avoid bytes to strings conversions

This code is using a bytes.Buffer to render the stats, before writing
the results to the CLI's output. Let's try to use bytes where possible
instead of converting to a string;

  • Use the buffer's Write (and Out().Write) to write directly to the
    buffer/writer where possible.
  • Use io.WriteString instead of fmt.Printf
  • Use bytes.SplitSeq instead of strings.SplitSeq

cli/command/container: statsFormatWrite: inline render func

- Human readable description for the release notes

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

Move logic to capture a snapshot of the current stats to the stats struct.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This code is using a `bytes.Buffer` to render the stats, before writing
the results to the CLI's output. Let's try to use bytes where possible
instead of converting to a string;

- Use the buffer's `Write` (and `Out().Write`) to write directly to the
  buffer/writer where possible.
- Use `io.WriteString` instead of `fmt.Printf`
- Use `bytes.SplitSeq` instead of `strings.SplitSeq`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 29.3.1 milestone Mar 20, 2026
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Mar 20, 2026
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 26.31579% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/container/stats.go 0.00% 20 Missing ⚠️
cli/command/container/stats_helpers.go 0.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants