Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Revert "Use binary search in getSeriesIndex (#621)" (#648)
Browse files Browse the repository at this point in the history
This reverts commit b1a77df.
  • Loading branch information
Rustin170506 authored and cyriltovena committed Apr 24, 2023
1 parent cbeb28c commit 30aa493
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 52 deletions.
37 changes: 0 additions & 37 deletions pkg/phlaredb/profile_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down
18 changes: 6 additions & 12 deletions pkg/phlaredb/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions pkg/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 30aa493

Please sign in to comment.