Merge pull request #2106 from filecoin-project/feat/streaming-bench-results

stream bench import results to disk
This commit is contained in:
Łukasz Magiera 2020-06-23 11:42:18 +02:00 committed by GitHub
commit d24a750ba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"math" "math"
"os" "os"
@ -119,14 +120,22 @@ var importBenchCmd = &cli.Command{
ts = next ts = next
} }
out := make([]TipSetExec, 0, len(tschain)) ibj, err := os.Create("import-bench.json")
if err != nil {
return err
}
defer ibj.Close() //nolint:errcheck
enc := json.NewEncoder(ibj)
var lastTse *TipSetExec
lastState := tschain[len(tschain)-1].ParentState() lastState := tschain[len(tschain)-1].ParentState()
for i := len(tschain) - 2; i >= 0; i-- { for i := len(tschain) - 2; i >= 0; i-- {
cur := tschain[i] cur := tschain[i]
log.Infof("computing state (height: %d, ts=%s)", cur.Height(), cur.Cids()) log.Infof("computing state (height: %d, ts=%s)", cur.Height(), cur.Cids())
if cur.ParentState() != lastState { if cur.ParentState() != lastState {
lastTrace := out[len(out)-1].Trace lastTrace := lastTse.Trace
d, err := json.MarshalIndent(lastTrace, "", " ") d, err := json.MarshalIndent(lastTrace, "", " ")
if err != nil { if err != nil {
panic(err) panic(err)
@ -140,26 +149,20 @@ var importBenchCmd = &cli.Command{
if err != nil { if err != nil {
return err return err
} }
out = append(out, TipSetExec{
lastTse = &TipSetExec{
TipSet: cur.Key(), TipSet: cur.Key(),
Trace: trace, Trace: trace,
Duration: time.Since(start), Duration: time.Since(start),
}) }
lastState = st lastState = st
if err := enc.Encode(lastTse); err != nil {
return xerrors.Errorf("failed to write out tipsetexec: %w", err)
}
} }
pprof.StopCPUProfile() pprof.StopCPUProfile()
ibj, err := os.Create("import-bench.json")
if err != nil {
return err
}
defer ibj.Close() //nolint:errcheck
if err := json.NewEncoder(ibj).Encode(out); err != nil {
return err
}
return nil return nil
}, },
@ -236,9 +239,16 @@ var importAnalyzeCmd = &cli.Command{
} }
var results []TipSetExec var results []TipSetExec
if err := json.NewDecoder(fi).Decode(&results); err != nil { for {
var tse TipSetExec
if err := json.NewDecoder(fi).Decode(&tse); err != nil {
if err != io.EOF {
return err return err
} }
break
}
results = append(results, tse)
}
chargeDeltas := make(map[string][]float64) chargeDeltas := make(map[string][]float64)