From 30aa49364fce39cf91c0f5cfabe4f863803d220e Mon Sep 17 00:00:00 2001 From: Rustin Date: Mon, 24 Apr 2023 15:27:55 +0800 Subject: [PATCH] Revert "Use binary search in `getSeriesIndex` (#621)" (#648) This reverts commit b1a77df0bab95e24fc3ff86ca3800ed710ed1500. --- pkg/phlaredb/profile_store_test.go | 37 ------------------------------ pkg/phlaredb/profiles.go | 18 +++++---------- pkg/pprof/pprof.go | 6 ++--- 3 files changed, 9 insertions(+), 52 deletions(-) diff --git a/pkg/phlaredb/profile_store_test.go b/pkg/phlaredb/profile_store_test.go index f5e88683a..7eaa885c2 100644 --- a/pkg/phlaredb/profile_store_test.go +++ b/pkg/phlaredb/profile_store_test.go @@ -79,36 +79,6 @@ func sameProfileStream(i int) *testProfile { return tp } -// This will simulate a profile stream which ends and a new one starts at i > boundary -func profileStreamEndingAndStarting(boundary int) func(int) *testProfile { - return func(i int) *testProfile { - tp := &testProfile{} - - series := "at-beginning" - if i > boundary { - series = "at-end" - } - - tp.profileName = "process_cpu:cpu:nanoseconds:cpu:nanoseconds" - tp.lbls = phlaremodel.LabelsFromStrings( - phlaremodel.LabelNameProfileType, tp.profileName, - "job", "test", - "stream", series, - ) - - tp.p.ID = uuid.MustParse(fmt.Sprintf("00000000-0000-0000-0000-%012d", i)) - tp.p.TimeNanos = time.Second.Nanoseconds() * int64(i) - tp.p.Samples = []*schemav1.Sample{ - { - StacktraceID: 0x1, - Value: 10.0, - }, - } - tp.populateFingerprint() - return tp - } -} - func readFullParquetFile[M any](t *testing.T, path string) ([]M, uint64) { f, err := os.Open(path) require.NoError(t, err) @@ -161,13 +131,6 @@ func TestProfileStore_RowGroupSplitting(t *testing.T) { expectedNumRows: 100, values: sameProfileStream, }, - { - name: "a stream ending after half of the samples and a new one starting", - cfg: &ParquetConfig{MaxRowGroupBytes: 1828, MaxBufferRowCount: 100000}, - expectedNumRGs: 10, - expectedNumRows: 100, - values: profileStreamEndingAndStarting(50), - }, { name: "multiple row groups because of maximum row num", cfg: &ParquetConfig{MaxRowGroupBytes: 128000, MaxBufferRowCount: 10}, diff --git a/pkg/phlaredb/profiles.go b/pkg/phlaredb/profiles.go index 22d9a8584..35ea341af 100644 --- a/pkg/phlaredb/profiles.go +++ b/pkg/phlaredb/profiles.go @@ -41,20 +41,14 @@ type rowRangeWithSeriesIndex struct { type rowRangesWithSeriesIndex []rowRangeWithSeriesIndex func (s rowRangesWithSeriesIndex) getSeriesIndex(rowNum int64) uint32 { - l, r := 0, len(s)-1 - for l <= r { - mid := (l + r) / 2 - if s[mid].rowRange == nil { - l = mid + 1 + // todo: binary search + for _, rg := range s { + // it is possible that the series is not existing + if rg.rowRange == nil { continue } - if s[mid].rowNum <= rowNum && s[mid].rowNum+int64(s[mid].length) > rowNum { - return s[mid].seriesIndex - } - if s[mid].rowNum > rowNum { - r = mid - 1 - } else { - l = mid + 1 + if rg.rowNum <= rowNum && rg.rowNum+int64(rg.length) > rowNum { + return rg.seriesIndex } } panic("series index not found") diff --git a/pkg/pprof/pprof.go b/pkg/pprof/pprof.go index 23628bd07..04b512899 100644 --- a/pkg/pprof/pprof.go +++ b/pkg/pprof/pprof.go @@ -190,9 +190,9 @@ func FromProfile(p *profile.Profile) (*profilev1.Profile, error) { r.Mapping = append(r.Mapping, &profilev1.Mapping{ Id: m.ID, Filename: addString(strings, m.File), - MemoryStart: m.Start, - MemoryLimit: m.Limit, - FileOffset: m.Offset, + MemoryStart: (m.Start), + MemoryLimit: (m.Limit), + FileOffset: (m.Offset), BuildId: addString(strings, m.BuildID), HasFunctions: m.HasFunctions, HasFilenames: m.HasFilenames,