From e0f6ce3961ab2e4bff3613b30f8e116154c4dc02 Mon Sep 17 00:00:00 2001 From: Anton Kolesnikov Date: Thu, 11 Apr 2024 21:47:48 +0800 Subject: [PATCH] fix: pprof merge profiles ignoring sample type stub --- pkg/pprof/merge.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/pprof/merge.go b/pkg/pprof/merge.go index 9af12b0e87..ff1ff7d529 100644 --- a/pkg/pprof/merge.go +++ b/pkg/pprof/merge.go @@ -218,8 +218,12 @@ func equalValueType(st1, st2 *profilev1.ValueType) bool { func RewriteStrings(p *profilev1.Profile, n []uint32) { for _, t := range p.SampleType { - t.Unit = int64(n[t.Unit]) - t.Type = int64(n[t.Type]) + if t.Unit != 0 { + t.Unit = int64(n[t.Unit]) + } + if t.Type != 0 { + t.Type = int64(n[t.Type]) + } } for _, s := range p.Sample { for _, l := range s.Label { @@ -238,8 +242,12 @@ func RewriteStrings(p *profilev1.Profile, n []uint32) { } p.DropFrames = int64(n[p.DropFrames]) p.KeepFrames = int64(n[p.KeepFrames]) - p.PeriodType.Type = int64(n[p.PeriodType.Type]) - p.PeriodType.Unit = int64(n[p.PeriodType.Unit]) + if p.PeriodType.Type != 0 { + p.PeriodType.Type = int64(n[p.PeriodType.Type]) + } + if p.PeriodType.Unit != 0 { + p.PeriodType.Unit = int64(n[p.PeriodType.Unit]) + } for i, x := range p.Comment { p.Comment[i] = int64(n[x]) }