Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #30 from uber/pprof-mapping
Browse files Browse the repository at this point in the history
Add support for mappings in Location
  • Loading branch information
prashantv committed Oct 14, 2015
2 parents 1f46a6a + 3113b19 commit d9ad231
Show file tree
Hide file tree
Showing 3 changed files with 2,524 additions and 7 deletions.
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

0 comments on commit d9ad231

Please sign in to comment.