-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/pprof/profile" | ||
) | ||
|
||
const grpcProcessDataFunc = "google.golang.org/grpc/internal/transport.(*loopyWriter).processData" | ||
|
||
// NoInlineHack removes problematic samples from the profile to avoid bad | ||
// inlining decisions that can have a large memory impact. | ||
// See https://github.com/golang/go/issues/65532 for details. | ||
// | ||
// TODO: Delete this once it's fixed upstream. | ||
func NoInlineHack(prof *profile.Profile) error { | ||
return removeLeafSamples(prof, []string{grpcProcessDataFunc}) | ||
} | ||
|
||
func removeLeafSamples(prof *profile.Profile, funcs []string) error { | ||
newSamples := make([]*profile.Sample, 0, len(prof.Sample)) | ||
for _, s := range prof.Sample { | ||
leaf, ok := leafLine(s) | ||
if ok && lineContainsAny(leaf, funcs) { | ||
continue | ||
} | ||
newSamples = append(newSamples, s) | ||
} | ||
prof.Sample = newSamples | ||
return nil | ||
} | ||
|
||
func leafLine(s *profile.Sample) (profile.Line, bool) { | ||
if len(s.Location) == 0 || len(s.Location[0].Line) == 0 { | ||
return profile.Line{}, false | ||
} | ||
return s.Location[0].Line[0], true | ||
} | ||
|
||
func lineContainsAny(leaf profile.Line, funcs []string) bool { | ||
for _, fn := range funcs { | ||
if leaf.Function.Name == fn { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/google/pprof/profile" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNoInline(t *testing.T) { | ||
prof := loadTestProfile(t, "grpc-anon.pprof") | ||
require.Equal(t, 17, leafSamples(prof, grpcProcessDataFunc)) | ||
require.NoError(t, NoInlineHack(prof)) | ||
require.Equal(t, 0, leafSamples(prof, grpcProcessDataFunc)) | ||
} | ||
|
||
func loadTestProfile(t *testing.T, name string) *profile.Profile { | ||
t.Helper() | ||
data, err := os.ReadFile(filepath.Join("testdata", name)) | ||
require.NoError(t, err) | ||
prof, err := profile.ParseData(data) | ||
require.NoError(t, err) | ||
return prof | ||
} | ||
|
||
func leafSamples(prof *profile.Profile, fn string) (count int) { | ||
for _, s := range prof.Sample { | ||
leaf, ok := leafLine(s) | ||
if ok && leaf.Function.Name == fn { | ||
count++ | ||
} | ||
} | ||
return count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
``` | ||
pprofutils anon -whitelist='^google\.golang\.org/grpc' grpc-orig.pprof grpc-anon.pprof | ||
``` |
Binary file not shown.