Skip to content
Merged
27 changes: 0 additions & 27 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/times"
)

// FileID is used for unique identifiers for files, and is required to be 64-bits
Expand All @@ -33,29 +32,3 @@ func (fid FileID) StringNoQuotes() string {
func FileIDFromLibpf(id libpf.FileID) FileID {
return FileID(id.Hi())
}

type Frame struct {
File FileID
Lineno libpf.AddressOrLineno
Type libpf.FrameType
ReturnAddress bool
}

type Trace struct {
Comm libpf.String
ProcessName libpf.String
ExecutablePath libpf.String
ContainerID libpf.String
Frames []Frame
KTime times.KTime
PID libpf.PID
TID libpf.PID
Origin libpf.Origin
OffTime int64 // Time a task was off-cpu in nanoseconds.
APMTraceID libpf.APMTraceID
APMTransactionID libpf.APMTransactionID
CPU int
EnvVars map[libpf.String]libpf.String
CustomLabels map[libpf.String]libpf.String
KernelFrames libpf.Frames
}
3 changes: 1 addition & 2 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"go.opentelemetry.io/ebpf-profiler/internal/log"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/metrics"
"go.opentelemetry.io/ebpf-profiler/reporter"
Expand Down Expand Up @@ -163,7 +162,7 @@ func (c *Controller) Shutdown() {

func startTraceHandling(ctx context.Context, trc *tracer.Tracer) error {
// Spawn monitors for the various result maps
traceCh := make(chan *host.Trace)
traceCh := make(chan *libpf.EbpfTrace)

if err := trc.StartMapMonitors(ctx, traceCh); err != nil {
return fmt.Errorf("failed to start map monitors: %v", err)
Expand Down
3 changes: 1 addition & 2 deletions interpreter/apmint/apmint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"go.opentelemetry.io/ebpf-profiler/internal/log"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
Expand Down Expand Up @@ -162,7 +161,7 @@ func (i *Instance) Detach(ebpf interpreter.EbpfHandler, pid libpf.PID) error {

// NotifyAPMAgent sends out collected traces to the connected APM agent.
func (i *Instance) NotifyAPMAgent(
pid libpf.PID, rawTrace *host.Trace, umTraceHash libpf.TraceHash, count uint16,
pid libpf.PID, rawTrace *libpf.EbpfTrace, umTraceHash libpf.TraceHash, count uint16,
) {
if rawTrace.APMTransactionID == libpf.InvalidAPMSpanID || i.socket == nil {
return
Expand Down
7 changes: 3 additions & 4 deletions interpreter/beam/beam.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"go.opentelemetry.io/ebpf-profiler/internal/log"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/lpm"
Expand Down Expand Up @@ -153,15 +152,15 @@ func (i *beamInstance) Detach(interpreter.EbpfHandler, libpf.PID) error {
return nil
}

func (i *beamInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
if !frame.Type.IsInterpType(libpf.BEAM) {
func (r *beamInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
if !ef.Type().IsInterpType(libpf.BEAM) {
return interpreter.ErrMismatchInterpreterType
}

frames.Append(&libpf.Frame{
Type: libpf.BEAMFrame,
SourceFile: libpf.Intern("Unknown File"),
SourceLine: libpf.SourceLineno(frame.Lineno),
SourceLine: libpf.SourceLineno(ef.Data()),
})

return nil
Expand Down
16 changes: 8 additions & 8 deletions interpreter/dotnet/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,20 +714,20 @@ func (i *dotnetInstance) GetAndResetMetrics() ([]metrics.Metric, error) {
}, nil
}

func (i *dotnetInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
if !frame.Type.IsInterpType(libpf.Dotnet) {
func (i *dotnetInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
if !ef.Type().IsInterpType(libpf.Dotnet) {
return interpreter.ErrMismatchInterpreterType
}

sfCounter := successfailurecounter.New(&i.successCount, &i.failCount)
defer sfCounter.DefaultToFailure()

codeHeaderAndType := frame.File
frameType := uint(codeHeaderAndType & 0x1f)
codeHeaderAndType := ef.Variable(0)
subframeType := uint(codeHeaderAndType & 0x1f)
codeHeaderPtr := libpf.Address(codeHeaderAndType >> 5)
pcOffset := uint32(frame.Lineno)
pcOffset := uint32(ef.Data())

switch frameType {
switch subframeType {
case codeReadyToRun:
// Ready to Run (Non-JIT) frame running directly code from a PE file
module, err := i.getPEInfoByAddress(uint64(codeHeaderPtr))
Expand Down Expand Up @@ -756,7 +756,7 @@ func (i *dotnetInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) erro
break
}

ilOffset := method.mapPCOffsetToILOffset(pcOffset, frame.ReturnAddress)
ilOffset := method.mapPCOffsetToILOffset(pcOffset, ef.Flags().ReturnAddress())

// The Line ID format is:
// 4 bits Set to 0xf to indicate JIT frame.
Expand All @@ -776,7 +776,7 @@ func (i *dotnetInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) erro
})
default:
// Stub code
i.appendStubFrame(frames, frameType)
i.appendStubFrame(frames, subframeType)
}

sfCounter.ReportSuccess()
Expand Down
13 changes: 7 additions & 6 deletions interpreter/go/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"sync/atomic"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/metrics"
Expand Down Expand Up @@ -102,22 +101,24 @@ func (g *goInstance) Detach(_ interpreter.EbpfHandler, _ libpf.PID) error {
return nil
}

func (g *goInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
if !frame.Type.IsInterpType(libpf.Native) {
func (g *goInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
if !ef.Type().IsInterpType(libpf.Native) {
return interpreter.ErrMismatchInterpreterType
}

sfCounter := successfailurecounter.New(&g.successCount, &g.failCount)
defer sfCounter.DefaultToFailure()

sourceFile, lineNo, fn := g.d.pclntab.Symbolize(uintptr(frame.Lineno))
address := ef.Data()
sourceFile, lineNo, fn := g.d.pclntab.Symbolize(uintptr(address))
if fn == "" {
return fmt.Errorf("failed to symbolize 0x%x", frame.Lineno)
return fmt.Errorf("failed to symbolize 0x%x", address)
}

frames.Append(&libpf.Frame{
Type: libpf.GoFrame,
//TODO: File: convert the frame.File (host.FileID) to libpf.FileID here
AddressOrLineno: frame.Lineno,
AddressOrLineno: libpf.AddressOrLineno(address),
FunctionName: libpf.Intern(fn),
SourceFile: libpf.Intern(sourceFile),
SourceLine: libpf.SourceLineno(lineNo),
Expand Down
8 changes: 3 additions & 5 deletions interpreter/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ func BenchmarkGolang(b *testing.B) {
}

frames := libpf.Frames{}
ef := libpf.NewEbpfFrame(libpf.NativeFrame, 0, 1, uint64(pc))
ef[1] = uint64(hostFileID)

if err := gI.Symbolize(&host.Frame{
File: hostFileID,
Lineno: libpf.AddressOrLineno(pc),
Type: libpf.FrameType(libpf.Native),
}, &frames); err != nil {
if err := gI.Symbolize(ef, &frames); err != nil {
b.Fatalf("Failed to symbolize 0x%x: %v", pc, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/metrics"
"go.opentelemetry.io/ebpf-profiler/tracer"
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
Expand Down Expand Up @@ -106,7 +106,7 @@ func Test_Golabels(t *testing.T) {
require.NoError(t, trc.EnableProfiling())
require.NoError(t, trc.AttachSchedMonitor())

traceCh := make(chan *host.Trace)
traceCh := make(chan *libpf.EbpfTrace)
require.NoError(t, trc.StartMapMonitors(ctx, traceCh))

wg := sync.WaitGroup{}
Expand Down
12 changes: 6 additions & 6 deletions interpreter/hotspot/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,16 +867,16 @@ func (d *hotspotInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
// Symbolize interpreters Hotspot eBPF uwinder given data containing target
// process address and translates it to decorated frames expanding any inlined
// frames to multiple new frames.
func (d *hotspotInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
if !frame.Type.IsInterpType(libpf.HotSpot) {
func (d *hotspotInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
if !ef.Type().IsInterpType(libpf.HotSpot) {
return interpreter.ErrMismatchInterpreterType
}

// Extract the HotSpot frame bitfields from the file and line variables
ptr := libpf.Address(frame.File)
subtype := uint32(frame.Lineno>>60) & 0xf
ripOrBci := uint32(frame.Lineno>>32) & 0x0fffffff
ptrCheck := uint32(frame.Lineno)
ptr := libpf.Address(ef.Variable(0))
subtype := uint32(ef.Variable(1)>>60) & 0xf
ripOrBci := uint32(ef.Variable(1)>>32) & 0x0fffffff
ptrCheck := uint32(ef.Variable(1))

var err error
sfCounter := successfailurecounter.New(&d.successCount, &d.failCount)
Expand Down
3 changes: 1 addition & 2 deletions interpreter/instancestubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package interpreter // import "go.opentelemetry.io/ebpf-profiler/interpreter"

import (
"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/metrics"
Expand All @@ -26,7 +25,7 @@ func (is *InstanceStubs) UpdateLibcInfo(EbpfHandler, libpf.PID, libc.LibcInfo) e
return nil
}

func (is *InstanceStubs) Symbolize(*host.Frame, *libpf.Frames) error {
func (is *InstanceStubs) Symbolize(libpf.EbpfFrame, *libpf.Frames) error {
return ErrMismatchInterpreterType
}

Expand Down
5 changes: 2 additions & 3 deletions interpreter/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package interpreter // import "go.opentelemetry.io/ebpf-profiler/interpreter"
import (
"errors"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/internal/log"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
Expand Down Expand Up @@ -116,10 +115,10 @@ func (m *MultiInstance) UpdateLibcInfo(ebpf EbpfHandler, pid libpf.PID, info lib
}

// Symbolize tries to symbolize the frame with each interpreter instance until one succeeds.
func (m *MultiInstance) Symbolize(ebpfFrame *host.Frame, frames *libpf.Frames) error {
func (m *MultiInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
// Try each interpreter in order
for _, instance := range m.instances {
err := instance.Symbolize(ebpfFrame, frames)
err := instance.Symbolize(ef, frames)
if err != ErrMismatchInterpreterType {
return err
}
Expand Down
19 changes: 9 additions & 10 deletions interpreter/nodev8/v8.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ import (

"github.com/elastic/go-freelru"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
Expand Down Expand Up @@ -1701,21 +1700,21 @@ func (i *v8Instance) symbolizeCode(code *v8Code, delta uint64, returnAddress boo
return nil
}

func (i *v8Instance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
if !frame.Type.IsInterpType(libpf.V8) {
func (i *v8Instance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
if !ef.Type().IsInterpType(libpf.V8) {
return interpreter.ErrMismatchInterpreterType
}

sfCounter := successfailurecounter.New(&i.successCount, &i.failCount)
defer sfCounter.DefaultToFailure()

pointerAndType := libpf.Address(frame.File)
deltaOrMarker := uint64(frame.Lineno)
frameType := pointerAndType & support.V8FileTypeMask
pointerAndType := libpf.Address(ef.Variable(0))
deltaOrMarker := uint64(ef.Variable(1))
subframeType := pointerAndType & support.V8FileTypeMask
pointer := pointerAndType&^support.V8FileTypeMask | HeapObjectTag

var err error
switch frameType {
switch subframeType {
case support.V8FileTypeMarker:
// This is a stub V8 frame, with deltaOrMarker containing the marker.
// Convert the V8 build specific marker ID to a static ID and symbolize
Expand All @@ -1726,16 +1725,16 @@ func (i *v8Instance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
case support.V8FileTypeNativeCode, support.V8FileTypeNativeJSFunc:
var code *v8Code
codeCookie := uint32(deltaOrMarker & support.V8LineCookieMask >> support.V8LineCookieShift)
if frameType == support.V8FileTypeNativeCode {
if subframeType == support.V8FileTypeNativeCode {
code, err = i.getCode(pointer, codeCookie)
} else {
code, err = i.getCodeFromJSFunc(pointer, codeCookie)
}
if err == nil {
err = i.symbolizeCode(code, deltaOrMarker, frame.ReturnAddress, frames)
err = i.symbolizeCode(code, deltaOrMarker, ef.Flags().ReturnAddress(), frames)
}
default:
err = fmt.Errorf("unsupported frame type %#x", frameType)
err = fmt.Errorf("unsupported frame type %#x", subframeType)
}
if err != nil {
// TODO: emit error frame
Expand Down
9 changes: 4 additions & 5 deletions interpreter/perl/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/zeebo/xxh3"
"go.opentelemetry.io/ebpf-profiler/internal/log"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
Expand Down Expand Up @@ -385,22 +384,22 @@ func (i *perlInstance) getCOP(copAddr libpf.Address, funcName libpf.String) (
return c, nil
}

func (i *perlInstance) Symbolize(frame *host.Frame, frames *libpf.Frames) error {
if !frame.Type.IsInterpType(libpf.Perl) {
func (i *perlInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames) error {
if !ef.Type().IsInterpType(libpf.Perl) {
return interpreter.ErrMismatchInterpreterType
}

sfCounter := successfailurecounter.New(&i.successCount, &i.failCount)
defer sfCounter.DefaultToFailure()

functionName := interpreter.TopLevelFunctionName
if gvAddr := libpf.Address(frame.File); gvAddr != 0 {
if gvAddr := libpf.Address(ef.Variable(0)); gvAddr != 0 {
var err error
if functionName, err = i.getGV(gvAddr, false); err != nil {
return fmt.Errorf("failed to get Perl GV %x: %v", gvAddr, err)
}
}
copAddr := libpf.Address(frame.Lineno)
copAddr := libpf.Address(ef.Variable(1))
cop, err := i.getCOP(copAddr, functionName)
if err != nil {
return fmt.Errorf("failed to get Perl COP %x: %v", copAddr, err)
Expand Down
Loading