Skip to content

Commit

Permalink
move lookupcgroupv2 to libpf
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Nov 20, 2024
1 parent 1cf6ac9 commit 400b2fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions util/cgroup/cgroupv2.go → libpf/cgroupv2.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package cgroup // import "go.opentelemetry.io/ebpf-profiler/util/cgroup"
package libpf // import "go.opentelemetry.io/ebpf-profiler/libpf"

import (
"bufio"
Expand All @@ -11,15 +11,14 @@ import (

lru "github.com/elastic/go-freelru"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/ebpf-profiler/libpf"
)

var (
cgroupv2PathPattern = regexp.MustCompile(`0:.*?:(.*)`)
)

// LookupCgroupv2 returns the cgroupv2 ID for pid.
func LookupCgroupv2(cgrouplru *lru.SyncedLRU[libpf.PID, string], pid libpf.PID) (string, error) {
func LookupCgroupv2(cgrouplru *lru.SyncedLRU[PID, string], pid PID) (string, error) {
id, ok := cgrouplru.Get(pid)
if ok {
return id, nil
Expand Down
3 changes: 1 addition & 2 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/xsync"
"go.opentelemetry.io/ebpf-profiler/util/cgroup"
)

// Assert that we implement the full Reporter interface.
Expand Down Expand Up @@ -209,7 +208,7 @@ func (r *OTLPReporter) ReportTraceEvent(trace *libpf.Trace, meta *TraceEventMeta
traceEventsMap := r.traceEvents.WLock()
defer r.traceEvents.WUnlock(&traceEventsMap)

containerID, err := cgroup.LookupCgroupv2(r.cgroupv2ID, meta.PID)
containerID, err := libpf.LookupCgroupv2(r.cgroupv2ID, meta.PID)
if err != nil {
log.Debugf("Failed to get a cgroupv2 ID as container ID for PID %d: %v",
meta.PID, err)
Expand Down

0 comments on commit 400b2fd

Please sign in to comment.