Files
tendermint/test/loadtime/cmd/report/main.go
mergify[bot] 014d0d6ca0 add separated runs by UUID (backport #9367) (#9380)
* add separated runs by UUID (#9367)

This _should_ be the last piece needed for this tool.
This allows the tool to generate reports on multiple experimental runs that may have been performed against the same chain.

The `load` tool has been updated to generate a `UUID` on startup to uniquely identify each experimental run. The `report` tool separates all of the results it reads by `UUID` and performs separate calculations for each discovered experiment.

Sample output is as follows

```
Experiment ID: 6bd7d1e8-d82c-4dbe-a1b3-40ab99e4fa30

        Connections: 1
        Rate: 1000
        Size: 1024

        Total Valid Tx: 9000
        Total Negative Latencies: 0
        Minimum Latency: 86.632837ms
        Maximum Latency: 1.151089602s
        Average Latency: 813.759361ms
        Standard Deviation: 225.189977ms

Experiment ID: 453960af-6295-4282-aed6-367fc17c0de0

        Connections: 1
        Rate: 1000
        Size: 1024

        Total Valid Tx: 9000
        Total Negative Latencies: 0
        Minimum Latency: 79.312992ms
        Maximum Latency: 1.162446243s
        Average Latency: 422.755139ms
        Standard Deviation: 241.832475ms

Total Invalid Tx: 0
```

closes: #9352

#### PR checklist

- [ ] Tests written/updated, or no tests needed
- [ ] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [ ] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed

(cherry picked from commit 1067ba1571)

# Conflicts:
#	go.mod

* fix merge conflict

* fix lint

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
Co-authored-by: William Banfield <wbanfield@gmail.com>
2022-09-06 11:07:59 -04:00

104 lines
2.4 KiB
Go

package main
import (
"encoding/csv"
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/test/loadtime/report"
dbm "github.com/tendermint/tm-db"
)
var (
db = flag.String("database-type", "goleveldb", "the type of database holding the blockstore")
dir = flag.String("data-dir", "", "path to the directory containing the tendermint databases")
csvOut = flag.String("csv", "", "dump the extracted latencies as raw csv for use in additional tooling")
)
func main() {
flag.Parse()
if *db == "" {
log.Fatalf("must specify a database-type")
}
if *dir == "" {
log.Fatalf("must specify a data-dir")
}
d := strings.TrimPrefix(*dir, "~/")
if d != *dir {
h, err := os.UserHomeDir()
if err != nil {
panic(err)
}
d = h + "/" + d
}
_, err := os.Stat(d)
if err != nil {
panic(err)
}
dbType := dbm.BackendType(*db)
db, err := dbm.NewDB("blockstore", dbType, d)
if err != nil {
panic(err)
}
s := store.NewBlockStore(db)
defer s.Close()
rs, err := report.GenerateFromBlockStore(s)
if err != nil {
panic(err)
}
if *csvOut != "" {
cf, err := os.Create(*csvOut)
if err != nil {
panic(err)
}
w := csv.NewWriter(cf)
err = w.WriteAll(toCSVRecords(rs.List()))
if err != nil {
panic(err)
}
return
}
for _, r := range rs.List() {
fmt.Printf(""+
"Experiment ID: %s\n\n"+
"\tConnections: %d\n"+
"\tRate: %d\n"+
"\tSize: %d\n\n"+
"\tTotal Valid Tx: %d\n"+
"\tTotal Negative Latencies: %d\n"+
"\tMinimum Latency: %s\n"+
"\tMaximum Latency: %s\n"+
"\tAverage Latency: %s\n"+
"\tStandard Deviation: %s\n\n", r.ID, r.Connections, r.Rate, r.Size, len(r.All), r.NegativeCount, r.Min, r.Max, r.Avg, r.StdDev) //nolint:lll
}
fmt.Printf("Total Invalid Tx: %d\n", rs.ErrorCount())
}
func toCSVRecords(rs []report.Report) [][]string {
total := 0
for _, v := range rs {
total += len(v.All)
}
res := make([][]string, total+1)
res[0] = []string{"experiment_id", "duration_ns", "connections", "rate", "size"}
offset := 1
for _, r := range rs {
idStr := r.ID.String()
connStr := strconv.FormatInt(int64(r.Connections), 10)
rateStr := strconv.FormatInt(int64(r.Rate), 10)
sizeStr := strconv.FormatInt(int64(r.Size), 10)
for i, v := range r.All {
res[offset+i] = []string{idStr, strconv.FormatInt(int64(v), 10), connStr, rateStr, sizeStr}
}
offset += len(r.All)
}
return res
}