-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-fetch-panic
- Loading branch information
Showing
12 changed files
with
289 additions
and
35 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,9 @@ | ||
Browser tests are separated out into a module of their own to avoid | ||
polluting pprof dependencies with chromedp. | ||
|
||
These tests can be run by executing the following in the top-level | ||
of the pprof directory: | ||
|
||
```shell | ||
(cd browsertests && go test ./...) | ||
``` |
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,23 @@ | ||
module github.com/google/pprof/browsertests | ||
|
||
go 1.19 | ||
|
||
// Use the version of pprof in this directory tree. | ||
replace github.com/google/pprof => ../ | ||
|
||
require ( | ||
github.com/chromedp/chromedp v0.9.2 | ||
github.com/google/pprof v0.0.0 | ||
) | ||
|
||
require ( | ||
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89 // indirect | ||
github.com/chromedp/sysutil v1.0.0 // indirect | ||
github.com/gobwas/httphead v0.1.0 // indirect | ||
github.com/gobwas/pool v0.2.1 // indirect | ||
github.com/gobwas/ws v1.2.1 // indirect | ||
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
) |
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,24 @@ | ||
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89 h1:aPflPkRFkVwbW6dmcVqfgwp1i+UWGFH6VgR1Jim5Ygc= | ||
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= | ||
github.com/chromedp/chromedp v0.9.2 h1:dKtNz4kApb06KuSXoTQIyUC2TrA0fhGDwNZf3bcgfKw= | ||
github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs= | ||
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= | ||
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= | ||
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= | ||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= | ||
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= | ||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= | ||
github.com/gobwas/ws v1.2.1 h1:F2aeBZrm2NDsc7vbovKrWSogd4wvfAxg0FQ89/iqOTk= | ||
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY= | ||
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 h1:KwWnWVWCNtNq/ewIX7HIKnELmEx2nDP42yskD/pi7QE= | ||
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= | ||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= | ||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= | ||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo= | ||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs= | ||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= | ||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= | ||
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw= | ||
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= | ||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
File renamed without changes.
File renamed without changes.
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,216 @@ | ||
package browsertests | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"regexp" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/pprof/driver" | ||
"github.com/google/pprof/profile" | ||
) | ||
|
||
func makeTestServer(t testing.TB, prof *profile.Profile) *httptest.Server { | ||
if runtime.GOOS == "nacl" || runtime.GOOS == "js" { | ||
t.Skip("test assumes tcp available") | ||
} | ||
|
||
// Custom http server creator | ||
var server *httptest.Server | ||
serverCreated := make(chan bool) | ||
creator := func(a *driver.HTTPServerArgs) error { | ||
server = httptest.NewServer(http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if h := a.Handlers[r.URL.Path]; h != nil { | ||
h.ServeHTTP(w, r) | ||
} | ||
})) | ||
serverCreated <- true | ||
return nil | ||
} | ||
|
||
// Start server and wait for it to be initialized | ||
go func() { | ||
err := driver.PProf(&driver.Options{ | ||
Obj: fakeObjTool{}, | ||
UI: testUI{t}, | ||
Fetch: testFetcher{prof}, | ||
HTTPServer: creator, | ||
Flagset: testFlags{ | ||
"http": "unused:1234", | ||
"no_browser": true, | ||
}, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}() | ||
<-serverCreated | ||
|
||
// Close the server when the test is done. | ||
t.Cleanup(server.Close) | ||
|
||
return server | ||
} | ||
|
||
// Fake test implementations of types needed by pprof driver. | ||
|
||
const addrBase = 0x1000 | ||
const fakeSource = "testdata/file1000.src" | ||
|
||
type fakeObj struct{} | ||
|
||
func (f fakeObj) Close() error { return nil } | ||
func (f fakeObj) Name() string { return "testbin" } | ||
func (f fakeObj) ObjAddr(addr uint64) (uint64, error) { return addr, nil } | ||
func (f fakeObj) BuildID() string { return "" } | ||
func (f fakeObj) SourceLine(addr uint64) ([]driver.Frame, error) { | ||
return nil, fmt.Errorf("SourceLine unimplemented") | ||
} | ||
func (f fakeObj) Symbols(r *regexp.Regexp, addr uint64) ([]*driver.Sym, error) { | ||
return []*driver.Sym{ | ||
{ | ||
Name: []string{"F1"}, File: fakeSource, | ||
Start: addrBase, End: addrBase + 10, | ||
}, | ||
{ | ||
Name: []string{"F2"}, File: fakeSource, | ||
Start: addrBase + 10, End: addrBase + 20, | ||
}, | ||
{ | ||
Name: []string{"F3"}, File: fakeSource, | ||
Start: addrBase + 20, End: addrBase + 30, | ||
}, | ||
}, nil | ||
} | ||
|
||
type fakeObjTool struct{} | ||
|
||
func (obj fakeObjTool) Open(file string, start, limit, offset uint64, relocationSymbol string) (driver.ObjFile, error) { | ||
return fakeObj{}, nil | ||
} | ||
|
||
func (obj fakeObjTool) Disasm(file string, start, end uint64, intelSyntax bool) ([]driver.Inst, error) { | ||
return []driver.Inst{ | ||
{Addr: addrBase + 10, Text: "f1:asm", Function: "F1", Line: 3}, | ||
{Addr: addrBase + 20, Text: "f2:asm", Function: "F2", Line: 11}, | ||
{Addr: addrBase + 30, Text: "d3:asm", Function: "F3", Line: 22}, | ||
}, nil | ||
} | ||
|
||
func makeFakeProfile() *profile.Profile { | ||
// Three functions: F1, F2, F3 with three lines, 11, 22, 33. | ||
funcs := []*profile.Function{ | ||
{ID: 1, Name: "F1", Filename: fakeSource, StartLine: 3}, | ||
{ID: 2, Name: "F2", Filename: fakeSource, StartLine: 5}, | ||
{ID: 3, Name: "F3", Filename: fakeSource, StartLine: 7}, | ||
} | ||
lines := []profile.Line{ | ||
{Function: funcs[0], Line: 11}, | ||
{Function: funcs[1], Line: 22}, | ||
{Function: funcs[2], Line: 33}, | ||
} | ||
mapping := []*profile.Mapping{ | ||
{ | ||
ID: 1, | ||
Start: addrBase, | ||
Limit: addrBase + 100, | ||
Offset: 0, | ||
File: "testbin", | ||
HasFunctions: true, | ||
HasFilenames: true, | ||
HasLineNumbers: true, | ||
}, | ||
} | ||
|
||
// Three interesting addresses: base+{10,20,30} | ||
locs := []*profile.Location{ | ||
{ID: 1, Address: addrBase + 10, Line: lines[0:1], Mapping: mapping[0]}, | ||
{ID: 2, Address: addrBase + 20, Line: lines[1:2], Mapping: mapping[0]}, | ||
{ID: 3, Address: addrBase + 30, Line: lines[2:3], Mapping: mapping[0]}, | ||
} | ||
|
||
// Two stack traces. | ||
return &profile.Profile{ | ||
PeriodType: &profile.ValueType{Type: "cpu", Unit: "milliseconds"}, | ||
Period: 1, | ||
DurationNanos: 10e9, | ||
SampleType: []*profile.ValueType{ | ||
{Type: "cpu", Unit: "milliseconds"}, | ||
}, | ||
Sample: []*profile.Sample{ | ||
{ | ||
Location: []*profile.Location{locs[2], locs[1], locs[0]}, | ||
Value: []int64{100}, | ||
}, | ||
{ | ||
Location: []*profile.Location{locs[1], locs[0]}, | ||
Value: []int64{200}, | ||
}, | ||
}, | ||
Location: locs, | ||
Function: funcs, | ||
Mapping: mapping, | ||
} | ||
} | ||
|
||
type testFlags map[string]any | ||
|
||
func (flags testFlags) Bool(name string, def bool, usage string) *bool { | ||
return getFlag(flags, name, def) | ||
} | ||
func (flags testFlags) Int(name string, def int, usage string) *int { | ||
return getFlag(flags, name, def) | ||
} | ||
func (flags testFlags) Float64(name string, def float64, usage string) *float64 { | ||
return getFlag(flags, name, def) | ||
} | ||
func (flags testFlags) String(name string, def string, usage string) *string { | ||
return getFlag(flags, name, def) | ||
} | ||
func (flags testFlags) StringList(name string, def string, usage string) *[]*string { | ||
return getFlag(flags, name, []*string{}) // Not supported, so return an empty list. | ||
} | ||
func (flags testFlags) ExtraUsage() string { return "" } | ||
func (flags testFlags) AddExtraUsage(eu string) {} | ||
func (flags testFlags) Parse(usage func()) []string { return []string{"test", "bin"} } | ||
|
||
var _ driver.FlagSet = testFlags{} | ||
|
||
func getFlag[T any](flags testFlags, name string, def T) *T { | ||
result := &def | ||
if v, ok := flags[name]; ok { | ||
*result = v.(T) | ||
} | ||
return result | ||
} | ||
|
||
type testUI struct { | ||
T testing.TB | ||
} | ||
|
||
func (ui testUI) ReadLine(_ string) (string, error) { return "", io.EOF } | ||
func (ui testUI) IsTerminal() bool { return false } | ||
func (ui testUI) WantBrowser() bool { return false } | ||
func (ui testUI) SetAutoComplete(_ func(string) string) {} | ||
func (ui testUI) Print(args ...interface{}) {} // discard | ||
func (ui testUI) PrintErr(args ...interface{}) { | ||
ui.T.Error("unexpected error: " + fmt.Sprint(args...)) | ||
} | ||
|
||
var _ driver.UI = testUI{} | ||
|
||
type testFetcher struct { | ||
profile *profile.Profile | ||
} | ||
|
||
func (f testFetcher) Fetch(source string, duration, timeout time.Duration) (*profile.Profile, string, error) { | ||
// http://pproftest.local prevents file from being saved. | ||
return f.profile, "http://pproftest.local", nil | ||
} | ||
|
||
var _ driver.Fetcher = testFetcher{} |
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 |
---|---|---|
@@ -1,31 +1,11 @@ | ||
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89 h1:aPflPkRFkVwbW6dmcVqfgwp1i+UWGFH6VgR1Jim5Ygc= | ||
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= | ||
github.com/chromedp/chromedp v0.9.2 h1:dKtNz4kApb06KuSXoTQIyUC2TrA0fhGDwNZf3bcgfKw= | ||
github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs= | ||
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= | ||
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= | ||
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= | ||
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= | ||
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= | ||
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= | ||
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= | ||
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= | ||
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= | ||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= | ||
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= | ||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= | ||
github.com/gobwas/ws v1.2.1 h1:F2aeBZrm2NDsc7vbovKrWSogd4wvfAxg0FQ89/iqOTk= | ||
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY= | ||
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 h1:KwWnWVWCNtNq/ewIX7HIKnELmEx2nDP42yskD/pi7QE= | ||
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= | ||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= | ||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= | ||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo= | ||
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs= | ||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= | ||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= | ||
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw= | ||
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= | ||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
Oops, something went wrong.