mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 22:05:18 +00:00
add min, max, and error count
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/test/loadtime/payload"
|
||||
@@ -17,20 +18,37 @@ type Report struct {
|
||||
Max, Min, Avg time.Duration
|
||||
StdDev int64
|
||||
All []time.Duration
|
||||
ErrorCount int
|
||||
}
|
||||
|
||||
func GenerateFromBlockStore(s blockStore) (Report, error) {
|
||||
r := Report{}
|
||||
r := Report{
|
||||
Max: 0,
|
||||
Min: math.MaxInt64,
|
||||
}
|
||||
var sum int64
|
||||
for i := s.Base(); i < s.Height(); i++ {
|
||||
b := s.LoadBlock(i)
|
||||
for _, tx := range b.Data.Txs {
|
||||
p, err := payload.FromBytes(tx)
|
||||
if err != nil {
|
||||
return Report{}, err
|
||||
r.ErrorCount++
|
||||
continue
|
||||
}
|
||||
t := p.Time.AsTime().Sub(b.Time)
|
||||
r.All = append(r.All, t)
|
||||
if t > r.Max {
|
||||
r.Max = t
|
||||
} else if t < r.Min {
|
||||
r.Min = t
|
||||
}
|
||||
|
||||
// Using an int64 here makes an assumption about the scale and quantity of the data we are processing.
|
||||
// If all latencies were 2 seconds, we would need around 4 billion records to overflow this.
|
||||
// We are therefore assuming that the data does not exceed these bounds.
|
||||
sum += int64(t)
|
||||
}
|
||||
}
|
||||
r.Avg = time.Duration(sum / int64(len(r.All)))
|
||||
return r, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user