Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions libpf/convenience.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package libpf // import "go.opentelemetry.io/ebpf-profiler/libpf"

import (
"context"
"math/rand/v2"
"reflect"
"time"
Expand All @@ -13,24 +12,6 @@ import (
log "github.com/sirupsen/logrus"
)

// SleepWithJitter sleeps for baseDuration +/- jitter (jitter is [0..1])
func SleepWithJitter(baseDuration time.Duration, jitter float64) {
time.Sleep(AddJitter(baseDuration, jitter))
}

// SleepWithJitterAndContext blocks for duration +/- jitter (jitter is [0..1]) or until ctx
// is canceled.
func SleepWithJitterAndContext(ctx context.Context, duration time.Duration, jitter float64) error {
tick := time.NewTicker(AddJitter(duration, jitter))
defer tick.Stop()
select {
case <-ctx.Done():
return ctx.Err()
case <-tick.C:
return nil
}
}

// AddJitter adds +/- jitter (jitter is [0..1]) to baseDuration
func AddJitter(baseDuration time.Duration, jitter float64) time.Duration {
if jitter < 0.0 || jitter > 1.0 {
Expand Down
40 changes: 0 additions & 40 deletions libpf/generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ func MapKeysToSlice[K comparable, V any](m map[K]V) []K {
return slice
}

// MapValuesToSlice creates a slice from a map's values.
func MapValuesToSlice[K comparable, V any](m map[K]V) []V {
slice := make([]V, 0, len(m))
for _, value := range m {
slice = append(slice, value)
}
return slice
}

// SliceToSet creates a set from a slice, deduplicating it.
func SliceToSet[T comparable](s []T) Set[T] {
set := make(map[T]Void, len(s))
for _, item := range s {
set[item] = Void{}
}
return set
}

// SliceAllEqual checks whether all items in a slice have a given value.
func SliceAllEqual[T comparable](s []T, value T) bool {
for _, item := range s {
Expand All @@ -52,25 +34,3 @@ func SliceAllEqual[T comparable](s []T, value T) bool {

return true
}

// SlicesEqual checks whether two slices are element-wise equal.
func SlicesEqual[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}

// MapSlice returns a new slice by mapping given function over the input slice.
func MapSlice[T, V any](in []T, mapf func(T) V) []V {
ret := make([]V, len(in))
for idx := range in {
ret[idx] = mapf(in[idx])
}
return ret
}