Skip to content

Commit 2cb3ce0

Browse files
committed
cmd/compile/internal/pgo: fix hard-coded PGO sample data position
This patch detects at which index position profiling samples that have the value-type samples count are, instead of the previously hard-coded position of index 1. Runtime generated profiles always generate CPU profiling data with the 0 index being CPU nanoseconds, and samples count at index 1, which is why this previously hasn't come up. Fixes #58292
1 parent 2f2c5e4 commit 2cb3ce0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/cmd/compile/internal/pgo/irgraph.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,22 @@ func New(profileFile string) *Profile {
140140
return nil
141141
}
142142

143+
samplesCountIndex := -1
144+
for i, s := range profile.SampleType {
145+
if s.Type == "samples" && s.Unit == "count" {
146+
samplesCountIndex = i
147+
break
148+
}
149+
}
150+
151+
if samplesCountIndex == -1 {
152+
log.Fatal("failed to find CPU samples count value-type in profile.")
153+
return nil
154+
}
155+
143156
g := newGraph(profile, &Options{
144157
CallTree: false,
145-
SampleValue: func(v []int64) int64 { return v[1] },
158+
SampleValue: func(v []int64) int64 { return v[samplesCountIndex] },
146159
})
147160

148161
p := &Profile{

0 commit comments

Comments
 (0)