Skip to content

Commit 03d8ee1

Browse files
authored
Merge pull request #421 from parca-dev/fix-pprof-nil-pointer
pkg/storage: Fix nil pointer for locations that don't have a mapping
2 parents d7d98b0 + aeedb38 commit 03d8ee1

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ Parca was originally developed by [Polar Signals](https://polarsignals.com/). Re
7474
## Contributing
7575

7676
Check out our [Contributing Guide](CONTRIBUTING.md) to get started!
77-
77+
It explains how compile Parca, run it with Tilt as container in Kubernetes and send a Pull Request.

pkg/storage/pprof.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ func GeneratePprof(ctx context.Context, locationStore Locations, ip InstantProfi
140140
}
141141
}
142142

143-
location := &profile.Location{
144-
ID: uint64(len(p.Location) + 1),
145-
Mapping: mapping,
143+
addr := loc.Address
144+
if mapping != nil {
146145
// TODO: Is this right?
147-
Address: loc.Address + mapping.Offset,
146+
addr += mapping.Offset
147+
}
148+
149+
location := &profile.Location{
150+
ID: uint64(len(p.Location) + 1),
151+
Mapping: mapping,
152+
Address: addr,
148153
Line: lines,
149154
IsFolded: loc.IsFolded,
150155
}

pkg/storage/pprof_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/go-kit/log"
2323
"github.com/google/pprof/profile"
24+
"github.com/google/uuid"
2425
"github.com/parca-dev/parca/pkg/storage/metastore"
2526
"github.com/prometheus/client_golang/prometheus"
2627
"github.com/stretchr/testify/require"
@@ -63,3 +64,50 @@ func TestGeneratePprof(t *testing.T) {
6364
require.NoError(t, f.Close())
6465
require.NoError(t, resProf.CheckValid())
6566
}
67+
68+
func TestGeneratePprofNilMapping(t *testing.T) {
69+
ctx := context.Background()
70+
71+
pt := NewProfileTree()
72+
pt.Insert(makeSample(2, []uuid.UUID{
73+
uuid.MustParse("00000000-0000-0000-0000-000000000002"),
74+
uuid.MustParse("00000000-0000-0000-0000-000000000001"),
75+
}))
76+
77+
l := &fakeLocations{m: map[uuid.UUID]*metastore.Location{
78+
uuid.MustParse("00000000-0000-0000-0000-000000000001"): {
79+
ID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
80+
Lines: []metastore.LocationLine{{
81+
Function: &metastore.Function{
82+
ID: uuid.MustParse("00000000-0000-0000-0000-0000000000f1"),
83+
FunctionKey: metastore.FunctionKey{Name: "1"},
84+
},
85+
}},
86+
},
87+
uuid.MustParse("00000000-0000-0000-0000-000000000002"): {
88+
ID: uuid.MustParse("00000000-0000-0000-0000-000000000002"),
89+
Lines: []metastore.LocationLine{{
90+
Function: &metastore.Function{
91+
ID: uuid.MustParse("00000000-0000-0000-0000-0000000000f2"),
92+
FunctionKey: metastore.FunctionKey{Name: "2"},
93+
},
94+
}},
95+
},
96+
}}
97+
98+
res, err := GeneratePprof(ctx, l, &Profile{Tree: pt})
99+
require.NoError(t, err)
100+
101+
tmpfile, err := ioutil.TempFile("", "pprof")
102+
defer os.Remove(tmpfile.Name())
103+
require.NoError(t, err)
104+
require.NoError(t, res.Write(tmpfile))
105+
require.NoError(t, tmpfile.Close())
106+
107+
f, err := os.Open(tmpfile.Name())
108+
require.NoError(t, err)
109+
resProf, err := profile.Parse(f)
110+
require.NoError(t, err)
111+
require.NoError(t, f.Close())
112+
require.NoError(t, resProf.CheckValid())
113+
}

0 commit comments

Comments
 (0)