// NewRates reports rolling rate information for countTracker. samples specifies
// the number of samples to report, and interval specifies the time interval
// between samples. The minimum interval is 1 second.
8262
func NewRates(name string, countTracker CountTracker, samples int, interval time.Duration) *Rates {
	if interval < 1*time.Second {
		panic("interval too small")
	}
	rt := &Rates{
		timeStamps:   NewRingInt64(samples + 1),
		counts:       make(map[string]*RingInt64),
		countTracker: countTracker,
		samples:      samples + 1,
		interval:     interval,
	}
	if name != "" {
		Publish(name, rt)
	}
	go rt.track()
	return rt
}
346993
func (s *UniformSample) Min() int64 {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return SampleMin(s.values)
}
1324166
func NewRateLimitedFunction(keyFunc kcache.KeyFunc, interval int, handlerFunc HandlerFunc) *RateLimitedFunction {
	fifo := kcache.NewFIFO(keyFunc)

	qps := float32(1000.0) // Call rate per second (SLA).
	if interval > 0 {
		qps = float32(1.0 / float32(interval))
	}

	limiter := flowcontrol.NewTokenBucketRateLimiter(qps, 1)

	return &RateLimitedFunction{handlerFunc, fifo, limiter}
}
199109
func NewRateLimiter(rate_bytes_per_sec, refill_period_us int64, fairness int32) *RateLimiter {
	return NewNativeRateLimiter(C.rocksdb_ratelimiter_create(
		C.int64_t(rate_bytes_per_sec),
		C.int64_t(refill_period_us),
		C.int32_t(fairness),
	))
}
103526
func (pulse Pulse) Rate(rate int8) Input {
	CheckRate(rate)
	(&pulse).defaults()
	return NewInput("Pulse", rate, 0, 1, pulse.Freq, pulse.Width)
}
1285430
func (s *RemotelyControlledSampler) updateRateLimitingOrProbabilisticSampler(res *sampling.SamplingStrategyResponse) error {
	var newSampler Sampler
	if probabilistic := res.GetProbabilisticSampling(); probabilistic != nil {
		newSampler = newProbabilisticSampler(probabilistic.SamplingRate)
	} else if rateLimiting := res.GetRateLimitingSampling(); rateLimiting != nil {
		newSampler = NewRateLimitingSampler(float64(rateLimiting.MaxTracesPerSecond))
	} else {
		return fmt.Errorf("Unsupported sampling strategy type %v", res.GetStrategyType())
	}
	if !s.sampler.Equal(newSampler) {
		s.sampler = newSampler
	}
	return nil
}
50534
func (s *Statsd) Counter(sampleRate float32, bucket string, n ...int) {
	samp, ok := maybeSample(sampleRate)
	if !ok {
		return
	}

	msgs := make([]sendable, len(n))
	for i, ni := range n {
		msgs[i] = &counterUpdate{
			prefix:   s.prefix,
			bucket:   bucket,
			n:        ni,
			sampling: samp,
		}
	}

	s.publish(msgs)
}
1295996
func (rt *Rates) TotalRate() float64 {
	rt.mu.Lock()
	defer rt.mu.Unlock()

	return rt.totalRate
}
165325
func (sr SampleRate) D(n int) time.Duration {
	return time.Second * time.Duration(n) / time.Duration(sr)
}
546814
func NewIntervalMetrics(intv time.Time) *IntervalMetrics {
	return &IntervalMetrics{
		Interval: intv,
		Gauges:   make(map[string]GaugeValue),
		Points:   make(map[string][]float32),
		Counters: make(map[string]SampledValue),
		Samples:  make(map[string]SampledValue),
	}
}
1009258
func NewCountingSampler(rate float64) (Sampler, error) {
	if rate == 0.0 {
		return NeverSample, nil
	}
	if rate == 1.0 {
		return AlwaysSample, nil
	}
	if rate < 0.01 || rate > 1 {
		return nil, fmt.Errorf("rate should be 0.0 or between 0.01 and 1: was %f", rate)
	}
	var (
		i         = 0
		outOf100  = int(rate*100 + math.Copysign(0.5, rate*100)) // for rounding float to int conversion instead of truncation
		decisions = randomBitSet(100, outOf100, rand.New(rand.NewSource(time.Now().UnixNano())))
		mtx       = &sync.Mutex{}
	)

	return func(_ uint64) bool {
		mtx.Lock()
		result := decisions[i]
		i++
		if i == 100 {
			i = 0
		}
		mtx.Unlock()
		return result
	}, nil
}
208279
func (dust2 Dust2) Rate(rate int8) Input {
	CheckRate(rate)
	(&dust2).defaults()
	return NewInput("Dust2", rate, 0, 1, dust2.Density)
}
74316
func NewRateLimiter(bandwidth float64) *RateLimiter {
	//  convert bandwidth to bytes per nanosecond
	b := bandwidth / float64(time.Second)
	return &RateLimiter{
		bandwidth:    b,
		allowance:    0,
		maxAllowance: bandwidth,
		lastUpdate:   time.Now(),
	}
}
514360
func NewRateSet() *RateSet {
	rs := new(RateSet)
	rs.m = make(map[time.Duration]*rate)
	return rs
}
173891
func (sin SinOsc) Rate(rate int8) Input {
	CheckRate(rate)
	(&sin).defaults()
	return NewInput("SinOsc", rate, 0, 1, sin.Freq, sin.Phase)
}
137628
func (pc PulseCount) Rate(rate int8) Input {
	CheckRate(rate)
	(&pc).defaults()
	return NewInput("PulseCount", rate, 0, 1, pc.Trig, pc.Reset)
}
3430
func (d *Influxstatsd) NewCounter(name string, sampleRate float64) *Counter {
	d.rates.Set(name, sampleRate)
	return &Counter{
		name: name,
		obs:  d.counters.Observe,
	}
}