MCPcopy
hub / github.com/rs/zerolog / inc

Method inc

sampler.go:89–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87}
88
89func (s *BurstSampler) inc() uint32 {
90 now := TimestampFunc().UnixNano()
91 resetAt := atomic.LoadInt64(&s.resetAt)
92 var c uint32
93 if now >= resetAt {
94 c = 1
95 atomic.StoreUint32(&s.counter, c)
96 newResetAt := now + s.Period.Nanoseconds()
97 reset := atomic.CompareAndSwapInt64(&s.resetAt, resetAt, newResetAt)
98 if !reset {
99 // Lost the race with another goroutine trying to reset.
100 c = atomic.AddUint32(&s.counter, 1)
101 }
102 } else {
103 c = atomic.AddUint32(&s.counter, 1)
104 }
105 return c
106}
107
108// LevelSampler applies a different sampler for each level.
109type LevelSampler struct {

Callers 1

SampleMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected