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

Method Normalize

profile/merge.go:94–124  ·  view source on GitHub ↗

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.

(pb *Profile)

Source from the content-addressed store, hash-verified

92// ratio of the sum of the base profile's values of that sample type to the sum of the
93// source profile's value of that sample type.
94func (p *Profile) Normalize(pb *Profile) error {
95
96 if err := p.compatible(pb); err != nil {
97 return err
98 }
99
100 baseVals := make([]int64, len(p.SampleType))
101 for _, s := range pb.Sample {
102 for i, v := range s.Value {
103 baseVals[i] += v
104 }
105 }
106
107 srcVals := make([]int64, len(p.SampleType))
108 for _, s := range p.Sample {
109 for i, v := range s.Value {
110 srcVals[i] += v
111 }
112 }
113
114 normScale := make([]float64, len(baseVals))
115 for i := range baseVals {
116 if srcVals[i] == 0 {
117 normScale[i] = 0.0
118 } else {
119 normScale[i] = float64(baseVals[i]) / float64(srcVals[i])
120 }
121 }
122 p.ScaleN(normScale)
123 return nil
124}
125
126func isZeroSample(s *Sample) bool {
127 for _, v := range s.Value {

Calls 2

compatibleMethod · 0.95
ScaleNMethod · 0.95