Optimize basic sampler

This commit is contained in:
Olivier Poitrey 2019-05-23 17:00:29 -07:00
parent ad0401954a
commit ffd0e9625d
1 changed files with 5 additions and 1 deletions

View File

@ -46,8 +46,12 @@ type BasicSampler struct {
// Sample implements the Sampler interface. // Sample implements the Sampler interface.
func (s *BasicSampler) Sample(lvl Level) bool { func (s *BasicSampler) Sample(lvl Level) bool {
n := s.N
if n == 1 {
return true
}
c := atomic.AddUint32(&s.counter, 1) c := atomic.AddUint32(&s.counter, 1)
return c%s.N == s.N-1 return c%n == 1
} }
// BurstSampler lets Burst events pass per Period then pass the decision to // BurstSampler lets Burst events pass per Period then pass the decision to