Skip to content

Commit

Permalink
Adding support for both types (kprobe/perf_event) and moving the choi…
Browse files Browse the repository at this point in the history
…ce to go tags instead of Makefile

Signed-off-by: Amit Schendel <amitschendel@gmail.com>
  • Loading branch information
amitschendel committed Oct 15, 2024
1 parent 9256910 commit 0171838
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 7 deletions.
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
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 modified 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.
5 changes: 3 additions & 2 deletions support/support_amd64.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//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

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

import (
_ "embed"
Expand Down
5 changes: 3 additions & 2 deletions support/support_arm64.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//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

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

import (
_ "embed"
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 (
_ "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 (
_ "embed"
)

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

0 comments on commit 0171838

Please sign in to comment.