diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index d85891a5f3..b2e59d5b4b 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "io" - "strings" "sync" "time" @@ -202,10 +201,13 @@ func calculateCPUPercentWindows(v *types.StatsJSON) float64 { func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) { var blkRead, blkWrite uint64 for _, bioEntry := range blkio.IoServiceBytesRecursive { - switch strings.ToLower(bioEntry.Op) { - case "read": + if len(bioEntry.Op) == 0 { + continue + } + switch bioEntry.Op[0] { + case 'r', 'R': blkRead = blkRead + bioEntry.Value - case "write": + case 'w', 'W': blkWrite = blkWrite + bioEntry.Value } } diff --git a/cli/command/container/stats_unit_test.go b/cli/command/container/stats_unit_test.go index 21e650e285..9aac0ab939 100644 --- a/cli/command/container/stats_unit_test.go +++ b/cli/command/container/stats_unit_test.go @@ -11,15 +11,20 @@ func TestCalculateBlockIO(t *testing.T) { IoServiceBytesRecursive: []types.BlkioStatEntry{ {Major: 8, Minor: 0, Op: "read", Value: 1234}, {Major: 8, Minor: 1, Op: "read", Value: 4567}, + {Major: 8, Minor: 0, Op: "Read", Value: 6}, + {Major: 8, Minor: 1, Op: "Read", Value: 8}, {Major: 8, Minor: 0, Op: "write", Value: 123}, {Major: 8, Minor: 1, Op: "write", Value: 456}, + {Major: 8, Minor: 0, Op: "Write", Value: 6}, + {Major: 8, Minor: 1, Op: "Write", Value: 8}, + {Major: 8, Minor: 1, Op: "", Value: 456}, }, } blkRead, blkWrite := calculateBlockIO(blkio) - if blkRead != 5801 { - t.Fatalf("blkRead = %d, want 5801", blkRead) + if blkRead != 5815 { + t.Fatalf("blkRead = %d, want 5815", blkRead) } - if blkWrite != 579 { - t.Fatalf("blkWrite = %d, want 579", blkWrite) + if blkWrite != 593 { + t.Fatalf("blkWrite = %d, want 593", blkWrite) } }