mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
updated stat printer
This commit is contained in:
+8
-10
@@ -13,17 +13,15 @@ const (
|
||||
type GorStat struct {
|
||||
statName string
|
||||
latest int
|
||||
min int
|
||||
mean int
|
||||
max int
|
||||
|
||||
currentTime int64
|
||||
}
|
||||
|
||||
func NewGorStat(statName string) (s *GorStat) {
|
||||
s = new(GorStat)
|
||||
s.statName = statName
|
||||
s.latest = 0
|
||||
s.min = 0
|
||||
s.mean = 0
|
||||
s.max = 0
|
||||
|
||||
if Settings.stats {
|
||||
@@ -37,21 +35,21 @@ func (s *GorStat) Write(latest int) {
|
||||
if latest > s.max {
|
||||
s.max = latest
|
||||
}
|
||||
if latest < s.min {
|
||||
s.min = latest
|
||||
if latest != 0 {
|
||||
s.mean = (s.mean + latest) / 2
|
||||
}
|
||||
s.latest = latest
|
||||
}
|
||||
}
|
||||
|
||||
func (s *GorStat) String() string {
|
||||
return s.statName + ":" + strconv.Itoa(s.latest) + "," + strconv.Itoa(s.min) + "," + strconv.Itoa(s.max)
|
||||
return s.statName + ":" + strconv.Itoa(s.latest) + "," + strconv.Itoa(s.mean) + "," + strconv.Itoa(s.max)
|
||||
}
|
||||
|
||||
func (s *GorStat) reportStats() {
|
||||
if (time.Now().UnixNano() - s.currentTime) > (rate * time.Second.Nanoseconds()) {
|
||||
s.currentTime = time.Now().UnixNano()
|
||||
log.Println(s)
|
||||
for {
|
||||
log.Println(s)
|
||||
time.Sleep(rate * time.Second.Nanoseconds())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user