Debian Codegraph @

internal/driver/webui_test.go

raw symbols SCIP
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 driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
19 "ioscip-go gomod github.com/golang/go/src go1.24.0 io/"
20 "netscip-go gomod github.com/golang/go/src go1.24.0 net/"
21 "net/httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/"
22 "net/http/httptestscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/"
23 "net/urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/"
24 "os/execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/"
25 "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/"
26 "runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/"
27 "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/"
28 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
29
30 "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/"
31 "github.com/google/pprof/internal/proftestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/"
32 "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/"
33 )
34
35 func makeTestServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeTestServer().(t testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.TBscip-go gomod github.com/golang/go/src go1.24.0 testing/TB#, 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#) *httptestscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/.Serverscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/Server# {
36 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. == "nacl" || 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. == "js" {
37 t.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/TB#Skip().("test assumes tcp available")
38 }
39
40 // Custom http server creator
41 var server *httptestscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/.Serverscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/Server#
42 serverCreated := make(chan bool)
43 creator := func(a *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.HTTPServerArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#) error {
44 server = httptestscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(
45 func(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) {
46 if h := a.Handlersscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Handlers.[r.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Pathscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Path.]; h != nil {
47 h.ServeHTTPscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Handler#ServeHTTP().(w, r)
48 }
49 }))
50 serverCreated <- true
51 return nil
52 }
53
54 // Start server and wait for it to be initialized
55 go serveWebInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/serveWebInterface().("unused:1234", prof, &pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#{
56 Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj.: fakeObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObjTool#{},
57 UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.: &proftestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/.TestUIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/TestUI#{Tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/TestUI#T.: t},
58 HTTPServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#HTTPServer.: creator,
59 }, false)
60 <-serverCreated
61
62 // Close the server when the test is done.
63 t.Cleanupscip-go gomod github.com/golang/go/src go1.24.0 testing/TB#Cleanup().(server.Closescip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/Server#Close().)
64
65 return server
66 }
67
68 func TestWebInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/TestWebInterface().(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#) {
69 prof := makeFakeProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeFakeProfile().()
70 server := makeTestServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeTestServer().(t, prof)
71 haveDot := false
72 if _, err := execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/.LookPathscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/LookPath().("dot"); err == nil {
73 haveDot = true
74 }
75
76 type testCase struct {
77 path string
78 want []string
79 needDot bool
80 }
81 testcases := []testCase{
82 {"/", []string{"F1", "F2", "F3", "testbin", "cpu"}, true},
83 {"/top", []string{`"Name":"F2","InlineLabel":"","Flat":200,"Cum":300,"FlatFormat":"200ms","CumFormat":"300ms"}`}, false},
84 {"/source?f=" + urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.QueryEscapescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/QueryEscape().("F[12]"), []string{
85 "F1",
86 "F2",
87 `\. +300ms .*f1:asm`, // Cumulative count for F1
88 "200ms +300ms .*f2:asm", // Flat + cumulative count for F2
89 }, false},
90 {"/peek?f=" + urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.QueryEscapescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/QueryEscape().("F[12]"),
91 []string{"300ms.*F1", "200ms.*300ms.*F2"}, false},
92 {"/disasm?f=" + urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.QueryEscapescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/QueryEscape().("F[12]"),
93 []string{"f1:asm", "f2:asm"}, false},
94 {"/flamegraph", []string{
95 "File: testbin",
96 // Check that interesting frames are included.
97 `\bF1\b`,
98 `\bF2\b`,
99 // Check new view JS is included.
100 `function stackViewer`,
101 // Check new view CSS is included.
102 "#stack-chart {",
103 }, false},
104 }
105 for _, c := range testcases {
106 if c.needDot && !haveDot {
107 t.Logscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Log().("skipping", c.path, "since dot (graphviz) does not seem to be installed")
108 continue
109 }
110 res, err := httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Getscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Get().(server.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/Server#URL. + c.path)
111 if err != nil {
112 t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().("could not fetch", c.path, err)
113 continue
114 }
115 data, err := ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(res.Bodyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Body.)
116 if err != nil {
117 t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().("could not read response", c.path, err)
118 continue
119 }
120 result := string(data)
121 for _, w := range c.want {
122 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().(w, result); !match {
123 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("response for %s does not match "+
124 "expected pattern '%s'; "+
125 "actual result:\n%s", c.path, w, result)
126 }
127 }
128 }
129
130 // Also fetch all the test case URLs in parallel to test thread
131 // safety when run under the race detector.
132 var wg syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.24.0 sync/WaitGroup#
133 for _, c := range testcases {
134 if c.needDot && !haveDot {
135 continue
136 }
137 path := server.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/Server#URL. + c.path
138 for count := 0; count < 2; count++ {
139 wg.Addscip-go gomod github.com/golang/go/src go1.24.0 sync/WaitGroup#Add().(1)
140 go func() {
141 defer wg.Donescip-go gomod github.com/golang/go/src go1.24.0 sync/WaitGroup#Done().()
142 res, err := httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Getscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Get().(path)
143 if err != nil {
144 t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().("could not fetch", path, err)
145 return
146 }
147 if _, err = ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(res.Bodyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Body.); err != nil {
148 t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().("could not read response", path, err)
149 }
150 }()
151 }
152 }
153 wg.Waitscip-go gomod github.com/golang/go/src go1.24.0 sync/WaitGroup#Wait().()
154 }
155
156 // Implement fake object file support.
157
158 const addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. = 0x1000
159 const fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource. = "testdata/file1000.src"
160
161 type fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj# struct{}
162
163 func (f fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#) Closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#Close().() error { return nil }
164 func (f fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#) Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#Name().() string { return "testbin" }
165 func (f fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#) ObjAddrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#ObjAddr().(addr uint64) (uint64, error) { return addr, nil }
166 func (f fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#) BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#BuildID().() string { return "" }
167 func (f fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#) SourceLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#SourceLine().(addr uint64) ([]pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Framescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#, error) {
168 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("SourceLine unimplemented")
169 }
170 func (f fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#) Symbolsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#Symbols().(r *regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#, addr uint64) ([]*pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#, error) {
171 return []*pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Symscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#{
172 {
173 Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#Name.: []string{"F1"}, Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#File.: fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource.,
174 Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#Start.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase., Endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#End.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 10,
175 },
176 {
177 Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#Name.: []string{"F2"}, Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#File.: fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource.,
178 Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#Start.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 10, Endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#End.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 20,
179 },
180 {
181 Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#Name.: []string{"F3"}, Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#File.: fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource.,
182 Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#Start.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 20, Endscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Sym#End.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 30,
183 },
184 }, nil
185 }
186
187 type fakeObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObjTool# struct{}
188
189 func (obj fakeObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObjTool#) Openscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObjTool#Open().(file string, start, limit, offset uint64, relocationSymbol string) (pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#, error) {
190 return fakeObjscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObj#{}, nil
191 }
192
193 func (obj fakeObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObjTool#) Disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeObjTool#Disasm().(file string, start, end uint64, intelSyntax bool) ([]pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Instscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#, error) {
194 return []pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Instscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#{
195 {Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 10, Textscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Text.: "f1:asm", Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Function.: "F1", Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Line.: 3},
196 {Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 20, Textscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Text.: "f2:asm", Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Function.: "F2", Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Line.: 11},
197 {Addrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Addr.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 30, Textscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Text.: "d3:asm", Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Function.: "F3", Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Inst#Line.: 22},
198 }, nil
199 }
200
201 func makeFakeProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeFakeProfile().() *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# {
202 // Three functions: F1, F2, F3 with three lines, 11, 22, 33.
203 funcs := []*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#{
204 {IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.: 1, Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: "F1", Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource., StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.: 3},
205 {IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.: 2, Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: "F2", Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource., StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.: 5},
206 {IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.: 3, Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: "F3", Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: fakeSourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/fakeSource., StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.: 7},
207 }
208 lines := []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#{
209 {Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: funcs[0], Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.: 11},
210 {Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: funcs[1], Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.: 22},
211 {Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: funcs[2], Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.: 33},
212 }
213 mapping := []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{
214 {
215 IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.: 1,
216 Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase.,
217 Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 100,
218 Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0,
219 Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "testbin",
220 HasFunctionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFunctions.: true,
221 HasFilenamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFilenames.: true,
222 HasLineNumbersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasLineNumbers.: true,
223 },
224 }
225
226 // Three interesting addresses: base+{10,20,30}
227 locs := []*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#{
228 {IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.: 1, Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 10, Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.: lines[0:1], Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.: mapping[0]},
229 {IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.: 2, Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 20, Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.: lines[1:2], Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.: mapping[0]},
230 {IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.: 3, Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addrBasescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addrBase. + 30, Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.: lines[2:3], Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.: mapping[0]},
231 }
232
233 // Two stack traces.
234 return &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#{
235 PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.: &profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "cpu", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "milliseconds"},
236 Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.: 1,
237 DurationNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DurationNanos.: 10e9,
238 SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.: []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{
239 {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "cpu", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "milliseconds"},
240 },
241 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#{
242 {
243 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#{locs[2], locs[1], locs[0]},
244 Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{100},
245 },
246 {
247 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#{locs[1], locs[0]},
248 Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{200},
249 },
250 },
251 Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.: locs,
252 Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function.: funcs,
253 Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.: mapping,
254 }
255 }
256
257 func TestGetHostAndPortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/TestGetHostAndPort().(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#) {
258 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. == "nacl" || 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. == "js" {
259 t.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Skip().("test assumes tcp available")
260 }
261
262 type testCase struct {
263 hostport string
264 wantHost string
265 wantPort int
266 wantRandomPort bool
267 }
268
269 testCases := []testCase{
270 {":", "localhost", 0, true},
271 {":4681", "localhost", 4681, false},
272 {"localhost:4681", "localhost", 4681, false},
273 }
274 for _, tc := range testCases {
275 host, port, err := getHostAndPortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getHostAndPort().(tc.hostport)
276 if err != nil {
277 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("could not get host and port for %q: %v", tc.hostport, err)
278 }
279 if got, want := host, tc.wantHost; got != want {
280 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("for %s, got host %s, want %s", tc.hostport, got, want)
281 continue
282 }
283 if !tc.wantRandomPort {
284 if got, want := port, tc.wantPort; got != want {
285 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("for %s, got port %d, want %d", tc.hostport, got, want)
286 continue
287 }
288 }
289 }
290 }
291
292 func TestIsLocalHostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/TestIsLocalHost().(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#) {
293 for _, s := range []string{"localhost:10000", "[::1]:10000", "127.0.0.1:10000"} {
294 host, _, err := netscip-go gomod github.com/golang/go/src go1.24.0 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.24.0 net/SplitHostPort().(s)
295 if err != nil {
296 t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().("unexpected error when splitting", s)
297 continue
298 }
299 if !isLocalhostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/isLocalhost().(host) {
300 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("host %s from %s not considered local", host, s)
301 }
302 }
303 }
304
305 func BenchmarkTopscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/BenchmarkTop().(b *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Bscip-go gomod github.com/golang/go/src go1.24.0 testing/B#) { benchmarkURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/benchmarkURL().(b, "/top", false) }
306 func BenchmarkFlamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/BenchmarkFlame().(b *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Bscip-go gomod github.com/golang/go/src go1.24.0 testing/B#) { benchmarkURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/benchmarkURL().(b, "/flamegraph", false) }
307 func BenchmarkDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/BenchmarkDot().(b *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Bscip-go gomod github.com/golang/go/src go1.24.0 testing/B#) { benchmarkURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/benchmarkURL().(b, "/", true) }
308
309 func benchmarkURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/benchmarkURL().(b *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Bscip-go gomod github.com/golang/go/src go1.24.0 testing/B#, path string, needDot bool) {
310 if needDot {
311 if _, err := execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/.LookPathscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/LookPath().("dot"); err != nil {
312 b.Skipscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Skip().("dot not available")
313 }
314 }
315 prof := largeProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/largeProfile().(b)
316 server := makeTestServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeTestServer().(b, prof)
317 url := server.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http/httptest`/Server#URL. + path
318 b.ResetTimerscip-go gomod github.com/golang/go/src go1.24.0 testing/B#ResetTimer().()
319 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.24.0 testing/B#N.; i++ {
320 res, err := httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Getscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Get().(url)
321 if err != nil {
322 b.Fatalscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatal().(err)
323 }
324 data, err := ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(res.Bodyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Body.)
325 if err != nil {
326 b.Fatalscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatal().(err)
327 }
328 if i == 0 && testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Verbosescip-go gomod github.com/golang/go/src go1.24.0 testing/Verbose().() {
329 b.Logfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Logf().("%-12s : %10d bytes", path, len(data))
330 }
331 }
332 }