MovieNight/stats.go

37 lines
643 B
Go
Raw Normal View History

package main
import (
"sync"
"time"
2019-03-30 21:20:06 +01:00
"github.com/zorchenhimer/MovieNight/common"
)
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() {
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))
}