bench: print bps speeds

This commit is contained in:
Łukasz Magiera 2019-12-10 19:04:13 +01:00
parent 739a41e834
commit 0fa20f6074
3 changed files with 39 additions and 26 deletions

19
cli/utils.go Normal file
View File

@ -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])
}

View File

@ -6,6 +6,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/filecoin-project/lotus/chain/types"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
@ -13,6 +14,7 @@ import (
"time" "time"
ffi "github.com/filecoin-project/filecoin-ffi" ffi "github.com/filecoin-project/filecoin-ffi"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
@ -315,7 +317,7 @@ func main() {
} }
verifypost2 := time.Now() verifypost2 := time.Now()
benchout := BenchResults{ bo := BenchResults{
SectorSize: cfg.SectorSize, SectorSize: cfg.SectorSize,
SealingResults: sealTimings, SealingResults: sealTimings,
@ -327,7 +329,7 @@ func main() {
} // TODO: optionally write this as json to a file } // TODO: optionally write this as json to a file
if c.Bool("json-out") { if c.Bool("json-out") {
data, err := json.MarshalIndent(benchout, "", " ") data, err := json.MarshalIndent(bo, "", " ")
if err != nil { if err != nil {
return err return err
} }
@ -336,17 +338,17 @@ func main() {
} else { } else {
fmt.Printf("results (%d)\n", sectorSize) fmt.Printf("results (%d)\n", sectorSize)
if robench == "" { if robench == "" {
fmt.Printf("seal: addPiece: %s\n", benchout.SealingResults[0].AddPiece) // TODO: average across multiple sealings 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\n", benchout.SealingResults[0].PreCommit) fmt.Printf("seal: preCommit: %s (%s)\n", bo.SealingResults[0].PreCommit, bps(bo.SectorSize, bo.SealingResults[0].PreCommit))
fmt.Printf("seal: Commit: %s\n", benchout.SealingResults[0].Commit) fmt.Printf("seal: commit: %s (%s)\n", bo.SealingResults[0].Commit, bps(bo.SectorSize, bo.SealingResults[0].Commit))
fmt.Printf("seal: Verify: %s\n", benchout.SealingResults[0].Verify) fmt.Printf("seal: verify: %s\n", bo.SealingResults[0].Verify)
fmt.Printf("unseal: %s\n", benchout.SealingResults[0].Unseal) 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("generate candidates: %s (%s)\n", bo.PostGenerateCandidates, bps(bo.SectorSize*uint64(len(bo.SealingResults)), bo.PostGenerateCandidates))
fmt.Printf("compute epost proof (cold): %s\n", benchout.PostEProofCold) fmt.Printf("compute epost proof (cold): %s\n", bo.PostEProofCold)
fmt.Printf("compute epost proof (hot): %s\n", benchout.PostEProofHot) fmt.Printf("compute epost proof (hot): %s\n", bo.PostEProofHot)
fmt.Printf("verify epost proof (cold): %s\n", benchout.VerifyEPostCold) fmt.Printf("verify epost proof (cold): %s\n", bo.VerifyEPostCold)
fmt.Printf("verify epost proof (hot): %s\n", benchout.VerifyEPostHot) fmt.Printf("verify epost proof (hot): %s\n", bo.VerifyEPostHot)
} }
return nil return nil
}, },
@ -357,3 +359,7 @@ func main() {
return 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"
}

View File

@ -43,7 +43,7 @@ var infoCmd = &cli.Command{
return err 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) pow, err := api.StateMinerPower(ctx, maddr, nil)
if err != nil { if err != nil {
@ -51,7 +51,7 @@ var infoCmd = &cli.Command{
} }
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower) 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 // TODO: indicate whether the post worker is in use
wstat, err := nodeApi.WorkerStats(ctx) 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) { func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
sectors, err := napi.SectorsList(ctx) sectors, err := napi.SectorsList(ctx)
if err != nil { if err != nil {