diff options
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/gosym/pclntab_test.go | 91 |
1 files changed, 84 insertions, 7 deletions
diff --git a/src/debug/gosym/pclntab_test.go b/src/debug/gosym/pclntab_test.go index 7347139b5d..8589227157 100644 --- a/src/debug/gosym/pclntab_test.go +++ b/src/debug/gosym/pclntab_test.go @@ -267,7 +267,8 @@ func TestPCLine(t *testing.T) { } } -// Test that we can parse a pclntab from 1.15. +// read115Executable returns a hello world executable compiled by Go 1.15. +// // The file was compiled in /tmp/hello.go: // [BEGIN] // package main @@ -276,25 +277,30 @@ func TestPCLine(t *testing.T) { // println("hello") // } // [END] -func Test115PclnParsing(t *testing.T) { +func read115Executable(tb testing.TB) []byte { zippedDat, err := os.ReadFile("testdata/pcln115.gz") if err != nil { - t.Fatal(err) + tb.Fatal(err) } var gzReader *gzip.Reader gzReader, err = gzip.NewReader(bytes.NewBuffer(zippedDat)) if err != nil { - t.Fatal(err) + tb.Fatal(err) } var dat []byte dat, err = io.ReadAll(gzReader) if err != nil { - t.Fatal(err) + tb.Fatal(err) } + return dat +} + +// Test that we can parse a pclntab from 1.15. +func Test115PclnParsing(t *testing.T) { + dat := read115Executable(t) const textStart = 0x1001000 pcln := NewLineTable(dat, textStart) - var tab *Table - tab, err = NewTable(nil, pcln) + tab, err := NewTable(nil, pcln) if err != nil { t.Fatal(err) } @@ -314,3 +320,74 @@ func Test115PclnParsing(t *testing.T) { t.Fatalf("expected to parse name as main.main, got %v", f.Name) } } + +var ( + sinkLineTable *LineTable + sinkTable *Table +) + +func Benchmark115(b *testing.B) { + dat := read115Executable(b) + const textStart = 0x1001000 + + b.Run("NewLineTable", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + sinkLineTable = NewLineTable(dat, textStart) + } + }) + + pcln := NewLineTable(dat, textStart) + b.Run("NewTable", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + var err error + sinkTable, err = NewTable(nil, pcln) + if err != nil { + b.Fatal(err) + } + } + }) + + tab, err := NewTable(nil, pcln) + if err != nil { + b.Fatal(err) + } + + b.Run("LineToPC", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + var f *Func + var pc uint64 + pc, f, err = tab.LineToPC("/tmp/hello.go", 3) + if err != nil { + b.Fatal(err) + } + if pcln.version != ver12 { + b.Fatalf("want version=%d, got %d", ver12, pcln.version) + } + if pc != 0x105c280 { + b.Fatalf("want pc=0x105c280, got 0x%x", pc) + } + if f.Name != "main.main" { + b.Fatalf("want name=main.main, got %q", f.Name) + } + } + }) + + b.Run("PCToLine", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + file, line, fn := tab.PCToLine(0x105c280) + if file != "/tmp/hello.go" { + b.Fatalf("want name=/tmp/hello.go, got %q", file) + } + if line != 3 { + b.Fatalf("want line=3, got %d", line) + } + if fn.Name != "main.main" { + b.Fatalf("want name=main.main, got %q", fn.Name) + } + } + }) +} |
