Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integ #3

Merged
merged 6 commits into from
Oct 15, 2024
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ generate:
go generate ./...

ebpf:
$(MAKE) $(EBPF_FLAGS) -j$(shell nproc) -C support/ebpf $(if $(EXTERNAL),EXTERNAL=1,)
$(MAKE) $(EBPF_FLAGS) -j$(shell nproc) -C support/ebpf EXTERNAL=external
$(MAKE) $(EBPF_FLAGS) -j$(shell nproc) -C support/ebpf

ebpf-profiler: generate ebpf
go build $(GO_FLAGS) -tags $(GO_TAGS)
Expand Down
8 changes: 3 additions & 5 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"io"
"os"
"strconv"
"strings"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -63,7 +62,7 @@ func trimMappingPath(path string) string {
return path
}

func parseMappings(mapsFile io.Reader, pid libpf.PID) ([]Mapping, error) {
func parseMappings(mapsFile io.Reader) ([]Mapping, error) {
mappings := make([]Mapping, 0)
scanner := bufio.NewScanner(mapsFile)
buf := make([]byte, 512)
Expand Down Expand Up @@ -119,8 +118,7 @@ func parseMappings(mapsFile io.Reader, pid libpf.PID) ([]Mapping, error) {
continue
}
} else {
// This is needed to support running the profiler from whithin a container.
path = "/proc/" + strconv.Itoa(int(pid)) + "/root/" + trimMappingPath(path)
path = trimMappingPath(path)
path = strings.Clone(path)
}

Expand Down Expand Up @@ -150,7 +148,7 @@ func (sp *systemProcess) GetMappings() ([]Mapping, error) {
}
defer mapsFile.Close()

mappings, err := parseMappings(mapsFile, sp.pid)
mappings, err := parseMappings(mapsFile)
if err == nil {
fileToMapping := make(map[string]*Mapping)
for idx := range mappings {
Expand Down
16 changes: 8 additions & 8 deletions process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var testMappings = `55fe82710000-55fe8273c000 r--p 00000000 fd:01 1068432
7f63c8ebf000-7f63c8fef000 r-xp 0001c000 1fd:01 1075944 /tmp/usr_lib_x86_64-linux-gnu_libopensc.so.6.0.0`

func TestParseMappings(t *testing.T) {
mappings, err := parseMappings(strings.NewReader(testMappings), 1)
mappings, err := parseMappings(strings.NewReader(testMappings))
require.NoError(t, err)
assert.NotNil(t, mappings)

Expand All @@ -37,7 +37,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1068432,
Length: 0x2c000,
FileOffset: 0,
Path: "/proc/1/root//tmp/usr_bin_seahorse",
Path: "/tmp/usr_bin_seahorse",
},
{
Vaddr: 0x55fe8273c000,
Expand All @@ -46,7 +46,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1068432,
Length: 0x82000,
FileOffset: 0x2c000,
Path: "/proc/1/root//tmp/usr_bin_seahorse",
Path: "/tmp/usr_bin_seahorse",
},
{
Vaddr: 0x55fe827be000,
Expand All @@ -55,7 +55,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1068432,
Length: 0x78000,
FileOffset: 0xae000,
Path: "/proc/1/root//tmp/usr_bin_seahorse",
Path: "/tmp/usr_bin_seahorse",
},
{
Vaddr: 0x55fe82836000,
Expand All @@ -64,7 +64,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1068432,
Length: 0x7000,
FileOffset: 0x125000,
Path: "/proc/1/root//tmp/usr_bin_seahorse",
Path: "/tmp/usr_bin_seahorse",
},
{
Vaddr: 0x55fe8283d000,
Expand All @@ -73,7 +73,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1068432,
Length: 0x1000,
FileOffset: 0x12c000,
Path: "/proc/1/root//tmp/usr_bin_seahorse",
Path: "/tmp/usr_bin_seahorse",
},
{
Vaddr: 0x7f63c8c3e000,
Expand All @@ -82,7 +82,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1048922,
Length: 0x1A2000,
FileOffset: 544768,
Path: "/proc/1/root//tmp/usr_lib_x86_64-linux-gnu_libcrypto.so.1.1",
Path: "/tmp/usr_lib_x86_64-linux-gnu_libcrypto.so.1.1",
},
{
Vaddr: 0x7f63c8ebf000,
Expand All @@ -91,7 +91,7 @@ func TestParseMappings(t *testing.T) {
Inode: 1075944,
Length: 0x130000,
FileOffset: 114688,
Path: "/proc/1/root//tmp/usr_lib_x86_64-linux-gnu_libopensc.so.6.0.0",
Path: "/tmp/usr_lib_x86_64-linux-gnu_libopensc.so.6.0.0",
},
}
assert.Equal(t, expected, mappings)
Expand Down
17 changes: 15 additions & 2 deletions support/ebpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ TARGET_ARCH ?= $(NATIVE_ARCH)
# Valid values: release, debug
BUILD_TYPE ?= release

TRACER_NAME ?= tracer.ebpf.$(BUILD_TYPE).$(TARGET_ARCH)
ifdef EXTERNAL
TRACER_NAME ?= tracer.ebpf.$(BUILD_TYPE).$(EXTERNAL).$(TARGET_ARCH)
else
TRACER_NAME ?= tracer.ebpf.$(BUILD_TYPE).$(TARGET_ARCH)
endif

ifeq ($(TARGET_ARCH),arm64)
TARGET_FLAGS = -target aarch64-linux-gnu
Expand All @@ -55,7 +59,11 @@ FLAGS=$(TARGET_FLAGS) \
$(EXTERNAL_FLAG)

SRCS := $(wildcard *.ebpf.c)
OBJS := $(SRCS:.c=.$(BUILD_TYPE).$(TARGET_ARCH).o)
ifdef EXTERNAL
OBJS := $(SRCS:.c=.$(BUILD_TYPE).$(EXTERNAL).$(TARGET_ARCH).o)
else
OBJS := $(SRCS:.c=.$(BUILD_TYPE).$(TARGET_ARCH).o)
endif

.DEFAULT_GOAL := all

Expand All @@ -81,8 +89,13 @@ errors.h: ../../tools/errors-codegen/errors.json

%.ebpf.c: errors.h ;

ifdef EXTERNAL
%.ebpf.$(BUILD_TYPE).$(EXTERNAL).$(TARGET_ARCH).o: %.ebpf.c
$(BPF_CLANG) $(FLAGS) -o $@
else
%.ebpf.$(BUILD_TYPE).$(TARGET_ARCH).o: %.ebpf.c
$(BPF_CLANG) $(FLAGS) -o $@
endif

$(TRACER_NAME): $(OBJS)
$(BPF_LINK) $^ -o - | $(LLC) -march=bpf -mcpu=v2 -filetype=obj -o $@
Expand Down
Binary file added support/ebpf/tracer.ebpf.release.amd64
Binary file not shown.
Binary file removed support/ebpf/tracer.ebpf.release.arm64
Binary file not shown.
Binary file added support/ebpf/tracer.ebpf.release.external.amd64
Binary file not shown.
3 changes: 2 additions & 1 deletion support/support_amd64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build amd64 && !dummy
//go:build amd64 && !dummy && !external_trigger
// +build amd64,!dummy,!external_trigger

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
Expand Down
3 changes: 2 additions & 1 deletion support/support_arm64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build arm64 && !dummy
//go:build arm64 && !dummy && !external_trigger
// +build arm64,!dummy,!external_trigger

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
Expand Down
14 changes: 14 additions & 0 deletions support/support_external_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build amd64 && !dummy && external_trigger
// +build amd64,!dummy,external_trigger

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package support // import "go.opentelemetry.io/ebpf-profiler/support"

import (
_ "embed"
)

//go:embed ebpf/tracer.ebpf.release.external.amd64
var tracerData []byte
14 changes: 14 additions & 0 deletions support/support_external_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build arm64 && !dummy && external_trigger
// +build arm64,!dummy,external_trigger

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package support // import "go.opentelemetry.io/ebpf-profiler/support"

import (
_ "embed"
)

//go:embed ebpf/tracer.ebpf.release.external.arm64
var tracerData []byte