gitee.com/quant1x/engine@v1.8.4/cache/scoreboard.go (about) 1 package cache 2 3 import ( 4 "fmt" 5 "sync" 6 "time" 7 ) 8 9 // ScoreBoard 记分牌 10 type ScoreBoard struct { 11 m sync.Mutex 12 Name string `name:"name"` // 名称 13 Kind Kind `name:"kind"` // 类型 14 Count int `name:"count"` // 总数 15 Max time.Duration `name:"max"` // 最大值 16 Min time.Duration `name:"min"` // 最小值 17 CrossTime time.Duration `name:"cross_time"` // 总耗时 18 Speed float64 `name:"speed"` // 速度 19 } 20 21 func (this *ScoreBoard) From(adapter DataAdapter) { 22 this.Name = adapter.Name() 23 this.Kind = adapter.Kind() 24 } 25 26 func (this *ScoreBoard) Add(delta int, take time.Duration) { 27 this.m.Lock() 28 defer this.m.Unlock() 29 this.Count = this.Count + delta 30 this.CrossTime += take 31 if this.Min == 0 || this.Min > take { 32 this.Min = take 33 } 34 if this.Max == 0 || this.Max < take { 35 this.Max = take 36 } 37 this.Speed = float64(this.Count) / this.CrossTime.Seconds() 38 } 39 40 func (this *ScoreBoard) String() string { 41 s := fmt.Sprintf("name: %s, kind: %d, total: %d, crosstime: %s, max: %d, min: %d, speed: %f", this.Name, this.Kind, this.Count, this.CrossTime, this.Max, this.Min, this.Speed) 42 return s 43 }