Skip to content

Commit

Permalink
profiler: fix goroutineswait profile frame order (#850)
Browse files Browse the repository at this point in the history
The frames were showing up in reverse in the UI. Not sure why I wrote
the code to prepend instead of append the frames, but it's wrong and
this patch fixes it.

Fixes PROF-2908
  • Loading branch information
felixge committed Feb 18, 2021
1 parent 31e491e commit 8026b33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion profiler/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func goroutineDebug2ToPprof(r io.Reader, w io.Writer, t time.Time) (err error) {
p.Location = append(p.Location, location)
locationID++

sample.Location = append([]*pprofile.Location{location}, sample.Location...)
sample.Location = append(sample.Location, location)
}

p.Sample = append(p.Sample, sample)
Expand Down
20 changes: 18 additions & 2 deletions profiler/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ main.main()
// pro tip: enable line below to inspect the pprof output using cli tools
// ioutil.WriteFile(prof.name, prof.data, 0644)

requireFunctions := func(t *testing.T, s *pprofile.Sample, want []string) {
t.Helper()
var got []string
for _, loc := range s.Location {
got = append(got, loc.Line[0].Function.Name)
}
require.Equal(t, want, got)
}

pp, err := pprofile.Parse(bytes.NewReader(prof.data))
require.NoError(t, err)
// timestamp
Expand All @@ -146,9 +155,16 @@ main.main()
require.Equal(t, []int64{3}, pp.Sample[1].NumLabel["goid"])
require.Equal(t, []string{"id"}, pp.Sample[1].NumUnit["goid"])
// Virtual frame for "frames elided" goroutine
require.Equal(t, 3, len(pp.Sample[2].Location))
requireFunctions(t, pp.Sample[2], []string{
"main.stackDump",
"main.main",
"...additional frames elided...",
})
// Virtual frame go "created by" frame
require.Equal(t, 2, len(pp.Sample[1].Location))
requireFunctions(t, pp.Sample[1], []string{
"time.Sleep",
"main.indirectShortSleepLoop2",
})
})
}

Expand Down

0 comments on commit 8026b33

Please sign in to comment.