Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pprof/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ func (p *rawParser) toSamples() []*stack.Sample {
// and creates a mapping from funcID to function name.
func (p *rawParser) addLocation(line string) {
parts := splitBySpace(line)
if len(parts) < 3 {
if len(parts) < 4 {
p.setError(fmt.Errorf("malformed location line: %v", line))
return
}
funcID := p.toFuncID(strings.TrimSuffix(parts[0], ":"))
p.funcNames[funcID] = parts[2]
if strings.HasPrefix(parts[2], "M=") {
p.funcNames[funcID] = parts[3]
} else {
p.funcNames[funcID] = parts[2]
}
}

type stackRecord struct {
Expand Down
20 changes: 15 additions & 5 deletions pprof/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/uber/go-torch/stack"
)

func parseTestRawData(t *testing.T) ([]byte, *rawParser) {
rawBytes, err := ioutil.ReadFile("testdata/pprof.raw.txt")
func parseTestRawData(t *testing.T, file string) ([]byte, *rawParser) {
rawBytes, err := ioutil.ReadFile(file)
if err != nil {
t.Fatalf("Failed to read testdata/pprof.raw.txt: %v", err)
t.Fatalf("Failed to read %v: %v", file, err)
}

parser := newRawParser()
Expand All @@ -44,8 +45,12 @@ func parseTestRawData(t *testing.T) ([]byte, *rawParser) {
return rawBytes, parser
}

func parseTest1(t *testing.T) ([]byte, *rawParser) {
return parseTestRawData(t, "testdata/pprof.raw.txt")
}

func TestParse(t *testing.T) {
_, parser := parseTestRawData(t)
_, parser := parseTest1(t)

// line 7 - 249 are stack records in the test file.
const expectedNumRecords = 242
Expand Down Expand Up @@ -82,8 +87,13 @@ func TestParse(t *testing.T) {
}
}

func TestParseWithM(t *testing.T) {
_, parser := parseTestRawData(t, "testdata/pprof2.raw.txt")
assert.Equal(t, "runtime.scanobject", parser.funcNames[1], "location with with m=1 failed")
}

func TestParseRawValid(t *testing.T) {
rawBytes, _ := parseTestRawData(t)
rawBytes, _ := parseTest1(t)
got, err := ParseRaw(rawBytes)
if err != nil {
t.Fatalf("ParseRaw failed: %v", err)
Expand Down
Loading