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
4 changes: 2 additions & 2 deletions interpreter/instancestubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ 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"
"go.opentelemetry.io/ebpf-profiler/process"
"go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/tpbase"
)

// InstanceStubs provides empty implementations of Instance hooks that are
Expand All @@ -22,7 +22,7 @@ func (is *InstanceStubs) SynchronizeMappings(EbpfHandler, reporter.ExecutableRep
return nil
}

func (is *InstanceStubs) UpdateTSDInfo(EbpfHandler, libpf.PID, tpbase.TSDInfo) error {
func (is *InstanceStubs) UpdateLibcInfo(EbpfHandler, libpf.PID, libc.LibcInfo) error {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions interpreter/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

"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"
"go.opentelemetry.io/ebpf-profiler/metrics"
"go.opentelemetry.io/ebpf-profiler/process"
"go.opentelemetry.io/ebpf-profiler/remotememory"
"go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/tpbase"
)

// MultiData implements the Data interface for multiple interpreters.
Expand Down Expand Up @@ -104,11 +104,11 @@ func (m *MultiInstance) SynchronizeMappings(ebpf EbpfHandler,
return errors.Join(errs...)
}

// UpdateTSDInfo updates TSD info for all interpreter instances.
func (m *MultiInstance) UpdateTSDInfo(ebpf EbpfHandler, pid libpf.PID, info tpbase.TSDInfo) error {
// UpdateLibcInfo updates libc info for all interpreter instances.
func (m *MultiInstance) UpdateLibcInfo(ebpf EbpfHandler, pid libpf.PID, info libc.LibcInfo) error {
var errs []error
for _, instance := range m.instances {
if err := instance.UpdateTSDInfo(ebpf, pid, info); err != nil {
if err := instance.UpdateLibcInfo(ebpf, pid, info); err != nil {
errs = append(errs, err)
}
}
Expand Down
13 changes: 6 additions & 7 deletions interpreter/perl/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfunsafe"
"go.opentelemetry.io/ebpf-profiler/metrics"
npsr "go.opentelemetry.io/ebpf-profiler/nopanicslicereader"
"go.opentelemetry.io/ebpf-profiler/remotememory"
"go.opentelemetry.io/ebpf-profiler/successfailurecounter"
"go.opentelemetry.io/ebpf-profiler/support"
"go.opentelemetry.io/ebpf-profiler/tpbase"
"go.opentelemetry.io/ebpf-profiler/util"
)

Expand Down Expand Up @@ -73,9 +73,8 @@ func hashCOPKey(k copKey) uint32 {
return uint32(h ^ xxh3.HashString128(k.funcName.String()).Lo)
}

func (i *perlInstance) UpdateTSDInfo(ebpf interpreter.EbpfHandler, pid libpf.PID,
tsdInfo tpbase.TSDInfo,
) error {
func (i *perlInstance) UpdateLibcInfo(ebpf interpreter.EbpfHandler, pid libpf.PID,
libcInfo libc.LibcInfo) error {
d := i.d
stateInTSD := uint8(0)
if d.stateInTSD {
Expand All @@ -88,9 +87,9 @@ func (i *perlInstance) UpdateTSDInfo(ebpf interpreter.EbpfHandler, pid libpf.PID
StateInTSD: stateInTSD,

TsdInfo: support.TSDInfo{
Offset: tsdInfo.Offset,
Multiplier: tsdInfo.Multiplier,
Indirect: tsdInfo.Indirect,
Offset: libcInfo.TSDInfo.Offset,
Multiplier: libcInfo.TSDInfo.Multiplier,
Indirect: libcInfo.TSDInfo.Indirect,
},

Interpreter_curcop: uint16(vms.interpreter.curcop),
Expand Down
13 changes: 6 additions & 7 deletions interpreter/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/interpreter"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
"go.opentelemetry.io/ebpf-profiler/metrics"
npsr "go.opentelemetry.io/ebpf-profiler/nopanicslicereader"
"go.opentelemetry.io/ebpf-profiler/remotememory"
"go.opentelemetry.io/ebpf-profiler/successfailurecounter"
"go.opentelemetry.io/ebpf-profiler/support"
"go.opentelemetry.io/ebpf-profiler/tpbase"
"go.opentelemetry.io/ebpf-profiler/util"
)

Expand Down Expand Up @@ -371,19 +371,18 @@ func (p *pythonInstance) GetAndResetMetrics() ([]metrics.Metric, error) {
}, nil
}

func (p *pythonInstance) UpdateTSDInfo(ebpf interpreter.EbpfHandler, pid libpf.PID,
tsdInfo tpbase.TSDInfo,
) error {
func (p *pythonInstance) UpdateLibcInfo(ebpf interpreter.EbpfHandler, pid libpf.PID,
libcInfo libc.LibcInfo) error {
d := p.d
vm := &d.vmStructs
cdata := support.PyProcInfo{
AutoTLSKeyAddr: uint64(d.autoTLSKey) + uint64(p.bias),
Version: d.version,

TsdInfo: support.TSDInfo{
Offset: tsdInfo.Offset,
Multiplier: tsdInfo.Multiplier,
Indirect: tsdInfo.Indirect,
Offset: libcInfo.TSDInfo.Offset,
Multiplier: libcInfo.TSDInfo.Multiplier,
Indirect: libcInfo.TSDInfo.Indirect,
},

PyThreadState_frame: uint8(vm.PyThreadState.Frame),
Expand Down
6 changes: 3 additions & 3 deletions interpreter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"unsafe"

"go.opentelemetry.io/ebpf-profiler/host"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/lpm"
"go.opentelemetry.io/ebpf-profiler/metrics"
"go.opentelemetry.io/ebpf-profiler/process"
"go.opentelemetry.io/ebpf-profiler/remotememory"
"go.opentelemetry.io/ebpf-profiler/reporter"
"go.opentelemetry.io/ebpf-profiler/tpbase"
"go.opentelemetry.io/ebpf-profiler/util"
)

Expand Down Expand Up @@ -143,9 +143,9 @@ type Instance interface {
SynchronizeMappings(ebpf EbpfHandler, exeReporter reporter.ExecutableReporter,
pr process.Process, mappings []process.Mapping) error

// UpdateTSDInfo is called when the process C-library Thread Specific Data related
// UpdateLibcInfo is called when the process C-library related
// introspection data has been updated.
UpdateTSDInfo(ebpf EbpfHandler, pid libpf.PID, info tpbase.TSDInfo) error
UpdateLibcInfo(ebpf EbpfHandler, pid libpf.PID, info libc.LibcInfo) error

// Symbolize converts one ebpf frame to one or more (if inlining was expanded) libpf.Frame.
// The resulting libpf.Frame values are appended to frames.
Expand Down
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 tpbase // import "go.opentelemetry.io/ebpf-profiler/tpbase"
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"errors"
Expand Down
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 tpbase
package libc

import (
"debug/elf"
Expand Down
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 tpbase // import "go.opentelemetry.io/ebpf-profiler/tpbase"
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"bytes"
Expand Down
21 changes: 19 additions & 2 deletions tpbase/libc.go → libc/libc.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 tpbase // import "go.opentelemetry.io/ebpf-profiler/tpbase"
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"debug/elf"
Expand All @@ -11,6 +11,12 @@ import (
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
)

// LibcInfo contains introspection information extracted from the C-library
type LibcInfo struct {
// TSDInfo is the TSDInfo extracted for this C-library
TSDInfo TSDInfo
}

// TSDInfo contains information to access C-library's Thread Specific Data from eBPF
type TSDInfo struct {
// Offset is the pointer difference from "tpbase" pointer to the C-library
Expand Down Expand Up @@ -84,8 +90,19 @@ func IsPotentialTSDDSO(filename string) bool {
return libcRegex.MatchString(filename)
}

func ExtractLibcInfo(ef *pfelf.File) (*LibcInfo, error) {
tsdinfo, err := extractTSDInfo(ef)
if err != nil {
return nil, err
}

return &LibcInfo{
TSDInfo: *tsdinfo,
}, nil
}

// ExtractTSDInfo extracts the introspection data for pthread thread specific data.
func ExtractTSDInfo(ef *pfelf.File) (*TSDInfo, error) {
func extractTSDInfo(ef *pfelf.File) (*TSDInfo, error) {
_, code, err := ef.SymbolData("__pthread_getspecific", 2048)
if err != nil {
_, code, err = ef.SymbolData("pthread_getspecific", 2048)
Expand Down
2 changes: 1 addition & 1 deletion tpbase/libc_aarch64.go → libc/libc_aarch64.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 tpbase // import "go.opentelemetry.io/ebpf-profiler/tpbase"
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion tpbase/libc_test.go → libc/libc_test.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 tpbase
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"debug/elf"
Expand Down
3 changes: 2 additions & 1 deletion tpbase/libc_x86.go → libc/libc_x86.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package tpbase // import "go.opentelemetry.io/ebpf-profiler/tpbase"
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"errors"

Expand Down
4 changes: 2 additions & 2 deletions tpbase/tpbase.go → libc/tpbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
// relative to the 'struct task_struct'. This is needed to support Thread Local
// Storage access in eBPF.

package tpbase // import "go.opentelemetry.io/ebpf-profiler/tpbase"
package libc // import "go.opentelemetry.io/ebpf-profiler/libc"

import (
"fmt"
"runtime"
)

func GetAnalyzers() ([]Analyzer, error) {
func GetTpBaseAnalyzers() ([]Analyzer, error) {
switch runtime.GOARCH {
case "amd64":
return getAnalyzersX86(), nil
Expand Down
16 changes: 8 additions & 8 deletions processmanager/execinfomanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/ebpf-profiler/interpreter/php"
"go.opentelemetry.io/ebpf-profiler/interpreter/python"
"go.opentelemetry.io/ebpf-profiler/interpreter/ruby"
"go.opentelemetry.io/ebpf-profiler/libc"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
"go.opentelemetry.io/ebpf-profiler/libpf/xsync"
Expand All @@ -32,7 +33,6 @@ import (
sdtypes "go.opentelemetry.io/ebpf-profiler/nativeunwind/stackdeltatypes"
pmebpf "go.opentelemetry.io/ebpf-profiler/processmanager/ebpfapi"
"go.opentelemetry.io/ebpf-profiler/support"
"go.opentelemetry.io/ebpf-profiler/tpbase"
"go.opentelemetry.io/ebpf-profiler/tracer/types"
"go.opentelemetry.io/ebpf-profiler/util"
)
Expand Down Expand Up @@ -61,8 +61,8 @@ type ExecutableInfo struct {
// instance belongs to was previously identified as an interpreter. Otherwise,
// this field is nil.
Data interpreter.Data
// TSDInfo stores TSD information if the executable is libc, otherwise nil.
TSDInfo *tpbase.TSDInfo
// LibcInfo stores libc information if the executable is libc, otherwise nil.
LibcInfo *libc.LibcInfo
}

// ExecutableInfoManager manages all per-executable (FileID) information that we require to
Expand Down Expand Up @@ -164,7 +164,7 @@ func (mgr *ExecutableInfoManager) AddOrIncRef(fileID host.FileID,
}
var (
intervalData sdtypes.IntervalData
tsdInfo *tpbase.TSDInfo
libcInfo *libc.LibcInfo
ref mapRef
gaps []util.Range
err error
Expand Down Expand Up @@ -198,9 +198,9 @@ func (mgr *ExecutableInfoManager) AddOrIncRef(fileID host.FileID,
}

// Also gather TSD info if applicable.
if tpbase.IsPotentialTSDDSO(elfRef.FileName()) {
if libc.IsPotentialTSDDSO(elfRef.FileName()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is now a bit awkwardly named, but it can potentially match libpthread, so changing constitutes an actual change to the logic. For now, i'm leaving it as-is.

if ef, errx := elfRef.GetELF(); errx == nil {
tsdInfo, _ = tpbase.ExtractTSDInfo(ef)
libcInfo, _ = libc.ExtractLibcInfo(ef)
}
}

Expand All @@ -226,8 +226,8 @@ func (mgr *ExecutableInfoManager) AddOrIncRef(fileID host.FileID,
// Insert a corresponding record into our map.
info = &entry{
ExecutableInfo: ExecutableInfo{
Data: state.detectAndLoadInterpData(loaderInfo),
TSDInfo: tsdInfo,
Data: state.detectAndLoadInterpData(loaderInfo),
LibcInfo: libcInfo,
},
mapRef: ref,
rc: 1,
Expand Down
Loading