mirror of https://github.com/docker/cli.git
Merge pull request #1688 from luoyunpeng/optimize-blockIOTypecheck
use char to check blockIO type
This commit is contained in:
commit
bf4a96e564
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue