2018-11-07 21:54:12 -08:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-04-12 15:52:16 -07:00
|
|
|
"io"
|
2018-11-07 21:54:12 -08:00
|
|
|
"sort"
|
|
|
|
)
|
|
|
|
|
|
|
|
type eventStats map[string]uint
|
|
|
|
|
|
|
|
func newEventStats() eventStats {
|
|
|
|
events := make(map[string]uint)
|
|
|
|
return events
|
|
|
|
}
|
|
|
|
|
2018-11-07 22:57:37 -08:00
|
|
|
func (es eventStats) tally(eventDesc string) {
|
2018-11-07 21:54:12 -08:00
|
|
|
es[eventDesc]++
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pretty-print events as a table
|
2019-04-12 15:52:16 -07:00
|
|
|
func (es eventStats) Print(w io.Writer) {
|
2018-11-07 21:54:12 -08:00
|
|
|
var keys []string
|
|
|
|
for key := range es {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
2019-04-12 15:52:16 -07:00
|
|
|
|
2018-11-07 21:54:12 -08:00
|
|
|
sort.Strings(keys)
|
2019-04-12 15:52:16 -07:00
|
|
|
fmt.Fprintf(w, "Event statistics: \n")
|
|
|
|
|
2018-11-07 21:54:12 -08:00
|
|
|
for _, key := range keys {
|
2019-04-12 15:52:16 -07:00
|
|
|
fmt.Fprintf(w, " % 60s => %d\n", key, es[key])
|
2018-11-07 21:54:12 -08:00
|
|
|
}
|
|
|
|
}
|