MCPcopy Create free account
hub / github.com/google/pprof / compatibilizeSampleTypes

Function compatibilizeSampleTypes

profile/merge.go:627–664  ·  view source on GitHub ↗

compatibilizeSampleTypes drops sample types that are not present in sTypes list and reorder them if needed. It sets DefaultSampleType to sType[0] if it is not in sType list. It assumes that all sample types from the sTypes list are present in the given profile otherwise it returns an error.

(p *Profile, sTypes []string)

Source from the content-addressed store, hash-verified

625// It assumes that all sample types from the sTypes list are present in the
626// given profile otherwise it returns an error.
627func compatibilizeSampleTypes(p *Profile, sTypes []string) error {
628 if len(sTypes) == 0 {
629 return fmt.Errorf("sample type list is empty")
630 }
631 defaultSampleType := sTypes[0]
632 reMap, needToModify := make([]int, len(sTypes)), false
633 for i, st := range sTypes {
634 if st == p.DefaultSampleType {
635 defaultSampleType = p.DefaultSampleType
636 }
637 idx := searchValueType(p.SampleType, st)
638 if idx < 0 {
639 return fmt.Errorf("%q sample type is not found in profile", st)
640 }
641 reMap[i] = idx
642 if idx != i {
643 needToModify = true
644 }
645 }
646 if !needToModify && len(sTypes) == len(p.SampleType) {
647 return nil
648 }
649 p.DefaultSampleType = defaultSampleType
650 oldSampleTypes := p.SampleType
651 p.SampleType = make([]*ValueType, len(sTypes))
652 for i, idx := range reMap {
653 p.SampleType[i] = oldSampleTypes[idx]
654 }
655 values := make([]int64, len(sTypes))
656 for _, s := range p.Sample {
657 for i, idx := range reMap {
658 values[i] = s.Value[idx]
659 }
660 s.Value = s.Value[:len(values)]
661 copy(s.Value, values)
662 }
663 return nil
664}
665
666func searchValueType(vts []*ValueType, s string) int {
667 for i, vt := range vts {

Callers 1

CompatibilizeSampleTypesFunction · 0.85

Calls 1

searchValueTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…