From 4425064f019a0b92663a8fe1bba5360235127ce9 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Thu, 4 Nov 2021 18:26:33 +0100 Subject: [PATCH 1/2] Clarify contributing guide --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae16735e1f2..44643142068 100644 --- a/README.md +++ b/README.md @@ -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. From aeedb38f047f45e4abdd8c54f7c00d6d8c35325f Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Fri, 5 Nov 2021 11:46:31 +0100 Subject: [PATCH 2/2] pkg/storage: Fix nil pointer for locations that don't have a mapping --- pkg/storage/pprof.go | 13 +++++++---- pkg/storage/pprof_test.go | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/pkg/storage/pprof.go b/pkg/storage/pprof.go index 4cc907aa075..83cfa378cd0 100644 --- a/pkg/storage/pprof.go +++ b/pkg/storage/pprof.go @@ -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, } diff --git a/pkg/storage/pprof_test.go b/pkg/storage/pprof_test.go index 122996438f5..2ee1995f7b0 100644 --- a/pkg/storage/pprof_test.go +++ b/pkg/storage/pprof_test.go @@ -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" @@ -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()) +}