| 1 |
// Copyright 2017 Google Inc. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/ |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 19 |
"osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 20 |
"path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 21 |
"regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 22 |
"runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/" |
| 23 |
"stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 24 |
"testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 25 |
|
| 26 |
"github.com/google/pprof/internal/binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/" |
| 27 |
"github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/" |
| 28 |
) |
| 29 |
|
| 30 |
func TestWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TestWebList().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| •31 |
t.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Skip().("https://github.com/google/pprof/issues/650") |
| 32 |
if runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.24.0 runtime/GOOS. != "linux" || runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/.GOARCHscip-go gomod github.com/golang/go/src go1.24.0 runtime/GOARCH. != "amd64" { |
| 33 |
t.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Skip().("weblist only tested on x86-64 linux") |
| 34 |
} |
| 35 |
|
| 36 |
cpu := readProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/readProfile().(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().("testdata", "sample.cpu"), t) |
| 37 |
rpt := Newscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/New().(cpu, &Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#{ |
| 38 |
OutputFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#OutputFormat.: WebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebList., |
| 39 |
Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol.: regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().("busyLoop"), |
| 40 |
SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleValue.: func(v []int64) int64 { return v[1] }, |
| 41 |
SampleUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleUnit.: cpu.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[1].Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit., |
| 42 |
}) |
| 43 |
result, err := MakeWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/MakeWebList().(rpt, &binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/.Binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/Binutils#{}, -1) |
| 44 |
if err != nil { |
| 45 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("could not generate weblist: %v", err) |
| 46 |
} |
| 47 |
output := fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(result) |
| 48 |
|
| 49 |
for _, expect := range []string{"func busyLoop", "call.*mapassign"} { |
| 50 |
if match, _ := regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/MatchString().(expect, output); !match { |
| 51 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("weblist output does not contain '%s':\n%s", expect, output) |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
func TestSourceSyntheticAddressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TestSourceSyntheticAddress().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 57 |
testSourceMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/testSourceMapping().(t, true) |
| 58 |
} |
| 59 |
|
| 60 |
func TestSourceMissingMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TestSourceMissingMapping().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 61 |
testSourceMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/testSourceMapping().(t, false) |
| 62 |
} |
| 63 |
|
| 64 |
// testSourceMapping checks that source info is found even when no applicable |
| 65 |
// Mapping/objectFile exists. The locations used in the test are either zero |
| 66 |
// (if zeroAddress is true), or non-zero (otherwise). |
| 67 |
func testSourceMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/testSourceMapping().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, zeroAddress bool) { |
| 68 |
nextAddr := uint64(0) |
| 69 |
|
| 70 |
makeLoc := func(name, fname string, line int64) *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# { |
| 71 |
if !zeroAddress { |
| 72 |
nextAddr++ |
| 73 |
} |
| 74 |
return &profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{ |
| 75 |
Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: nextAddr, |
| 76 |
Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.: []profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#{ |
| 77 |
{ |
| 78 |
Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: &profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: name, Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: fname}, |
| 79 |
Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.: line, |
| 80 |
}, |
| 81 |
}, |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
// Create profile that will need synthetic addresses since it has no mappings. |
| 86 |
foo100 := makeLoc("foo", "foo.go", 100) |
| 87 |
bar50 := makeLoc("bar", "bar.go", 50) |
| 88 |
prof := &profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{ |
| 89 |
Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.: []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{ |
| 90 |
{ |
| 91 |
Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{9}, |
| 92 |
Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{foo100, bar50}, |
| 93 |
}, |
| 94 |
{ |
| 95 |
Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{17}, |
| 96 |
Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{bar50}, |
| 97 |
}, |
| 98 |
}, |
| 99 |
} |
| 100 |
rpt := &Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#{ |
| 101 |
profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#prof.: prof, |
| 102 |
optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#options.: &Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#{ |
| 103 |
Symbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#Symbol.: regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().("foo|bar"), |
| 104 |
SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Options#SampleValue.: func(s []int64) int64 { return s[0] }, |
| 105 |
}, |
| 106 |
formatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#formatValue.: func(v int64) string { return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(v) }, |
| 107 |
} |
| 108 |
|
| 109 |
result, err := MakeWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/MakeWebList().(rpt, nil, -1) |
| 110 |
if err != nil { |
| 111 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("MakeWebList returned unexpected error: %v", err) |
| 112 |
} |
| 113 |
got := fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(result) |
| 114 |
|
| 115 |
expect := regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().( |
| 116 |
`(?s)` + // Allow "." to match newline |
| 117 |
`bar\.go.* 50\b.* 17 +26 .*` + |
| 118 |
`foo\.go.* 100\b.* 9 +9 `) |
| 119 |
if !expect.MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(got) { |
| 120 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("expected regular expression %v does not match output:\n%s\n", expect, got) |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
func TestOpenSourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TestOpenSourceFile().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 125 |
tempdir, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.MkdirTempscip-go gomod github.com/golang/go/src go1.24.0 os/MkdirTemp().("", "") |
| 126 |
if err != nil { |
| 127 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("failed to create temp dir: %v", err) |
| 128 |
} |
| 129 |
const lsep = string(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.ListSeparatorscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/ListSeparator.) |
| 130 |
for _, tc := range []struct { |
| 131 |
desc string |
| 132 |
searchPath string |
| 133 |
trimPath string |
| 134 |
fs []string |
| 135 |
path string |
| 136 |
wantPath string // If empty, error is wanted. |
| 137 |
}{ |
| 138 |
{ |
| 139 |
desc: "exact absolute path is found", |
| 140 |
fs: []string{"foo/bar.cc"}, |
| 141 |
path: "$dir/foo/bar.cc", |
| 142 |
wantPath: "$dir/foo/bar.cc", |
| 143 |
}, |
| 144 |
{ |
| 145 |
desc: "exact relative path is found", |
| 146 |
searchPath: "$dir", |
| 147 |
fs: []string{"foo/bar.cc"}, |
| 148 |
path: "foo/bar.cc", |
| 149 |
wantPath: "$dir/foo/bar.cc", |
| 150 |
}, |
| 151 |
{ |
| 152 |
desc: "multiple search path", |
| 153 |
searchPath: "some/path" + lsep + "$dir", |
| 154 |
fs: []string{"foo/bar.cc"}, |
| 155 |
path: "foo/bar.cc", |
| 156 |
wantPath: "$dir/foo/bar.cc", |
| 157 |
}, |
| 158 |
{ |
| 159 |
desc: "relative path is found in parent dir", |
| 160 |
searchPath: "$dir/foo/bar", |
| 161 |
fs: []string{"bar.cc", "foo/bar/baz.cc"}, |
| 162 |
path: "bar.cc", |
| 163 |
wantPath: "$dir/bar.cc", |
| 164 |
}, |
| 165 |
{ |
| 166 |
desc: "trims configured prefix", |
| 167 |
searchPath: "$dir", |
| 168 |
trimPath: "some-path" + lsep + "/some/remote/path", |
| 169 |
fs: []string{"my-project/foo/bar.cc"}, |
| 170 |
path: "/some/remote/path/my-project/foo/bar.cc", |
| 171 |
wantPath: "$dir/my-project/foo/bar.cc", |
| 172 |
}, |
| 173 |
{ |
| 174 |
desc: "trims heuristically", |
| 175 |
searchPath: "$dir/my-project", |
| 176 |
fs: []string{"my-project/foo/bar.cc"}, |
| 177 |
path: "/some/remote/path/my-project/foo/bar.cc", |
| 178 |
wantPath: "$dir/my-project/foo/bar.cc", |
| 179 |
}, |
| 180 |
{ |
| 181 |
desc: "error when not found", |
| 182 |
path: "foo.cc", |
| 183 |
}, |
| 184 |
} { |
| 185 |
t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 186 |
defer func() { |
| 187 |
if err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.RemoveAllscip-go gomod github.com/golang/go/src go1.24.0 os/RemoveAll().(tempdir); err != nil { |
| 188 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("failed to remove dir %q: %v", tempdir, err) |
| 189 |
} |
| 190 |
}() |
| 191 |
for _, f := range tc.fs { |
| 192 |
path := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(tempdir, filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.FromSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/FromSlash().(f)) |
| 193 |
dir := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Dir().(path) |
| 194 |
if err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.24.0 os/MkdirAll().(dir, 0755); err != nil { |
| 195 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("failed to create dir %q: %v", dir, err) |
| 196 |
} |
| 197 |
if err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.0 os/WriteFile().(path, nil, 0644); err != nil { |
| 198 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("failed to create file %q: %v", path, err) |
| 199 |
} |
| 200 |
} |
| 201 |
tc.searchPath = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.FromSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/FromSlash().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.24.0 strings/ReplaceAll().(tc.searchPath, "$dir", tempdir)) |
| 202 |
tc.path = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.FromSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/FromSlash().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.24.0 strings/Replace().(tc.path, "$dir", tempdir, 1)) |
| 203 |
tc.wantPath = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.FromSlashscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/FromSlash().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.24.0 strings/Replace().(tc.wantPath, "$dir", tempdir, 1)) |
| 204 |
if file, err := openSourceFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/openSourceFile().(tc.path, tc.searchPath, tc.trimPath); err != nil && tc.wantPath != "" { |
| 205 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("openSourceFile(%q, %q, %q) = err %v, want path %q", tc.path, tc.searchPath, tc.trimPath, err, tc.wantPath) |
| 206 |
} else if err == nil { |
| 207 |
defer file.Closescip-go gomod github.com/golang/go/src go1.24.0 os/File#Close().() |
| 208 |
gotPath := file.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().() |
| 209 |
if tc.wantPath == "" { |
| 210 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("openSourceFile(%q, %q, %q) = %q, want error", tc.path, tc.searchPath, tc.trimPath, gotPath) |
| 211 |
} else if gotPath != tc.wantPath { |
| 212 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("openSourceFile(%q, %q, %q) = %q, want path %q", tc.path, tc.searchPath, tc.trimPath, gotPath, tc.wantPath) |
| 213 |
} |
| 214 |
} |
| 215 |
}) |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
func TestIndentationscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TestIndentation().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 220 |
for _, c := range []struct { |
| 221 |
str string |
| 222 |
wantIndent int |
| 223 |
}{ |
| 224 |
{"", 0}, |
| 225 |
{"foobar", 0}, |
| 226 |
{" foo", 2}, |
| 227 |
{"\tfoo", 8}, |
| 228 |
{"\t foo", 9}, |
| 229 |
{" \tfoo", 8}, |
| 230 |
{" \tfoo", 8}, |
| 231 |
{" \tfoo", 16}, |
| 232 |
} { |
| 233 |
if n := indentationscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/indentation().(c.str); n != c.wantIndent { |
| 234 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("indentation(%v): got %d, want %d", c.str, n, c.wantIndent) |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
func TestRightPadscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TestRightPad().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 240 |
for _, c := range []struct { |
| 241 |
pad int |
| 242 |
in string |
| 243 |
expect string |
| 244 |
}{ |
| 245 |
{0, "", ""}, |
| 246 |
{4, "", " "}, |
| 247 |
{4, "x", "x "}, |
| 248 |
{4, "abcd", "abcd"}, // No padding because of overflow |
| 249 |
{4, "abcde", "abcde"}, // No padding because of overflow |
| 250 |
{10, "\tx", " x "}, |
| 251 |
{10, "w\txy\tz", "w xy z"}, |
| 252 |
{20, "w\txy\tz", "w xy z "}, |
| 253 |
} { |
| 254 |
out := rightPadscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/rightPad().(c.in, c.pad) |
| 255 |
if out != c.expect { |
| 256 |
t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("rightPad(%q, %d): got %q, want %q", c.in, c.pad, out, c.expect) |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
func readProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/readProfile().(fname string, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile# { |
| 262 |
file, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Openscip-go gomod github.com/golang/go/src go1.24.0 os/Open().(fname) |
| 263 |
if err != nil { |
| 264 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("%s: could not open profile: %v", fname, err) |
| 265 |
} |
| 266 |
defer file.Closescip-go gomod github.com/golang/go/src go1.24.0 os/File#Close().() |
| 267 |
p, err := profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Parsescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Parse().(file) |
| 268 |
if err != nil { |
| 269 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("%s: could not parse profile: %v", fname, err) |
| 270 |
} |
| 271 |
|
| 272 |
// Fix file names so they do not include absolute path names. |
| 273 |
fix := func(s string) string { |
| 274 |
const testdir = "/internal/report/" |
| 275 |
pos := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Indexscip-go gomod github.com/golang/go/src go1.24.0 strings/Index().(s, testdir) |
| 276 |
if pos == -1 { |
| 277 |
return s |
| 278 |
} |
| 279 |
return s[pos+len(testdir):] |
| 280 |
} |
| 281 |
for _, m := range p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. { |
| 282 |
m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File. = fix(m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.) |
| 283 |
} |
| 284 |
for _, f := range p.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. { |
| 285 |
f.Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename. = fix(f.Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.) |
| 286 |
} |
| 287 |
|
| 288 |
return p |
| 289 |
} |