add some smartness to bench analyze gas output

This commit is contained in:
Jeromy 2020-06-15 13:02:57 -07:00
parent 0230362d33
commit 01c4726fd5
2 changed files with 67 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math"
"os" "os"
"runtime/pprof" "runtime/pprof"
"sort" "sort"
@ -162,6 +163,43 @@ type Invocation struct {
Invoc *api.InvocResult Invoc *api.InvocResult
} }
const GasPerNs = 10
func countGasCosts(et *types.ExecutionTrace) (int64, int64) {
var cgas, vgas int64
for _, gc := range et.GasCharges {
cgas += gc.ComputeGas
vgas += gc.VirtualComputeGas
}
for _, sub := range et.Subcalls {
c, v := countGasCosts(&sub)
cgas += c
vgas += v
}
return cgas, vgas
}
func compStats(vals []float64) (float64, float64) {
var sum float64
for _, v := range vals {
sum += v
}
av := sum / float64(len(vals))
var varsum float64
for _, v := range vals {
delta := av - v
varsum += delta * delta
}
return av, math.Sqrt(varsum / float64(len(vals)))
}
var importAnalyzeCmd = &cli.Command{ var importAnalyzeCmd = &cli.Command{
Name: "analyze", Name: "analyze",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
@ -180,6 +218,8 @@ var importAnalyzeCmd = &cli.Command{
return err return err
} }
chargeDeltas := make(map[string][]float64)
var invocs []Invocation var invocs []Invocation
var totalTime time.Duration var totalTime time.Duration
for i, r := range results { for i, r := range results {
@ -191,9 +231,35 @@ var importAnalyzeCmd = &cli.Command{
TipSet: r.TipSet, TipSet: r.TipSet,
Invoc: inv, Invoc: inv,
}) })
cgas, vgas := countGasCosts(&inv.ExecutionTrace)
fmt.Printf("Invocation: %d %s: %s %d -> %0.2f\n", inv.Msg.Method, inv.Msg.To, inv.Duration, cgas+vgas, float64(GasPerNs*inv.Duration.Nanoseconds())/float64(cgas+vgas))
for _, gc := range inv.ExecutionTrace.GasCharges {
compGas := gc.ComputeGas + gc.VirtualComputeGas
ratio := float64(compGas) / float64(gc.TimeTaken.Nanoseconds())
chargeDeltas[gc.Name] = append(chargeDeltas[gc.Name], 1/(ratio/GasPerNs))
//fmt.Printf("%s: %d, %s: %0.2f\n", gc.Name, compGas, gc.TimeTaken, 1/(ratio/GasPerNs))
}
} }
} }
var keys []string
for k := range chargeDeltas {
keys = append(keys, k)
}
fmt.Println("Gas Price Deltas")
sort.Strings(keys)
for _, k := range keys {
vals := chargeDeltas[k]
av, stdev := compStats(vals)
fmt.Printf("%s: incr by %f (%f)\n", k, av, stdev)
}
sort.Slice(invocs, func(i, j int) bool { sort.Slice(invocs, func(i, j int) bool {
return invocs[i].Invoc.Duration > invocs[j].Invoc.Duration return invocs[i].Invoc.Duration > invocs[j].Invoc.Duration
}) })

View File

@ -460,7 +460,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
} }
if cerr != nil { if cerr != nil {
return xerrors.Errorf("failed to configure storage miner: %w", err) return xerrors.Errorf("failed to configure storage miner: %w", cerr)
} }
} }