aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2023-02-08 18:48:17 +0000
committerGopher Robot <gobot@golang.org>2023-02-08 19:06:56 +0000
commitbb6952fa25da050d04c2df3787fa0d508adb9b1a (patch)
tree15784e87a6e7c32a45c427bdad41863f4870bca4
parentda9376604309b8c470985b8d517a2377cfa56efe (diff)
downloadgo-bb6952fa25da050d04c2df3787fa0d508adb9b1a.tar.xz
Revert "cmd/compile/internal/pgo: fix hard-coded PGO sample data position"
This reverts CL 465135. Reason for revert: This broke cmd/go.TestScript/build_pgo on the linux-amd64-longtest builder: https://build.golang.org/log/8f8ed7bf576f891a06d295c4a5bca987c6e941d6 Change-Id: Ie2f2cc2731099eb28eda6b94dded4dfc34e29441 Reviewed-on: https://go-review.googlesource.com/c/go/+/466439 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
-rw-r--r--src/cmd/compile/internal/pgo/irgraph.go18
-rw-r--r--src/cmd/compile/internal/test/pgo_inl_test.go68
2 files changed, 1 insertions, 85 deletions
diff --git a/src/cmd/compile/internal/pgo/irgraph.go b/src/cmd/compile/internal/pgo/irgraph.go
index a0319f3962..ca9e2f3b5a 100644
--- a/src/cmd/compile/internal/pgo/irgraph.go
+++ b/src/cmd/compile/internal/pgo/irgraph.go
@@ -140,25 +140,9 @@ func New(profileFile string) *Profile {
return nil
}
- samplesCountIndex := -1
- for i, s := range profile.SampleType {
- // Samples count is the raw data collected, and CPU nanoseconds is just
- // a scaled version of it, so either one we can find is fine.
- if (s.Type == "samples" && s.Unit == "count") ||
- (s.Type == "cpu" && s.Unit == "nanoseconds") {
- samplesCountIndex = i
- break
- }
- }
-
- if samplesCountIndex == -1 {
- log.Fatal("failed to find CPU samples count or CPU nanoseconds value-types in profile.")
- return nil
- }
-
g := newGraph(profile, &Options{
CallTree: false,
- SampleValue: func(v []int64) int64 { return v[samplesCountIndex] },
+ SampleValue: func(v []int64) int64 { return v[1] },
})
p := &Profile{
diff --git a/src/cmd/compile/internal/test/pgo_inl_test.go b/src/cmd/compile/internal/test/pgo_inl_test.go
index 4d6b5a134a..2f6391fded 100644
--- a/src/cmd/compile/internal/test/pgo_inl_test.go
+++ b/src/cmd/compile/internal/test/pgo_inl_test.go
@@ -7,7 +7,6 @@ package test
import (
"bufio"
"fmt"
- "internal/profile"
"internal/testenv"
"io"
"os"
@@ -214,73 +213,6 @@ func TestPGOIntendedInliningShiftedLines(t *testing.T) {
testPGOIntendedInlining(t, dir)
}
-// TestPGOSingleIndex tests that the sample index can not be 1 and compilation
-// will not fail. All it should care about is that the sample type is either
-// CPU nanoseconds or samples count, whichever it finds first.
-func TestPGOSingleIndex(t *testing.T) {
- for _, tc := range []struct {
- originalIndex int
- }{{
- // The `testdata/pgo/inline/inline_hot.pprof` file is a standard CPU
- // profile as the runtime would generate. The 0 index contains the
- // value-type samples and value-unit count. The 1 index contains the
- // value-type cpu and value-unit nanoseconds. These tests ensure that
- // the compiler can work with profiles that only have a single index,
- // but are either samples count or CPU nanoseconds.
- originalIndex: 0,
- }, {
- originalIndex: 1,
- }} {
- t.Run(fmt.Sprintf("originalIndex=%d", tc.originalIndex), func(t *testing.T) {
- wd, err := os.Getwd()
- if err != nil {
- t.Fatalf("error getting wd: %v", err)
- }
- srcDir := filepath.Join(wd, "testdata/pgo/inline")
-
- // Copy the module to a scratch location so we can add a go.mod.
- dir := t.TempDir()
-
- originalPprofFile, err := os.Open(filepath.Join(srcDir, "inline_hot.pprof"))
- if err != nil {
- t.Fatalf("error opening inline_hot.pprof: %v", err)
- }
- defer originalPprofFile.Close()
-
- p, err := profile.Parse(originalPprofFile)
- if err != nil {
- t.Fatalf("error parsing inline_hot.pprof: %v", err)
- }
-
- // Move the samples count value-type to the 0 index.
- p.SampleType = []*profile.ValueType{p.SampleType[tc.originalIndex]}
-
- // Ensure we only have a single set of sample values.
- for _, s := range p.Sample {
- s.Value = []int64{s.Value[tc.originalIndex]}
- }
-
- modifiedPprofFile, err := os.Create(filepath.Join(dir, "inline_hot.pprof"))
- if err != nil {
- t.Fatalf("error creating inline_hot.pprof: %v", err)
- }
- defer modifiedPprofFile.Close()
-
- if err := p.Write(modifiedPprofFile); err != nil {
- t.Fatalf("error writing inline_hot.pprof: %v", err)
- }
-
- for _, file := range []string{"inline_hot.go", "inline_hot_test.go"} {
- if err := copyFile(filepath.Join(dir, file), filepath.Join(srcDir, file)); err != nil {
- t.Fatalf("error copying %s: %v", file, err)
- }
- }
-
- testPGOIntendedInlining(t, dir)
- })
- }
-}
-
func copyFile(dst, src string) error {
s, err := os.Open(src)
if err != nil {