mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
cmd/workload: filtergen exits on errors; filterperf collects them and writes error file
This commit is contained in:
parent
65051bd249
commit
013f01986f
2 changed files with 22 additions and 21 deletions
|
|
@ -40,7 +40,6 @@ var (
|
|||
Action: filterGenCmd,
|
||||
Flags: []cli.Flag{
|
||||
filterQueryFileFlag,
|
||||
filterErrorFileFlag,
|
||||
},
|
||||
}
|
||||
filterQueryFileFlag = &cli.StringFlag{
|
||||
|
|
@ -73,8 +72,7 @@ func filterGenCmd(ctx *cli.Context) error {
|
|||
query.run(f.client, nil)
|
||||
if query.Err != nil {
|
||||
query.printError()
|
||||
f.errors = append(f.errors, query)
|
||||
continue
|
||||
exit("filter query failed")
|
||||
}
|
||||
if len(query.results) > 0 && len(query.results) <= maxFilterResultSize {
|
||||
for {
|
||||
|
|
@ -92,8 +90,7 @@ func filterGenCmd(ctx *cli.Context) error {
|
|||
}
|
||||
if extQuery.Err != nil {
|
||||
extQuery.printError()
|
||||
f.errors = append(f.errors, extQuery)
|
||||
break
|
||||
exit("filter query failed")
|
||||
}
|
||||
if len(extQuery.results) > maxFilterResultSize {
|
||||
break
|
||||
|
|
@ -103,7 +100,6 @@ func filterGenCmd(ctx *cli.Context) error {
|
|||
f.storeQuery(query)
|
||||
if time.Since(lastWrite) > time.Second*10 {
|
||||
f.writeQueries()
|
||||
f.writeErrors()
|
||||
lastWrite = time.Now()
|
||||
}
|
||||
}
|
||||
|
|
@ -114,18 +110,15 @@ func filterGenCmd(ctx *cli.Context) error {
|
|||
type filterTestGen struct {
|
||||
client *client
|
||||
queryFile string
|
||||
errorFile string
|
||||
|
||||
finalizedBlock int64
|
||||
queries [filterBuckets][]*filterQuery
|
||||
errors []*filterQuery
|
||||
}
|
||||
|
||||
func newFilterTestGen(ctx *cli.Context) *filterTestGen {
|
||||
return &filterTestGen{
|
||||
client: makeClient(ctx),
|
||||
queryFile: ctx.String(filterQueryFileFlag.Name),
|
||||
errorFile: ctx.String(filterErrorFileFlag.Name),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -362,17 +355,6 @@ func (s *filterTestGen) writeQueries() {
|
|||
file.Close()
|
||||
}
|
||||
|
||||
// writeQueries serializes the generated errors to the error file.
|
||||
func (s *filterTestGen) writeErrors() {
|
||||
file, err := os.Create(s.errorFile)
|
||||
if err != nil {
|
||||
exit(fmt.Errorf("Error creating filter error file %s: %v", s.errorFile, err))
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
json.NewEncoder(file).Encode(s.errors)
|
||||
}
|
||||
|
||||
func mustGetFinalizedBlock(client *client) int64 {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"slices"
|
||||
"sort"
|
||||
"time"
|
||||
|
|
@ -61,7 +63,10 @@ func filterPerfCmd(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
// Run test queries.
|
||||
var failed, pruned, mismatch int
|
||||
var (
|
||||
failed, pruned, mismatch int
|
||||
errors []*filterQuery
|
||||
)
|
||||
for i := 1; i <= passCount; i++ {
|
||||
fmt.Println("Performance test pass", i, "/", passCount)
|
||||
for len(queries) > 0 {
|
||||
|
|
@ -80,11 +85,13 @@ func filterPerfCmd(ctx *cli.Context) error {
|
|||
qt.medianTime = qt.runtime[len(qt.runtime)/2]
|
||||
if qt.query.Err != nil {
|
||||
qt.query.printError()
|
||||
errors = append(errors, qt.query)
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
if rhash := qt.query.calculateHash(); *qt.query.ResultHash != rhash {
|
||||
fmt.Printf("Filter query result mismatch: fromBlock: %d toBlock: %d addresses: %v topics: %v expected hash: %064x calculated hash: %064x\n", qt.query.FromBlock, qt.query.ToBlock, qt.query.Address, qt.query.Topics, *qt.query.ResultHash, rhash)
|
||||
errors = append(errors, qt.query)
|
||||
mismatch++
|
||||
continue
|
||||
}
|
||||
|
|
@ -127,6 +134,7 @@ func filterPerfCmd(ctx *cli.Context) error {
|
|||
fmt.Printf("Most expensive query #%-2d median runtime: %13v max runtime: %13v result count: %4d fromBlock: %9d toBlock: %9d addresses: %v topics: %v\n",
|
||||
i+1, q.medianTime, q.runtime[len(q.runtime)-1], len(q.query.results), q.query.FromBlock, q.query.ToBlock, q.query.Address, q.query.Topics)
|
||||
}
|
||||
writeErrors(ctx.String(filterErrorFileFlag.Name), errors)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -143,3 +151,14 @@ func (st *bucketStats) print(name string) {
|
|||
fmt.Printf("%-20s queries: %4d average block length: %12.2f average log count: %7.2f average runtime: %13v\n",
|
||||
name, st.count, float64(st.blocks)/float64(st.count), float64(st.logs)/float64(st.count), st.runtime/time.Duration(st.count))
|
||||
}
|
||||
|
||||
// writeQueries serializes the generated errors to the error file.
|
||||
func writeErrors(errorFile string, errors []*filterQuery) {
|
||||
file, err := os.Create(errorFile)
|
||||
if err != nil {
|
||||
exit(fmt.Errorf("Error creating filter error file %s: %v", errorFile, err))
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
json.NewEncoder(file).Encode(errors)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue