Skip to content

Commit

Permalink
Fixes merge of empty samples in pprof (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored Feb 27, 2024
1 parent 11256b1 commit aa403a7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/pprof/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ func (m *ProfileMerge) merge(p *profilev1.Profile, clone bool) error {
return nil
}
ConvertIDsToIndices(p)
var initial bool
if m.profile == nil {
m.init(p, clone)
initial = true
}

// We rewrite strings first in order to compare
// sample types and period type.
m.tmp = slices.GrowLen(m.tmp, len(p.StringTable))
m.stringTable.Index(m.tmp, p.StringTable)
RewriteStrings(p, m.tmp)
if len(m.profile.StringTable) == 0 {
if initial {
// Right after initialisation we need to make
// sure that the string identifiers are normalized
// among profiles.
Expand Down
57 changes: 57 additions & 0 deletions pkg/pprof/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,60 @@ func Test_Merge_Sample(t *testing.T) {

testhelper.EqualProto(t, expected, m.Profile())
}

func TestMergeEmpty(t *testing.T) {
var m ProfileMerge

err := m.Merge(&profilev1.Profile{
SampleType: []*profilev1.ValueType{
{
Type: 2,
Unit: 1,
},
},
PeriodType: &profilev1.ValueType{
Type: 2,
Unit: 1,
},
StringTable: []string{"", "nanoseconds", "cpu"},
})
require.NoError(t, err)
err = m.Merge(&profilev1.Profile{
Sample: []*profilev1.Sample{
{
LocationId: []uint64{1},
Value: []int64{1},
},
},
Location: []*profilev1.Location{
{
Id: 1,
MappingId: 1,
Line: []*profilev1.Line{{FunctionId: 1, Line: 1}},
},
},
Function: []*profilev1.Function{
{
Id: 1,
Name: 1,
},
},
SampleType: []*profilev1.ValueType{
{
Type: 3,
Unit: 2,
},
},
PeriodType: &profilev1.ValueType{
Type: 3,
Unit: 2,
},
Mapping: []*profilev1.Mapping{
{
Id: 1,
},
},
StringTable: []string{"", "bar", "nanoseconds", "cpu"},
})
require.NoError(t, err)
}

0 comments on commit aa403a7

Please sign in to comment.