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
8 changes: 5 additions & 3 deletions internal/component/pyroscope/ebpf/ebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func New(logger log.Logger, reg prometheus.Registerer, id string, args Arguments
if err != nil {
return nil, err
}
cfg.FileObserver = nfs
cfg.ExecutableReporter = nfs

if dynamicProfilingPolicy {
cfg.Policy = &dynamicprofiling.ServiceDiscoveryTargetsOnlyPolicy{Discovery: discovery}
Expand Down Expand Up @@ -138,8 +138,10 @@ func (c *Component) Run(ctx context.Context) error {
c.metrics.profilingSessionsTotal.Inc()
defer func() {
ctlr.Shutdown()
if c.cfg.FileObserver != nil {
c.cfg.FileObserver.Cleanup()
if c.cfg.ExecutableReporter != nil {
if nfs, ok := c.cfg.ExecutableReporter.(*irsymcache.Resolver); ok {
nfs.Cleanup()
}
}
}()

Expand Down
9 changes: 4 additions & 5 deletions internal/component/pyroscope/ebpf/reporter/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (p *PPROFReporter) ReportTraceEvent(trace *libpf.Trace, meta *samples.Trace
ProcessName: meta.ProcessName,
ExecutablePath: meta.ExecutablePath,
ApmServiceName: meta.APMServiceName,
ExtraMeta: containerID,
Pid: int64(meta.PID),
Tid: int64(meta.TID),
}
Expand Down Expand Up @@ -163,9 +162,9 @@ func (p *PPROFReporter) reportProfile(ctx context.Context) {
*traceEventsPtr = newEvents
p.traceEvents.WUnlock(&traceEventsPtr)
var profiles []PPROF
for _, ts := range reportedEvents {
for containerID, ts := range reportedEvents {
for origin, events := range ts {
pp := p.createProfile(origin, events)
pp := p.createProfile(containerID, origin, events)
profiles = append(profiles, pp...)
}
}
Expand All @@ -178,7 +177,7 @@ func (p *PPROFReporter) reportProfile(ctx context.Context) {
_ = level.Debug(p.log).Log("msg", "pprof report successful", "count", len(profiles), "total-size", sz)
}

func (p *PPROFReporter) createProfile(origin libpf.Origin, events map[samples.TraceAndMetaKey]*samples.TraceEvents) []PPROF {
func (p *PPROFReporter) createProfile(containerID samples.ContainerID, origin libpf.Origin, events map[samples.TraceAndMetaKey]*samples.TraceEvents) []PPROF {
defer func() {
if p.cfg.ExtraNativeSymbolResolver != nil {
p.cfg.ExtraNativeSymbolResolver.Cleanup()
Expand All @@ -192,7 +191,7 @@ func (p *PPROFReporter) createProfile(origin libpf.Origin, events map[samples.Tr
})

for traceKey, traceInfo := range events {
target := p.sd.FindTarget(uint32(traceKey.Pid), traceKey.ExtraMeta.(string))
target := p.sd.FindTarget(uint32(traceKey.Pid), string(containerID))
if target == nil {
continue
}
Expand Down
22 changes: 14 additions & 8 deletions internal/component/pyroscope/ebpf/reporter/pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/google/pprof/profile"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"

"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/reporter/samples"
"go.opentelemetry.io/ebpf-profiler/support"

discovery "go.opentelemetry.io/ebpf-profiler/pyroscope/discovery"
"go.opentelemetry.io/ebpf-profiler/pyroscope/symb/irsymcache"
)

func singleFrameTrace(ty libpf.FrameType, mappingFile libpf.FrameMappingFile, lineno libpf.AddressOrLineno, funcName, sourceFile string, sourceLine libpf.SourceLineno) libpf.Frames {
Expand Down Expand Up @@ -73,6 +73,7 @@ func TestPPROFReporter_StringAndFunctionTablePopulation(t *testing.T) {
}

profiles := rep.createProfile(
samples.ContainerID(""),
support.TraceOriginSampling,
events,
)
Expand Down Expand Up @@ -129,6 +130,7 @@ func TestPPROFReporter_NativeFrame(t *testing.T) {
},
}
profiles := rep.createProfile(
samples.ContainerID(""),
support.TraceOriginSampling,
events,
)
Expand Down Expand Up @@ -172,6 +174,7 @@ func TestPPROFReporter_WithoutMapping(t *testing.T) {
}

profiles := rep.createProfile(
samples.ContainerID(""),
support.TraceOriginSampling,
events,
)
Expand Down Expand Up @@ -230,6 +233,7 @@ func TestPPROFReporter_Bug(t *testing.T) {
}

profiles := rep.createProfile(
samples.ContainerID(""),
support.TraceOriginSampling,
events,
)
Expand Down Expand Up @@ -259,12 +263,12 @@ Mappings
func TestPPROFReporter_Demangle(t *testing.T) {
fid := libpf.NewFileID(7, 13)
key := symbolizerKey{
fid: host.FileIDFromLibpf(fid),
fid: fid,
addr: 0xcafe00de,
}
rep := newReporter()
rep.cfg.ExtraNativeSymbolResolver = &symbolizer{
symbols: map[symbolizerKey]samples.SourceInfo{
symbols: map[symbolizerKey]irsymcache.SourceInfo{
key: {
LineNumber: 9,
FunctionName: libpf.Intern("_ZN15PlatformMonitor4waitEm"),
Expand Down Expand Up @@ -316,6 +320,7 @@ func TestPPROFReporter_Demangle(t *testing.T) {
}

profiles := rep.createProfile(
samples.ContainerID(""),
support.TraceOriginSampling,
events,
)
Expand Down Expand Up @@ -379,6 +384,7 @@ func TestPPROFReporter_UnsymbolizedStub(t *testing.T) {
}

profiles := rep.createProfile(
samples.ContainerID(""),
support.TraceOriginSampling,
events,
)
Expand Down Expand Up @@ -406,23 +412,23 @@ Mappings
}

type symbolizer struct {
symbols map[symbolizerKey]samples.SourceInfo
symbols map[symbolizerKey]irsymcache.SourceInfo
}

type symbolizerKey struct {
fid host.FileID
fid libpf.FileID
addr uint64
}

func (s symbolizer) ExecutableKnown(id host.FileID) bool {
func (s symbolizer) ExecutableKnown(id libpf.FileID) bool {
return true
}

func (s symbolizer) ObserveExecutable(id host.FileID, ref *pfelf.Reference) error {
func (s symbolizer) ObserveExecutable(id libpf.FileID, ref *pfelf.Reference) error {
return nil
}

func (s symbolizer) ResolveAddress(file host.FileID, addr uint64) (samples.SourceInfo, error) {
func (s symbolizer) ResolveAddress(file libpf.FileID, addr uint64) (irsymcache.SourceInfo, error) {
return s.symbols[symbolizerKey{fid: file, addr: addr}], nil
}

Expand Down
Loading