// parseContentionSample parses a single row from a contention profile
// into a new Sample.
183493
func parseContentionSample(line string, period, cpuHz int64) (value []int64, addrs []uint64, err error) {
	sampleData := contentionSampleRE.FindStringSubmatch(line)
	if sampleData == nil {
		return nil, nil, errUnrecognized
	}

	v1, err := strconv.ParseInt(sampleData[1], 10, 64)
	if err != nil {
		return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
	}
	v2, err := strconv.ParseInt(sampleData[2], 10, 64)
	if err != nil {
		return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
	}

	// Unsample values if period and cpuHz are available.
	// - Delays are scaled to cycles and then to nanoseconds.
	// - Contentions are scaled to cycles.
	if period > 0 {
		if cpuHz > 0 {
			cpuGHz := float64(cpuHz) / 1e9
			v1 = int64(float64(v1) * float64(period) / cpuGHz)
		}
		v2 = v2 * period
	}

	value = []int64{v2, v1}
	addrs, err = parseHexAddresses(sampleData[3])
	if err != nil {
		return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
	}

	return value, addrs, nil
}
161217
func (s *sampleLister) Samples(namespace string) SampleNamespaceLister {
	return sampleNamespaceLister{indexer: s.indexer, namespace: namespace}
}
82675
func NewExampleInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
	return NewFilteredExampleInformer(client, namespace, resyncPeriod, indexers, nil)
}
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
}
246956
func ParseInstanceGroupRole(input string, lenient bool) (InstanceGroupRole, bool) {
	findRole := strings.ToLower(input)
	if lenient {
		// Accept pluralized "bastions" for "bastion"
		findRole = strings.TrimSuffix(findRole, "s")
	}

	for _, role := range AllInstanceGroupRoles {
		s := string(role)
		s = strings.ToLower(s)
		if lenient {
			s = strings.TrimSuffix(s, "s")
		}
		if s == findRole {
			return role, true
		}
	}
	return "", false
}
638546
func (c *Clientset) SecondExample() secondexampleinternalversion.SecondExampleInterface {
	return &fakesecondexampleinternalversion.FakeSecondExample{Fake: &c.Fake}
}
66877
func NewSampleJSONBuilder() *SampleJSONBuilder {
	jb := &SampleJSONBuilder{
		_properties:        map[string]*SamplePropertyInfo{},
		_jsonPropertyMap:   map[string]*SamplePropertyInfo{},
		_structPropertyMap: map[string]*SamplePropertyInfo{},
		A: &SamplePropertyInfo{
			fieldName: "A",
			jsonName:  "foo!",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
		},
		B: &SamplePropertyInfo{
			fieldName: "B",
			jsonName:  "b",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
		},
		C: &SamplePropertyInfo{
			fieldName: "C",
			jsonName:  "c",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.C = src.C
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.C = src.C
				return nil
			},
		},
		D: &SamplePropertyInfo{
			fieldName: "D",
			jsonName:  "d",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.D = src.D
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.D = src.D
				return nil
			},
		},
		F: &SamplePropertyInfo{
			fieldName: "F",
			jsonName:  "f",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.F = src.F
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.F = src.F
				return nil
			},
		},
		G: &SamplePropertyInfo{
			fieldName: "G",
			jsonName:  "g",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.G = src.G
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.G = src.G
				return nil
			},
		},
	}
	jb._structPropertyMap["A"] = jb.A
	jb._jsonPropertyMap["foo!"] = jb.A
	jb._structPropertyMap["B"] = jb.B
	jb._jsonPropertyMap["b"] = jb.B
	jb._structPropertyMap["C"] = jb.C
	jb._jsonPropertyMap["c"] = jb.C
	jb._structPropertyMap["D"] = jb.D
	jb._jsonPropertyMap["d"] = jb.D
	jb._structPropertyMap["F"] = jb.F
	jb._jsonPropertyMap["f"] = jb.F
	jb._structPropertyMap["G"] = jb.G
	jb._jsonPropertyMap["g"] = jb.G
	return jb
}
692007
func (d *Decoder) decodeSamples2() error {
	for gr := 0; gr < 12; gr++ {
		for sb := 0; sb < 32; sb++ {
			nch := d.nChannels
			if sb >= d.bound {
				nch = 1
			}

			for ch := 0; ch < nch; ch++ {
				if alloc := d.allocation[ch][sb]; alloc > 0 {
					for s := 0; s < 3; s++ {
						sample, err := d.stream.readBits(alloc)
						if err != nil {
							return err
						}
						d.sample[ch][32*(3*gr+s)+sb] = float32(sample)
					}
				} else if alloc < 0 {
					sample, err := d.stream.readBits(-alloc)
					if err != nil {
						return err
					}
					nLevels := levelsPerGroupedSample[-alloc]
					d.sample[ch][32*(3*gr+0)+sb] = float32(sample % nLevels)
					sample /= nLevels
					d.sample[ch][32*(3*gr+1)+sb] = float32(sample % nLevels)
					d.sample[ch][32*(3*gr+2)+sb] = float32(sample / nLevels)
				}
			}
		}

		for sb := d.bound; sb < 32; sb++ {
			d.sample[1][32*(3*gr+0)+sb] = d.sample[0][32*(3*gr+0)+sb]
			d.sample[1][32*(3*gr+1)+sb] = d.sample[0][32*(3*gr+1)+sb]
			d.sample[1][32*(3*gr+2)+sb] = d.sample[0][32*(3*gr+2)+sb]
		}
	}

	return nil
}
499033
func (s fixedSampler) Sample() bool {
	samplingPercent := int(s)
	return samplingPercent > 0 && (samplingPercent == 100 || rand.Intn(100) < samplingPercent)
}
715678
func NewSampleQueryBuilderWithKind(kind string) *SampleQueryBuilder {
	q := datastore.NewQuery(kind)
	bldr := &SampleQueryBuilder{q: q}
	bldr.ID = &SampleQueryProperty{
		bldr: bldr,
		name: "__key__",
	}
	bldr.FooUrl = &SampleQueryProperty{
		bldr: bldr,
		name: "FooURL",
	}
	bldr.StartAt = &SampleQueryProperty{
		bldr: bldr,
		name: "Start",
	}
	bldr.LimitProperty = &SampleQueryProperty{
		bldr: bldr,
		name: "Limit",
	}
	bldr.CreatedAt = &SampleQueryProperty{
		bldr: bldr,
		name: "CreatedAt",
	}

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

	return bldr
}
1244708
func SampleMax(values []int64) int64 {
	if 0 == len(values) {
		return 0
	}
	var max int64 = math.MinInt64
	for _, v := range values {
		if max < v {
			max = v
		}
	}
	return max
}
940118
func (s *GetIntentOutput) SetSampleUtterances(v []*string) *GetIntentOutput {
	s.SampleUtterances = v
	return s
}
477733
func (s *PutIntentOutput) SetSampleUtterances(v []*string) *PutIntentOutput {
	s.SampleUtterances = v
	return s
}
919879
func (sfx *SignalFxSink) FlushOtherSamples(ctx context.Context, samples []ssf.SSFSample) {
	span, _ := trace.StartSpanFromContext(ctx, "")
	defer span.ClientFinish(sfx.traceClient)
	var countFailed = 0
	var countSuccess = 0
	for _, sample := range samples {
		if _, ok := sample.Tags[dogstatsd.EventIdentifierKey]; ok {
			err := sfx.reportEvent(ctx, &sample)
			if err != nil {
				countFailed++
			} else {
				countSuccess++
			}
		}
	}
	if countSuccess > 0 {
		span.Add(ssf.Count(sinks.EventReportedCount, float32(countSuccess), successSpanTags))
	}
	if countFailed > 0 {
		span.Add(ssf.Count(sinks.EventReportedCount, float32(countFailed), failureSpanTags))
	}
}
110178
func Sample(population []interface{}, k int) (res []interface{}, err error) {
	n := len(population)
	idxs, err := SampleInts(n, k)
	if err != nil {
		return
	}

	res = []interface{}{}
	for _, idx := range idxs {
		res = append(res, population[idx])
	}

	return
}
741490
func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) (model.Vector, error) {
	var (
		all     model.Vector
		lastErr error
	)
	for _, f := range fams {
		some, err := extractSamples(f, o)
		if err != nil {
			lastErr = err
			continue
		}
		all = append(all, some...)
	}
	return all, lastErr
}
426174
func (tid *TemplateInstanceData) Parse(reader io.ReadSeeker) error {
	err := encoding.Unmarshal(reader, &tid.NumValues, Endianness)
	if err != nil {
		return err
	}
	if tid.NumValues < 0 {
		return fmt.Errorf("Negative number of values in TemplateInstanceData")
	}
	// Cannot definitely not be bigger than MaxSliceSize
	if tid.NumValues > MaxSliceSize {
		return fmt.Errorf("Too many values in TemplateInstanceData")
	}
	// We can now allocate process the values
	tid.Values = make([]Element, tid.NumValues)
	tid.ValueOffsets = make([]int32, tid.NumValues)
	tid.ValDescs = make([]ValueDescriptor, tid.NumValues)
	if tid.NumValues > 0 {
		err = encoding.UnmarshaInitSlice(reader, &tid.ValDescs, Endianness)
		if err != nil {
			return err
		}
	}

	// Parse the values
	for i := int32(0); i < tid.NumValues; i++ {
		tid.Values[i], err = ParseValueReader(tid.ValDescs[i], reader)
		if err != nil {
			log.Errorf("%v : %s", tid.ValDescs[i], err)
			log.DebugDontPanicf("%v : %s", tid.ValDescs[i], err)
		}
	}
	return err
}