mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Added ResetStats
This commit is contained in:
10
sublist.go
10
sublist.go
@@ -419,7 +419,9 @@ func (s *Sublist) Stats() *Stats {
|
||||
st.NumInserts = s.stats.inserts
|
||||
st.NumRemoves = s.stats.removes
|
||||
st.NumMatches = s.stats.matches
|
||||
st.CacheHitRate = float64(s.stats.cacheHits) / float64(s.stats.matches)
|
||||
if s.stats.matches > 0 {
|
||||
st.CacheHitRate = float64(s.stats.cacheHits) / float64(s.stats.matches)
|
||||
}
|
||||
// whip through cache for fanout stats
|
||||
// FIXME, creating all each time could be expensive, should do a cb version.
|
||||
tot, max := 0, 0
|
||||
@@ -437,6 +439,12 @@ func (s *Sublist) Stats() *Stats {
|
||||
return st
|
||||
}
|
||||
|
||||
// ResetStats will clear stats and update StatsTime to time.Now()
|
||||
func (s *Sublist) ResetStats() {
|
||||
s.stats = stats{}
|
||||
s.stats.since = time.Now()
|
||||
}
|
||||
|
||||
// numLevels will return the maximum number of levels
|
||||
// contained in the Sublist tree.
|
||||
func (s *Sublist) numLevels() int {
|
||||
|
||||
@@ -277,6 +277,24 @@ func TestStats(t *testing.T) {
|
||||
if stats.AvgFanout != 2.5 {
|
||||
t.Fatalf("Wrong stats for MaxFanout: %d vs %d\n", stats.AvgFanout, 2.5)
|
||||
}
|
||||
|
||||
s.ResetStats()
|
||||
stats = s.Stats()
|
||||
if time.Since(stats.StatsTime) > 50*time.Millisecond {
|
||||
t.Fatalf("After Reset: StatsTime seems incorrect: %+v\n", stats.StatsTime)
|
||||
}
|
||||
if stats.NumInserts != 0 {
|
||||
t.Fatalf("After Reset: Wrong stats for NumInserts: %d vs %d\n", stats.NumInserts, 0)
|
||||
}
|
||||
if stats.NumRemoves != 0 {
|
||||
t.Fatalf("After Reset: Wrong stats for NumRemoves: %d vs %d\n", stats.NumRemoves, 0)
|
||||
}
|
||||
if stats.NumMatches != 0 {
|
||||
t.Fatalf("After Reset: Wrong stats for NumMatches: %d vs %d\n", stats.NumMatches, 0)
|
||||
}
|
||||
if stats.CacheHitRate != 0.0 {
|
||||
t.Fatalf("After Reset: Wrong stats for CacheHitRate: %.3g vs %0.3g\n", stats.CacheHitRate, 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
// -- Benchmarks Setup --
|
||||
|
||||
Reference in New Issue
Block a user