Merge pull request #4649 from filecoin-project/feat/sectorslist-utils

miner sectors list: flags for events/seal time
This commit is contained in:
Łukasz Magiera 2020-10-29 19:55:16 +01:00 committed by GitHub
commit 7d02cd6679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"sort" "sort"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/docker/go-units" "github.com/docker/go-units"
@ -155,6 +156,14 @@ var sectorsListCmd = &cli.Command{
Name: "fast", Name: "fast",
Usage: "don't show on-chain info for better performance", Usage: "don't show on-chain info for better performance",
}, },
&cli.BoolFlag{
Name: "events",
Usage: "display number of events the sector has received",
},
&cli.BoolFlag{
Name: "seal-time",
Usage: "display how long it took for the sector to be sealed",
},
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") color.NoColor = !cctx.Bool("color")
@ -216,6 +225,8 @@ var sectorsListCmd = &cli.Command{
tablewriter.Col("OnChain"), tablewriter.Col("OnChain"),
tablewriter.Col("Active"), tablewriter.Col("Active"),
tablewriter.Col("Expiration"), tablewriter.Col("Expiration"),
tablewriter.Col("SealTime"),
tablewriter.Col("Events"),
tablewriter.Col("Deals"), tablewriter.Col("Deals"),
tablewriter.Col("DealWeight"), tablewriter.Col("DealWeight"),
tablewriter.NewLineCol("Error"), tablewriter.NewLineCol("Error"),
@ -286,6 +297,52 @@ var sectorsListCmd = &cli.Command{
} }
} }
if cctx.Bool("events") {
var events int
for _, sectorLog := range st.Log {
if !strings.HasPrefix(sectorLog.Kind, "event") {
continue
}
if sectorLog.Kind == "event;sealing.SectorRestart" {
continue
}
events++
}
pieces := len(st.Deals)
switch {
case events < 12+pieces:
m["Events"] = color.GreenString("%d", events)
case events < 20+pieces:
m["Events"] = color.YellowString("%d", events)
default:
m["Events"] = color.RedString("%d", events)
}
}
if cctx.Bool("seal-time") && len(st.Log) > 1 {
start := time.Unix(int64(st.Log[0].Timestamp), 0)
for _, sectorLog := range st.Log {
if sectorLog.Kind == "event;sealing.SectorProving" {
end := time.Unix(int64(sectorLog.Timestamp), 0)
dur := end.Sub(start)
switch {
case dur < 12*time.Hour:
m["SealTime"] = color.GreenString("%s", dur)
case dur < 24*time.Hour:
m["SealTime"] = color.YellowString("%s", dur)
default:
m["SealTime"] = color.RedString("%s", dur)
}
break
}
}
}
tw.Write(m) tw.Write(m)
} }
} }