// Compact performs garbage collection on a profile to remove any // unreferenced fields. This is useful to reduce the size of a profile // after samples or locations have been removed. func (p *Profile) Compact() *Profile { … } // Merge merges all the profiles in profs into a single Profile. // Returns a new profile independent of the input profiles. The merged // profile is compacted to eliminate unused samples, locations, // functions and mappings. Profiles must have identical profile sample // and period types or the merge will fail. profile.Period of the // resulting profile will be the maximum of all profiles, and // profile.TimeNanos will be the earliest nonzero one. Merges are // associative with the caveat of the first profile having some // specialization in how headers are combined. There may be other // subtleties now or in the future regarding associativity. func Merge(srcs []*Profile) (*Profile, error) { … } // Normalize normalizes the source profile by multiplying each value in profile by the // ratio of the sum of the base profile's values of that sample type to the sum of the // source profile's value of that sample type. func (p *Profile) Normalize(pb *Profile) error { … } func isZeroSample(s *Sample) bool { … } type profileMerger … type mapInfo … func (pm *profileMerger) mapSample(src *Sample) *Sample { … } func (pm *profileMerger) sampleKey(sample *Sample) sampleKey { … } type sampleKey … // sortedKeys1 returns the sorted keys found in a string->[]string map. // // Note: this is currently non-generic since github pprof runs golint, // which does not support generics. When that issue is fixed, it can // be merged with sortedKeys2 and made into a generic function. func sortedKeys1(m map[string][]string) []string { … } // sortedKeys2 returns the sorted keys found in a string->[]int64 map. // // Note: this is currently non-generic since github pprof runs golint, // which does not support generics. When that issue is fixed, it can // be merged with sortedKeys1 and made into a generic function. func sortedKeys2(m map[string][]int64) []string { … } func (pm *profileMerger) mapLocation(src *Location) *Location { … } // key generates locationKey to be used as a key for maps. func (l *Location) key() locationKey { … } type locationKey … func (pm *profileMerger) mapMapping(src *Mapping) mapInfo { … } // key generates encoded strings of Mapping to be used as a key for // maps. func (m *Mapping) key() mappingKey { … } type mappingKey … func (pm *profileMerger) mapLine(src Line) Line { … } func (pm *profileMerger) mapFunction(src *Function) *Function { … } // key generates a struct to be used as a key for maps. func (f *Function) key() functionKey { … } type functionKey … // combineHeaders checks that all profiles can be merged and returns // their combined profile. func combineHeaders(srcs []*Profile) (*Profile, error) { … } // compatible determines if two profiles can be compared/merged. // returns nil if the profiles are compatible; otherwise an error with // details on the incompatibility. func (p *Profile) compatible(pb *Profile) error { … } // equalValueType returns true if the two value types are semantically // equal. It ignores the internal fields used during encode/decode. func equalValueType(st1, st2 *ValueType) bool { … } type locationIDMap … func makeLocationIDMap(n int) locationIDMap { … } func (lm locationIDMap) get(id uint64) *Location { … } func (lm locationIDMap) set(id uint64, loc *Location) { … } // CompatibilizeSampleTypes makes profiles compatible to be compared/merged. It // keeps sample types that appear in all profiles only and drops/reorders the // sample types as necessary. // // In the case of sample types order is not the same for given profiles the // order is derived from the first profile. // // Profiles are modified in-place. // // It returns an error if the sample type's intersection is empty. func CompatibilizeSampleTypes(ps []*Profile) error { … } // commonSampleTypes returns sample types that appear in all profiles in the // order how they ordered in the first profile. func commonSampleTypes(ps []*Profile) []string { … } // 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. func compatibilizeSampleTypes(p *Profile, sTypes []string) error { … } func searchValueType(vts []*ValueType, s string) int { … }