This commit is contained in:
Łukasz Magiera 2020-05-01 21:51:31 +02:00
parent 4014cbdb44
commit 35b1963eeb
4 changed files with 21 additions and 23 deletions

View File

@ -142,9 +142,9 @@ var infoCmd = &cli.Command{
}, },
} }
type stateMeta struct{ type stateMeta struct {
i int i int
col color.Attribute col color.Attribute
state sealing.SectorState state sealing.SectorState
} }
@ -178,8 +178,8 @@ var stateList = []stateMeta{
func init() { func init() {
for i, state := range stateList { for i, state := range stateList {
stateOrder[state.state] = stateMeta{ stateOrder[state.state] = stateMeta{
i: i, i: i,
col: state.col, col: state.col,
} }
} }
} }

View File

@ -145,7 +145,7 @@ var storageListCmd = &cli.Command{
type fsInfo struct { type fsInfo struct {
stores.ID stores.ID
sectors []stores.Decl sectors []stores.Decl
stat stores.FsStat stat stores.FsStat
} }
sorted := make([]fsInfo, 0, len(st)) sorted := make([]fsInfo, 0, len(st))
@ -187,7 +187,7 @@ var storageListCmd = &cli.Command{
} }
ping := time.Now().Sub(pingStart) ping := time.Now().Sub(pingStart)
usedPercent := (st.Capacity-st.Available)*100/st.Capacity usedPercent := (st.Capacity - st.Available) * 100 / st.Capacity
percCol := color.FgGreen percCol := color.FgGreen
switch { switch {
@ -198,7 +198,7 @@ var storageListCmd = &cli.Command{
} }
var barCols = uint64(50) var barCols = uint64(50)
set := (st.Capacity-st.Available)*barCols/st.Capacity set := (st.Capacity - st.Available) * barCols / st.Capacity
bar := strings.Repeat("|", int(set)) + strings.Repeat(" ", int(barCols-set)) bar := strings.Repeat("|", int(set)) + strings.Repeat(" ", int(barCols-set))
fmt.Printf("\t[%s] %s/%s %s\n", color.New(percCol).Sprint(bar), fmt.Printf("\t[%s] %s/%s %s\n", color.New(percCol).Sprint(bar),

View File

@ -66,37 +66,36 @@ var workersListCmd = &cli.Command{
gpuUse = "" gpuUse = ""
} }
fmt.Printf("Worker %d, host %s\n", stat.id, color.MagentaString(stat.Info.Hostname)) fmt.Printf("Worker %d, host %s\n", stat.id, color.MagentaString(stat.Info.Hostname))
var barCols = uint64(64) var barCols = uint64(64)
cpuBars := int(stat.CpuUse * barCols / stat.Info.Resources.CPUs) cpuBars := int(stat.CpuUse * barCols / stat.Info.Resources.CPUs)
cpuBar := strings.Repeat("|", cpuBars) + strings.Repeat(" ", int(barCols) - cpuBars) cpuBar := strings.Repeat("|", cpuBars) + strings.Repeat(" ", int(barCols)-cpuBars)
fmt.Printf("\tCPU: [%s] %d core(s) in use\n", color.GreenString(cpuBar), stat.CpuUse) fmt.Printf("\tCPU: [%s] %d core(s) in use\n", color.GreenString(cpuBar), stat.CpuUse)
ramBarsRes := int(stat.Info.Resources.MemReserved*barCols/stat.Info.Resources.MemPhysical) ramBarsRes := int(stat.Info.Resources.MemReserved * barCols / stat.Info.Resources.MemPhysical)
ramBarsUsed := int(stat.MemUsedMin*barCols/stat.Info.Resources.MemPhysical) ramBarsUsed := int(stat.MemUsedMin * barCols / stat.Info.Resources.MemPhysical)
ramBar := color.YellowString(strings.Repeat("|", ramBarsRes)) + ramBar := color.YellowString(strings.Repeat("|", ramBarsRes)) +
color.GreenString(strings.Repeat("|", ramBarsUsed)) + color.GreenString(strings.Repeat("|", ramBarsUsed)) +
strings.Repeat(" ", int(barCols) - ramBarsUsed - ramBarsRes) strings.Repeat(" ", int(barCols)-ramBarsUsed-ramBarsRes)
vmem := stat.Info.Resources.MemPhysical+stat.Info.Resources.MemSwap vmem := stat.Info.Resources.MemPhysical + stat.Info.Resources.MemSwap
vmemBarsRes := int(stat.Info.Resources.MemReserved*barCols/vmem) vmemBarsRes := int(stat.Info.Resources.MemReserved * barCols / vmem)
vmemBarsUsed := int(stat.MemUsedMax*barCols/vmem) vmemBarsUsed := int(stat.MemUsedMax * barCols / vmem)
vmemBar := color.YellowString(strings.Repeat("|", vmemBarsRes)) + vmemBar := color.YellowString(strings.Repeat("|", vmemBarsRes)) +
color.GreenString(strings.Repeat("|", vmemBarsUsed)) + color.GreenString(strings.Repeat("|", vmemBarsUsed)) +
strings.Repeat(" ", int(barCols) - vmemBarsUsed - vmemBarsRes) strings.Repeat(" ", int(barCols)-vmemBarsUsed-vmemBarsRes)
fmt.Printf("\tRAM: [%s] %d%% %s/%s\n", ramBar, fmt.Printf("\tRAM: [%s] %d%% %s/%s\n", ramBar,
(stat.Info.Resources.MemReserved + stat.MemUsedMin)*100/stat.Info.Resources.MemPhysical, (stat.Info.Resources.MemReserved+stat.MemUsedMin)*100/stat.Info.Resources.MemPhysical,
types.SizeStr(types.NewInt(stat.Info.Resources.MemReserved + stat.MemUsedMin)), types.SizeStr(types.NewInt(stat.Info.Resources.MemReserved+stat.MemUsedMin)),
types.SizeStr(types.NewInt(stat.Info.Resources.MemPhysical))) types.SizeStr(types.NewInt(stat.Info.Resources.MemPhysical)))
fmt.Printf("\tVMEM: [%s] %d%% %s/%s\n", vmemBar, fmt.Printf("\tVMEM: [%s] %d%% %s/%s\n", vmemBar,
(stat.Info.Resources.MemReserved + stat.MemUsedMax)*100/vmem, (stat.Info.Resources.MemReserved+stat.MemUsedMax)*100/vmem,
types.SizeStr(types.NewInt(stat.Info.Resources.MemReserved + stat.MemUsedMax)), types.SizeStr(types.NewInt(stat.Info.Resources.MemReserved+stat.MemUsedMax)),
types.SizeStr(types.NewInt(vmem))) types.SizeStr(types.NewInt(vmem)))
for _, gpu := range stat.Info.Resources.GPUs { for _, gpu := range stat.Info.Resources.GPUs {

View File

@ -275,7 +275,7 @@ func TestUnmarshalableResult(t *testing.T) {
} }
type ChanHandler struct { type ChanHandler struct {
wait chan struct{} wait chan struct{}
ctxdone <-chan struct{} ctxdone <-chan struct{}
} }
@ -436,7 +436,6 @@ func TestChanServerClose(t *testing.T) {
require.Equal(t, false, ok) require.Equal(t, false, ok)
} }
func TestServerChanLockClose(t *testing.T) { func TestServerChanLockClose(t *testing.T) {
var client struct { var client struct {
Sub func(context.Context, int, int) (<-chan int, error) Sub func(context.Context, int, int) (<-chan int, error)