diff --git a/libpf/symbol.go b/libpf/symbol.go index d71a5f8f..bb33af2f 100644 --- a/libpf/symbol.go +++ b/libpf/symbol.go @@ -6,6 +6,7 @@ package libpf // import "go.opentelemetry.io/ebpf-profiler/libpf" import ( "fmt" "sort" + "strings" ) // SymbolValue represents the value associated with a symbol, e.g. either an @@ -81,6 +82,17 @@ func (symmap *SymbolMap) LookupSymbol(symbolName SymbolName) (*Symbol, error) { return nil, fmt.Errorf("symbol %v not present in map", symbolName) } +// LookupSymbolByPrefix loops over all known symbols and returns the first symbol +// that starts with the given prefix. +func (symmap *SymbolMap) LookupSymbolByPrefix(prefix string) (*Symbol, error) { + for name, sym := range symmap.nameToSymbol { + if strings.HasPrefix(string(name), prefix) { + return sym, nil + } + } + return nil, fmt.Errorf("no symbol not present that starts with '%s' in map", prefix) +} + // LookupSymbolAddress returns the address of a symbol. // Returns SymbolValueInvalid and error if not found. func (symmap *SymbolMap) LookupSymbolAddress(symbolName SymbolName) (SymbolValue, error) { diff --git a/tracer/ebpf_integration_test.go b/tracer/ebpf_integration_test.go index 0a9be766..6b784466 100644 --- a/tracer/ebpf_integration_test.go +++ b/tracer/ebpf_integration_test.go @@ -261,7 +261,7 @@ func TestAllTracers(t *testing.T) { FilterErrorFrames: false, KernelVersionCheck: false, DebugTracer: false, - BPFVerifierLogLevel: 1, + BPFVerifierLogLevel: 0, }) require.NoError(t, err) } diff --git a/tracer/tracer.go b/tracer/tracer.go index 34ba1819..9c8d317b 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -1277,7 +1277,12 @@ func (t *Tracer) StartOffCPUProfiling() error { return errors.New("off-cpu program finish_task_switch is not available") } - kprobeLink, err := link.Kprobe("finish_task_switch.isra.0", kprobeProg, nil) + kprobeSymbol, err := t.kernelSymbols.LookupSymbolByPrefix("finish_task_switch") + if err != nil { + return errors.New("failed to find kernel symbol for finish_task_switch") + } + + kprobeLink, err := link.Kprobe(string(kprobeSymbol.Name), kprobeProg, nil) if err != nil { return err }