mirror of
https://github.com/status-im/simulation.git
synced 2025-02-23 12:28:20 +00:00
Add elapsed time info to stats
This commit is contained in:
parent
70eca79946
commit
3c6dab9f89
@ -3,6 +3,7 @@ package stats
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/divan/graph-experiments/graph"
|
"github.com/divan/graph-experiments/graph"
|
||||||
"github.com/status-im/simulator/propagation"
|
"github.com/status-im/simulator/propagation"
|
||||||
@ -14,12 +15,14 @@ type Stats struct {
|
|||||||
NodeCoverage Coverage
|
NodeCoverage Coverage
|
||||||
LinkCoverage Coverage
|
LinkCoverage Coverage
|
||||||
Hist *Histogram
|
Hist *Histogram
|
||||||
|
Time time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintVerbose prints detailed terminal-friendly stats to
|
// PrintVerbose prints detailed terminal-friendly stats to
|
||||||
// the console.
|
// the console.
|
||||||
func (s *Stats) PrintVerbose() {
|
func (s *Stats) PrintVerbose() {
|
||||||
fmt.Println("Stats:")
|
fmt.Println("Stats:")
|
||||||
|
fmt.Println("Time elapsed:", s.Time)
|
||||||
fmt.Println("Nodes coverage:", s.NodeCoverage)
|
fmt.Println("Nodes coverage:", s.NodeCoverage)
|
||||||
fmt.Println("Links coverage:", s.LinkCoverage)
|
fmt.Println("Links coverage:", s.LinkCoverage)
|
||||||
fmt.Println("Histogram:")
|
fmt.Println("Histogram:")
|
||||||
@ -28,6 +31,7 @@ func (s *Stats) PrintVerbose() {
|
|||||||
|
|
||||||
// Analyze analyzes given propagation log and returns filled Stats object.
|
// Analyze analyzes given propagation log and returns filled Stats object.
|
||||||
func Analyze(g *graph.Graph, plog *propagation.Log) *Stats {
|
func Analyze(g *graph.Graph, plog *propagation.Log) *Stats {
|
||||||
|
t := analyzeTiming(plog)
|
||||||
nodeHits, hist := analyzeNodeHits(g, plog)
|
nodeHits, hist := analyzeNodeHits(g, plog)
|
||||||
nodeCoverage := analyzeNodeCoverage(g, nodeHits)
|
nodeCoverage := analyzeNodeCoverage(g, nodeHits)
|
||||||
linkCoverage := analyzeLinkCoverage(g, plog)
|
linkCoverage := analyzeLinkCoverage(g, plog)
|
||||||
@ -37,6 +41,7 @@ func Analyze(g *graph.Graph, plog *propagation.Log) *Stats {
|
|||||||
NodeCoverage: nodeCoverage,
|
NodeCoverage: nodeCoverage,
|
||||||
LinkCoverage: linkCoverage,
|
LinkCoverage: linkCoverage,
|
||||||
Hist: hist,
|
Hist: hist,
|
||||||
|
Time: t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,3 +92,16 @@ func analyzeLinkCoverage(g *graph.Graph, plog *propagation.Log) Coverage {
|
|||||||
total := len(g.Links())
|
total := len(g.Links())
|
||||||
return NewCoverage(actual, total)
|
return NewCoverage(actual, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// analyzeTiming returns the amount of time the simulation took.
|
||||||
|
func analyzeTiming(plog *propagation.Log) time.Duration {
|
||||||
|
// log contains timestamps in milliseconds, so the
|
||||||
|
// max value will be our number
|
||||||
|
var max int
|
||||||
|
for _, ts := range plog.Timestamps {
|
||||||
|
if ts > max {
|
||||||
|
max = ts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return time.Duration(max) * time.Millisecond
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user