// SamplingPercent sets the tracing sampling rate as a percentage value.
// It panics if p is less than 0 or more than 100.
// SamplingPercent and MaxSamplingRate are mutually exclusive.
199238
func SamplingPercent(p int) TracerOption {
	if p < 0 || p > 100 {
		panic("sampling rate must be between 0 and 100")
	}
	return func(o *tracerOptions) *tracerOptions {
		o.samplingPercent = p
		return o
	}
}
463003
func (sg *SampleGroup) MinRate() int64 {
	m := int64(0)
	for i, s := range sg.Samples {
		if i == 0 {
			m = s.Rate()
		}
		m = min(m, s.Rate())
	}
	return m
}
958183
func SamplePercentile(values int64Slice, p float64) float64 {
	return SamplePercentiles(values, []float64{p})[0]
}
1171839
func (c *StatsdClient) FGaugeWithSampling(stat string, value float64, sampleRate float32) error {
	if err := checkSampleRate(sampleRate); err != nil {
		return err
	}

	if !shouldFire(sampleRate) {
		return nil
	}

	if value < 0 {
		err := c.send(stat, "%d|g", 0, 1)
		if nil != err {
			return err
		}
	}

	return c.send(stat, "%g|g", value, sampleRate)
}
380394
func PercentilInt(data []int, p int) int {
	n := len(data)
	if n == 0 {
		return 0
	}
	if n == 1 {
		return data[0]
	}

	pos := float64(p) * float64(n+1) / 100
	fpos := math.Floor(pos)
	intPos := int(fpos)
	dif := pos - fpos
	if intPos < 1 {
		return data[0]
	}
	if intPos >= n {
		return data[n-1]
	}
	lower := data[intPos-1]
	upper := data[intPos]
	val := float64(lower) + dif*float64(upper-lower)
	return int(math.Floor(val + 0.5))
}
370059
func (s *ExpDecaySample) Percentiles(ps []float64) []float64 {
	return SamplePercentiles(s.Values(), ps)
}
880948
func (s *LogGroupField) SetPercent(v int64) *LogGroupField {
	s.Percent = &v
	return s
}
1070971
func NewGuaranteedThroughputProbabilisticSampler(
	lowerBound, samplingRate float64,
) (*GuaranteedThroughputProbabilisticSampler, error) {
	return newGuaranteedThroughputProbabilisticSampler(lowerBound, samplingRate), nil
}
585159
func (sg *SampleGroup) MaxRate() int64 {
	m := int64(0)
	for i, s := range sg.Samples {
		if i == 0 {
			m = s.Rate()
		}
		m = max(m, s.Rate())
	}
	return m
}
1010660
func (ss *segmentStack) calcTargetTopLevel() int {
	var minMergePercentage float64
	if ss.options != nil {
		minMergePercentage = ss.options.MinMergePercentage
	}
	if minMergePercentage <= 0 {
		minMergePercentage = DefaultCollectionOptions.MinMergePercentage
	}

	newTopLevel := 0
	maxTopLevel := len(ss.a) - 2

	for newTopLevel < maxTopLevel {
		numX0 := ss.a[newTopLevel].Len()
		numX1 := ss.a[newTopLevel+1].Len()
		if (float64(numX1) / float64(numX0)) > minMergePercentage {
			break
		}

		newTopLevel++
	}

	return newTopLevel
}
833056
func (s *DBSnapshot) SetPercentProgress(v int64) *DBSnapshot {
	s.PercentProgress = &v
	return s
}
755510
func Tracer(sampleRate int, spanIDFunc, traceIDFunc IDFunc) goa.Middleware {
	return NewTracer(SamplingPercent(sampleRate), SpanIDFunc(spanIDFunc), TraceIDFunc(traceIDFunc))
}
231662
func (s *DescribeThingRegistrationTaskOutput) SetPercentageProgress(v int64) *DescribeThingRegistrationTaskOutput {
	s.PercentageProgress = &v
	return s
}
563871
func sampleDecodeFunc(bitsPerSample int) (func([]byte) int, error) {
	// NOTE: WAV PCM data is stored using little-endian
	switch bitsPerSample {
	case 8:
		// 8bit values are unsigned
		return func(s []byte) int {
			return int(uint8(s[0]))
		}, nil
	case 16:
		// -32,768	(0x7FFF) to	32,767	(0x8000)
		return func(s []byte) int {
			return int(int16(binary.LittleEndian.Uint16(s)))
		}, nil
	case 24:
		// -34,359,738,367 (0x7FFFFF) to 34,359,738,368	(0x800000)
		return func(s []byte) int {
			return int(int32(s[0])<<8 | int32(s[1])<<16 | int32(s[2])<<24)
			// ss := int32(s[0]) | int32(s[1])<<8 | int32(s[2])<<16
			// if (ss & 0x800000) > 0 {
			// 	ss |= ^0xffffff
			// }
			// return int(ss)
		}, nil
	case 32:
		return func(s []byte) int {
			return int(s[0]) + int(s[1])<<8 + int(s[2])<<16 + int(s[3])<<24
		}, nil
	default:
		return nil, fmt.Errorf("unhandled byte depth:%d", bitsPerSample)
	}
}
952352
func ExtractPercentileComputation(opts ...interface{}) *opt.PercentileComputationOption {
	for _, o := range opts {
		if v, ok := o.(*opt.PercentileComputationOption); ok {
			return v
		}
	}
	return nil
}
805492
func (s *DescribeRestoreJobOutput) SetPercentDone(v string) *DescribeRestoreJobOutput {
	s.PercentDone = &v
	return s
}
268239
func (s *DBClusterSnapshot) SetPercentProgress(v int64) *DBClusterSnapshot {
	s.PercentProgress = &v
	return s
}