Skip to content

Commit

Permalink
perffile: populate RecordSample.Weight with first weight
Browse files Browse the repository at this point in the history
For ease of use, if the perf file is using a weight struct, put the
first weight in the old Weight field.
  • Loading branch information
aclements committed Jul 11, 2022
1 parent 38280a4 commit 8e534be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion perffile/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ type RecordSample struct {
StackUser []byte // if SampleFormatStackUser
StackUserDynSize uint64 // if SampleFormatStackUser

Weight uint64 // if SampleFormatWeight
Weight uint64 // if SampleFormatWeight or SampleFormatWeightStruct
Weights Weights // if SampleFormatWeightStruct

DataSrc DataSrc // if SampleFormatDataSrc
Expand Down
4 changes: 3 additions & 1 deletion perffile/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ func (r *Records) parseSample(bd *bufDecoder, hdr *recordHeader, common *RecordC
o.Weight = bd.u64()
o.Weights = Weights{}
} else if t&SampleFormatWeightStruct != 0 {
o.Weight = 0
// N.B. the kernel memcpys the 64-bit union value regardless of
// format, so on big endian systems the fields appear in the
// opposite order. Read as a 64-bit value and extract the
Expand All @@ -602,6 +601,9 @@ func (r *Records) parseSample(bd *bufDecoder, hdr *recordHeader, common *RecordC
o.Weights.Var1 = uint32(weight)
o.Weights.Var2 = uint16(weight >> 32)
o.Weights.Var3 = uint16(weight >> 48)
// For ease of use, also put Var1 in Weight. If you
// only care about one weight, that's the one.
o.Weight = uint64(o.Weights.Var1)
}

if t&SampleFormatDataSrc != 0 {
Expand Down

0 comments on commit 8e534be

Please sign in to comment.