提交 c546ea2e 编写于 作者: D Derek Parker

Reduce running time / allocations of frame parser

上级 6a82ebb2
......@@ -6,7 +6,6 @@ package frame
import (
"bytes"
"encoding/binary"
"io"
"github.com/derekparker/dbg/dwarf/util"
)
......@@ -44,7 +43,7 @@ func cieEntry(data []byte) bool {
func parseLength(ctx *parseContext) parsefunc {
var fn parsefunc
binary.Read(ctx.Buf, binary.LittleEndian, &ctx.Length)
ctx.Length = binary.LittleEndian.Uint32(ctx.Buf.Next(4))
cieid := ctx.Buf.Next(4)
if cieEntry(cieid) {
......@@ -63,7 +62,7 @@ func parseLength(ctx *parseContext) parsefunc {
}
func parseInitialLocation(ctx *parseContext) parsefunc {
binary.Read(ctx.Buf, binary.LittleEndian, &ctx.Frame.AddressRange.begin)
ctx.Frame.AddressRange.begin = binary.LittleEndian.Uint64(ctx.Buf.Next(8))
ctx.Length -= 8
......@@ -71,7 +70,7 @@ func parseInitialLocation(ctx *parseContext) parsefunc {
}
func parseAddressRange(ctx *parseContext) parsefunc {
binary.Read(ctx.Buf, binary.LittleEndian, &ctx.Frame.AddressRange.end)
ctx.Frame.AddressRange.end = binary.LittleEndian.Uint64(ctx.Buf.Next(8))
ctx.Length -= 8
......@@ -82,17 +81,18 @@ func parseFrameInstructions(ctx *parseContext) parsefunc {
// The rest of this entry consists of the instructions
// so we can just grab all of the data from the buffer
// cursor to length.
var buf = make([]byte, ctx.Length)
io.ReadFull(ctx.Buf, buf)
ctx.Frame.Instructions = buf
ctx.Frame.Instructions = ctx.Buf.Next(int(ctx.Length))
ctx.Length = 0
return parseLength
}
func parseVersion(ctx *parseContext) parsefunc {
binary.Read(ctx.Buf, binary.LittleEndian, &ctx.Common.Version)
version, err := ctx.Buf.ReadByte()
if err != nil {
panic(err)
}
ctx.Common.Version = version
ctx.Length -= 1
return parseAugmentation
......@@ -137,10 +137,7 @@ func parseInitialInstructions(ctx *parseContext) parsefunc {
// The rest of this entry consists of the instructions
// so we can just grab all of the data from the buffer
// cursor to length.
var buf = make([]byte, ctx.Length)
binary.Read(ctx.Buf, binary.LittleEndian, &buf)
ctx.Common.InitialInstructions = buf
ctx.Common.InitialInstructions = ctx.Buf.Next(int(ctx.Length))
ctx.Length = 0
return parseLength
......
......@@ -3,6 +3,7 @@ package frame_test
import (
"testing"
"github.com/davecheney/profile"
"github.com/derekparker/dbg/dwarf/frame"
)
......@@ -38,3 +39,13 @@ func TestParse(t *testing.T) {
}
}
func BenchmarkParse(b *testing.B) {
defer profile.Start(profile.CPUProfile).Stop()
data := grabDebugFrameSection("../../_fixtures/testprog", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
frame.Parse(data)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册