github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/system/trace/statistics.go (about) 1 package trace 2 3 import "time" 4 5 type BaseStatistics interface { 6 Init(tags ...string) 7 Accumulate(tag string, lastPinTime time.Time) 8 GetTags() []string 9 GetValue(tag string) int64 10 } 11 12 type Summary struct { 13 statisticMap map[string]int64 14 keys []string 15 } 16 17 func NewSummary() *Summary { 18 return &Summary{ 19 statisticMap: make(map[string]int64), 20 } 21 } 22 23 func (s *Summary) Init(tags ...string) { 24 for _, k := range tags { 25 s.statisticMap[k] = 0 26 } 27 s.keys = tags 28 } 29 30 func (s *Summary) Accumulate(tag string, lastPinTime time.Time) { 31 s.statisticMap[tag] += time.Since(lastPinTime).Nanoseconds() 32 } 33 34 func (s *Summary) GetTags() []string { 35 return s.keys 36 } 37 38 func (s *Summary) GetValue(tag string) int64 { 39 return s.statisticMap[tag] 40 } 41 42 type StatisticsCell interface { 43 StartTiming() 44 EndTiming(tag string) 45 }