2019-03-21 21:20:50 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"time"
|
2019-03-30 21:20:06 +01:00
|
|
|
|
|
|
|
"github.com/zorchenhimer/MovieNight/common"
|
2019-03-21 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type streamStats struct {
|
|
|
|
messageIn int
|
|
|
|
messageOut int
|
|
|
|
start time.Time
|
|
|
|
mutex sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func newStreamStats() streamStats {
|
|
|
|
return streamStats{start: time.Now()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *streamStats) msgInInc() {
|
|
|
|
s.mutex.Lock()
|
|
|
|
s.messageIn++
|
|
|
|
s.mutex.Unlock()
|
|
|
|
}
|
|
|
|
func (s *streamStats) msgOutInc() {
|
|
|
|
s.mutex.Lock()
|
|
|
|
s.messageOut++
|
|
|
|
s.mutex.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *streamStats) Print() {
|
2019-03-30 21:18:26 +01:00
|
|
|
common.LogInfof("Messages In: %d\n", s.messageIn)
|
|
|
|
common.LogInfof("Messages Out: %d\n", s.messageOut)
|
|
|
|
common.LogInfof("Total Time: %s\n", time.Since(s.start))
|
2019-03-21 21:20:50 +01:00
|
|
|
}
|