diff --git a/cli/utils.go b/cli/utils.go new file mode 100644 index 000000000..62c29654f --- /dev/null +++ b/cli/utils.go @@ -0,0 +1,19 @@ +package cli + +import ( + "fmt" + + "github.com/filecoin-project/lotus/chain/types" +) + +var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"} + +func SizeStr(size types.BigInt) string { + size = types.BigMul(size, types.NewInt(100)) + i := 0 + for types.BigCmp(size, types.NewInt(102400)) >= 0 && i < len(Units)-1 { + size = types.BigDiv(size, types.NewInt(1024)) + i++ + } + return fmt.Sprintf("%s.%s %s", types.BigDiv(size, types.NewInt(100)), types.BigMod(size, types.NewInt(100)), Units[i]) +} diff --git a/cmd/lotus-bench/main.go b/cmd/lotus-bench/main.go index 11417d0c1..d32cd7fb8 100644 --- a/cmd/lotus-bench/main.go +++ b/cmd/lotus-bench/main.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/chain/types" "io/ioutil" "math/rand" "os" @@ -13,6 +14,7 @@ import ( "time" ffi "github.com/filecoin-project/filecoin-ffi" + lcli "github.com/filecoin-project/lotus/cli" "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log" "github.com/mitchellh/go-homedir" @@ -315,7 +317,7 @@ func main() { } verifypost2 := time.Now() - benchout := BenchResults{ + bo := BenchResults{ SectorSize: cfg.SectorSize, SealingResults: sealTimings, @@ -327,7 +329,7 @@ func main() { } // TODO: optionally write this as json to a file if c.Bool("json-out") { - data, err := json.MarshalIndent(benchout, "", " ") + data, err := json.MarshalIndent(bo, "", " ") if err != nil { return err } @@ -336,17 +338,17 @@ func main() { } else { fmt.Printf("results (%d)\n", sectorSize) if robench == "" { - fmt.Printf("seal: addPiece: %s\n", benchout.SealingResults[0].AddPiece) // TODO: average across multiple sealings - fmt.Printf("seal: preCommit: %s\n", benchout.SealingResults[0].PreCommit) - fmt.Printf("seal: Commit: %s\n", benchout.SealingResults[0].Commit) - fmt.Printf("seal: Verify: %s\n", benchout.SealingResults[0].Verify) - fmt.Printf("unseal: %s\n", benchout.SealingResults[0].Unseal) + fmt.Printf("seal: addPiece: %s (%s)\n", bo.SealingResults[0].AddPiece, bps(bo.SectorSize, bo.SealingResults[0].AddPiece)) // TODO: average across multiple sealings + fmt.Printf("seal: preCommit: %s (%s)\n", bo.SealingResults[0].PreCommit, bps(bo.SectorSize, bo.SealingResults[0].PreCommit)) + fmt.Printf("seal: commit: %s (%s)\n", bo.SealingResults[0].Commit, bps(bo.SectorSize, bo.SealingResults[0].Commit)) + fmt.Printf("seal: verify: %s\n", bo.SealingResults[0].Verify) + fmt.Printf("unseal: %s (%s)\n", bo.SealingResults[0].Unseal, bps(bo.SectorSize, bo.SealingResults[0].Unseal)) } - fmt.Printf("generate candidates: %s\n", benchout.PostGenerateCandidates) - fmt.Printf("compute epost proof (cold): %s\n", benchout.PostEProofCold) - fmt.Printf("compute epost proof (hot): %s\n", benchout.PostEProofHot) - fmt.Printf("verify epost proof (cold): %s\n", benchout.VerifyEPostCold) - fmt.Printf("verify epost proof (hot): %s\n", benchout.VerifyEPostHot) + fmt.Printf("generate candidates: %s (%s)\n", bo.PostGenerateCandidates, bps(bo.SectorSize*uint64(len(bo.SealingResults)), bo.PostGenerateCandidates)) + fmt.Printf("compute epost proof (cold): %s\n", bo.PostEProofCold) + fmt.Printf("compute epost proof (hot): %s\n", bo.PostEProofHot) + fmt.Printf("verify epost proof (cold): %s\n", bo.VerifyEPostCold) + fmt.Printf("verify epost proof (hot): %s\n", bo.VerifyEPostHot) } return nil }, @@ -357,3 +359,7 @@ func main() { return } } + +func bps(data uint64, d time.Duration) string { + return lcli.SizeStr(types.BigDiv(types.BigMul(types.NewInt(data), types.NewInt(uint64(time.Second))), types.NewInt(uint64(d)))) + "/s" +} diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 154d38fa0..58c459e44 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -43,7 +43,7 @@ var infoCmd = &cli.Command{ return err } - fmt.Printf("Sector Size: %s\n", sizeStr(types.NewInt(sizeByte))) + fmt.Printf("Sector Size: %s\n", lcli.SizeStr(types.NewInt(sizeByte))) pow, err := api.StateMinerPower(ctx, maddr, nil) if err != nil { @@ -51,7 +51,7 @@ var infoCmd = &cli.Command{ } percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower) - fmt.Printf("Power: %s / %s (%0.4f%%)\n", sizeStr(pow.MinerPower), sizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000) + fmt.Printf("Power: %s / %s (%0.4f%%)\n", lcli.SizeStr(pow.MinerPower), lcli.SizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000) // TODO: indicate whether the post worker is in use wstat, err := nodeApi.WorkerStats(ctx) @@ -110,18 +110,6 @@ var infoCmd = &cli.Command{ }, } -var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"} - -func sizeStr(size types.BigInt) string { - size = types.BigMul(size, types.NewInt(100)) - i := 0 - for types.BigCmp(size, types.NewInt(102400)) >= 0 && i < len(Units)-1 { - size = types.BigDiv(size, types.NewInt(1024)) - i++ - } - return fmt.Sprintf("%s.%s %s", types.BigDiv(size, types.NewInt(100)), types.BigMod(size, types.NewInt(100)), Units[i]) -} - func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) { sectors, err := napi.SectorsList(ctx) if err != nil {