-
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.
Browse files
Browse the repository at this point in the history
…ry-increase-workaround workaround upstream inlining issue
- Loading branch information
Showing
8 changed files
with
126 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,10 @@ N/A,github.com/mattn/go-isatty,MIT,Copyright (c) Yasuhiro MATSUMOTO <mattn.jp@gm | |
N/A,github.com/sourcegraph/conc,MIT,Copyright (c) 2023 Sourcegraph | ||
N/A,go.uber.org/atomic,MIT,Copyright (c) 2016 Uber Technologies, Inc. | ||
N/A,go.uber.org/multierr,MIT,Copyright (c) 2017-2021 Uber Technologies, Inc. | ||
N/A,golang.org/x/sys,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. | ||
N/A,golang.org/x/sys,BSD-3-Clause,Copyright (c) 2009 The Go Authors. All rights reserved. | ||
N/A,github.com/stretchr/testify,MIT,Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors. | ||
N/A,github.com/davecgh/go-spew,ISC,Copyright (c) 2012-2016 Dave Collins <[email protected]> | ||
N/A,github.com/kr/text,MIT,Copyright 2012 Keith Rarick | ||
N/A,github.com/pmezard/go-difflib,BSD 3-Clause,Copyright (c) 2013, Patrick Mezard | ||
N/A,gopkg.in/yaml.v3,MIT,Copyright (c) 2006-2010 Kirill Simonov + Copyright (c) 2006-2011 Kirill Simonov | ||
N/A,gopkg.in/yaml.v3,Apache-2.0,Copyright (c) 2011-2019 Canonical Ltd |
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
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,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/pprof/profile" | ||
) | ||
|
||
const grpcProcessDataFunc = "google.golang.org/grpc/internal/transport.(*loopyWriter).processData" | ||
|
||
// ApplyNoInlineHack 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 ApplyNoInlineHack(prof *profile.Profile) error { | ||
if err := removeLeafSamples(prof, []string{grpcProcessDataFunc}); err != nil { | ||
return fmt.Errorf("noinline hack: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
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 TestApplyNoInlineHack(t *testing.T) { | ||
prof := loadTestProfile(t, "grpc-anon.pprof") | ||
require.Equal(t, 17, leafSamples(prof, grpcProcessDataFunc)) | ||
require.NoError(t, ApplyNoInlineHack(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.