// WithSampler allows one to add a Sampler function
331554
func WithSampler(sampler Sampler) TracerOption {
	return func(opts *TracerOptions) error {
		opts.shouldSample = sampler
		return nil
	}
}
904806
func (s RandomSampler) Sample(lvl Level) bool {
	if s <= 0 {
		return false
	}
	if rand.Intn(int(s)) != 0 {
		return false
	}
	return true
}
965094
func (c *SampleCollector) MergeSampleCollector(sc *stmtctx.StatementContext, rc *SampleCollector) {
	c.NullCount += rc.NullCount
	c.Count += rc.Count
	c.TotalSize += rc.TotalSize
	c.FMSketch.mergeFMSketch(rc.FMSketch)
	if rc.CMSketch != nil {
		err := c.CMSketch.MergeCMSketch(rc.CMSketch)
		terror.Log(errors.Trace(err))
	}
	for _, item := range rc.Samples {
		err := c.collect(sc, item.Value)
		terror.Log(errors.Trace(err))
	}
}
854475
func (samplerOptions) SamplingServerURL(samplingServerURL string) SamplerOption {
	return func(o *samplerOptions) {
		o.samplingServerURL = samplingServerURL
	}
}
1037780
func NewCountingSampler(rate float64) Sampler {
	if rate <= 0 {
		return neverSample
	}
	if rate >= 1.0 {
		return alwaysSample
	}
	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()
		defer mtx.Unlock()
		result := decisions[i]
		i++
		if i == 100 {
			i = 0
		}
		return result
	}
}
517162
func WithTracer(tracer opentracing.Tracer) Option {
	return func(o *options) {
		o.tracer = tracer
	}
}
591452
func (a *AvgSampleWithMin) GetSampleRate(key string) int {
	a.lock.Lock()
	defer a.lock.Unlock()
	a.currentCounts[key]++
	if !a.haveData {
		return a.GoalSampleRate
	}
	if rate, found := a.savedSampleRates[key]; found {
		return rate
	}
	return 1
}
384368
func (samplerOptions) InitialSampler(sampler Sampler) SamplerOption {
	return func(o *samplerOptions) {
		o.sampler = sampler
	}
}
741616
func (s *GetTraceSummariesInput) SetSampling(v bool) *GetTraceSummariesInput {
	s.Sampling = &v
	return s
}
837512
func NewSampleQueryBuilderWithKind(kind string) *SampleQueryBuilder {
	q := datastore.NewQuery(kind)
	bldr := &SampleQueryBuilder{q: q}
	bldr.Kind = &SampleQueryProperty{
		bldr: bldr,
		name: "Kind",
	}
	bldr.Foo = &SampleQueryProperty{
		bldr: bldr,
		name: "Foo",
	}

	if plugger, ok := interface{}(bldr).(Plugger); ok {
		bldr.plugin = plugger.Plugin()
		bldr.plugin.Init("Sample")
	}

	return bldr
}
767008
func CreateDefaultGetSamples(names ...string) GetSamplesInteractor {
	var samples []*SampleEntity
	for _, item := range names {
		samples = append(samples, &SampleEntity{
			ID:   uuid.NewV4().String(),
			Name: item,
		})
	}
	return GetSamplesInteractorImpl{Samples: samples}
}
659254
func (builder *StoreBucketTypePropsCommandBuilder) WithR(r uint32) *StoreBucketTypePropsCommandBuilder {
	builder.props.R = &r
	return builder
}
120513
func (w *Waveform) setSampleFunction(function SampleReduceFunc) error {
	// Function cannot be nil
	if function == nil {
		return errSampleFunctionNil
	}

	w.sampleFn = function

	return nil
}
1124442
func focusedSample(s *Sample, focus, ignore TagMatch) (fm, im bool) {
	fm = focus == nil
	for key, vals := range s.Label {
		for _, val := range vals {
			if ignore != nil && ignore(key, val, 0) {
				im = true
			}
			if !fm && focus(key, val, 0) {
				fm = true
			}
		}
	}
	for key, vals := range s.NumLabel {
		for _, val := range vals {
			if ignore != nil && ignore(key, "", val) {
				im = true
			}
			if !fm && focus(key, "", val) {
				fm = true
			}
		}
	}
	return fm, im
}
1320967
func SampleCollectorFromProto(collector *tipb.SampleCollector) *SampleCollector {
	s := &SampleCollector{
		NullCount: collector.NullCount,
		Count:     collector.Count,
		FMSketch:  FMSketchFromProto(collector.FmSketch),
	}
	if collector.TotalSize != nil {
		s.TotalSize = *collector.TotalSize
	}
	s.CMSketch = CMSketchFromProto(collector.CmSketch)
	for _, val := range collector.Samples {
		// When store the histogram bucket boundaries to kv, we need to limit the length of the value.
		if len(val) <= maxSampleValueLength {
			item := &SampleItem{Value: types.NewBytesDatum(val)}
			s.Samples = append(s.Samples, item)
		}
	}
	return s
}
77210
func (w *Writer) WriteSample(sample []byte) error {
	if len(sample)*8 != int(w.options.SignificantBits) {
		return fmt.Errorf("incorrect Sample Length %d", len(sample))
	}

	n, err := w.sampleBuf.Write(sample)
	if err != nil {
		return err
	}

	w.bytesWritten += n

	return nil
}
1319855
func (l Logger) Sample(s Sampler) Logger {
	l.sampler = s
	return l
}