}
}
-// 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
// 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)
}
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)
+ }
+ }
+ })
+}