Skip to content

Commit

Permalink
Merge pull request #421 from parca-dev/fix-pprof-nil-pointer
Browse files Browse the repository at this point in the history
pkg/storage: Fix nil pointer for locations that don't have a mapping
  • Loading branch information
brancz authored Nov 8, 2021
2 parents d7d98b0 + aeedb38 commit 03d8ee1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ Parca was originally developed by [Polar Signals](https://polarsignals.com/). Re
## Contributing

Check out our [Contributing Guide](CONTRIBUTING.md) to get started!

It explains how compile Parca, run it with Tilt as container in Kubernetes and send a Pull Request.
13 changes: 9 additions & 4 deletions pkg/storage/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ func GeneratePprof(ctx context.Context, locationStore Locations, ip InstantProfi
}
}

location := &profile.Location{
ID: uint64(len(p.Location) + 1),
Mapping: mapping,
addr := loc.Address
if mapping != nil {
// TODO: Is this right?
Address: loc.Address + mapping.Offset,
addr += mapping.Offset
}

location := &profile.Location{
ID: uint64(len(p.Location) + 1),
Mapping: mapping,
Address: addr,
Line: lines,
IsFolded: loc.IsFolded,
}
Expand Down
48 changes: 48 additions & 0 deletions pkg/storage/pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/go-kit/log"
"github.com/google/pprof/profile"
"github.com/google/uuid"
"github.com/parca-dev/parca/pkg/storage/metastore"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -63,3 +64,50 @@ func TestGeneratePprof(t *testing.T) {
require.NoError(t, f.Close())
require.NoError(t, resProf.CheckValid())
}

func TestGeneratePprofNilMapping(t *testing.T) {
ctx := context.Background()

pt := NewProfileTree()
pt.Insert(makeSample(2, []uuid.UUID{
uuid.MustParse("00000000-0000-0000-0000-000000000002"),
uuid.MustParse("00000000-0000-0000-0000-000000000001"),
}))

l := &fakeLocations{m: map[uuid.UUID]*metastore.Location{
uuid.MustParse("00000000-0000-0000-0000-000000000001"): {
ID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
Lines: []metastore.LocationLine{{
Function: &metastore.Function{
ID: uuid.MustParse("00000000-0000-0000-0000-0000000000f1"),
FunctionKey: metastore.FunctionKey{Name: "1"},
},
}},
},
uuid.MustParse("00000000-0000-0000-0000-000000000002"): {
ID: uuid.MustParse("00000000-0000-0000-0000-000000000002"),
Lines: []metastore.LocationLine{{
Function: &metastore.Function{
ID: uuid.MustParse("00000000-0000-0000-0000-0000000000f2"),
FunctionKey: metastore.FunctionKey{Name: "2"},
},
}},
},
}}

res, err := GeneratePprof(ctx, l, &Profile{Tree: pt})
require.NoError(t, err)

tmpfile, err := ioutil.TempFile("", "pprof")
defer os.Remove(tmpfile.Name())
require.NoError(t, err)
require.NoError(t, res.Write(tmpfile))
require.NoError(t, tmpfile.Close())

f, err := os.Open(tmpfile.Name())
require.NoError(t, err)
resProf, err := profile.Parse(f)
require.NoError(t, err)
require.NoError(t, f.Close())
require.NoError(t, resProf.CheckValid())
}

0 comments on commit 03d8ee1

Please sign in to comment.