Skip to content

Commit

Permalink
Adding ebpf code
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
  • Loading branch information
amitschendel committed Oct 20, 2024
1 parent 002255c commit f9a1f63
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 25 deletions.
5 changes: 3 additions & 2 deletions support/ebpf/dotnet_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ ErrorCode unwind_one_dotnet_frame(PerCPURecord *record, DotnetProcInfo *vi, bool
// unwind_dotnet is the entry point for tracing when invoked from the native tracer
// or interpreter dispatcher. It does not reset the trace object and will append the
// dotnet stack frames to the trace object for the current CPU.
BPF_PROBE(unwind_dotnet)
int unwind_dotnet(struct pt_regs *ctx)
static inline int unwind_dotnet(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record) {
Expand Down Expand Up @@ -291,3 +290,5 @@ int unwind_dotnet(struct pt_regs *ctx)
DEBUG_PRINT("dotnet: tail call for next frame unwinder (%d) failed", unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_dotnet, unwind_dotnet, unwind_dotnet);
17 changes: 12 additions & 5 deletions support/ebpf/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
#define OPTI_HELPERS_H

// Macros for BPF program type and context handling.
#ifdef EXTERNAL_TRIGGER
#define BPF_PROBE(name) SEC("kprobe/"#name)
#else
#define BPF_PROBE(name) SEC("perf_event/"#name)
#endif
#define DEFINE_DUAL_PROGRAM(name, section_name, func) \
SEC("perf_event/" #section_name) \
int name##_perf(struct pt_regs *ctx) \
{ \
return func(ctx); \
} \
\
SEC("kprobe/" #section_name) \
int name##_kprobe(struct pt_regs *ctx) \
{ \
return func(ctx); \
}

#endif // OPTI_HELPERS_H
5 changes: 3 additions & 2 deletions support/ebpf/hotspot_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,7 @@ static ErrorCode hotspot_unwind_one_frame(PerCPURecord *record, HotspotProcInfo
// unwind_hotspot is the entry point for tracing when invoked from the native tracer
// and it recursive unwinds all HotSpot frames and then jumps back to unwind further
// native frames that follow.
BPF_PROBE(unwind_hotspot)
int unwind_hotspot(struct pt_regs *ctx)
static inline int unwind_hotspot(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record)
Expand Down Expand Up @@ -929,3 +928,5 @@ int unwind_hotspot(struct pt_regs *ctx)
DEBUG_PRINT("jvm: tail call for next frame unwinder (%d) failed", unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_hotspot, unwind_hotspot, unwind_hotspot);
5 changes: 3 additions & 2 deletions support/ebpf/interpreter_dispatcher.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ void maybe_add_apm_info(Trace *trace) {
trace->apm_transaction_id.as_int, corr_buf.trace_flags);
}

BPF_PROBE(unwind_stop)
int unwind_stop(struct pt_regs *ctx)
static inline int unwind_stop(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record)
Expand Down Expand Up @@ -241,6 +240,8 @@ int unwind_stop(struct pt_regs *ctx)
return 0;
}

DEFINE_DUAL_PROGRAM(unwind_stop, unwind_stop, unwind_stop);

char _license[] SEC("license") = "GPL";
// this number will be interpreted by the elf loader
// to set the current running kernel version
Expand Down
15 changes: 11 additions & 4 deletions support/ebpf/native_stack_trace.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,7 @@ static inline ErrorCode get_usermode_regs(struct pt_regs *ctx,

#endif

BPF_PROBE(unwind_native)
int unwind_native(struct pt_regs *ctx)
static inline int unwind_native(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record)
Expand Down Expand Up @@ -801,6 +800,8 @@ int unwind_native(struct pt_regs *ctx)
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_native, unwind_native, unwind_native);

static inline
int collect_trace(struct pt_regs *ctx) {
// Get the PID and TGID register.
Expand Down Expand Up @@ -859,8 +860,14 @@ int collect_trace(struct pt_regs *ctx) {
return -1;
}

BPF_PROBE(native_tracer_entry)
int native_tracer_entry(struct bpf_perf_event_data *ctx)
SEC("perf_event/native_tracer_entry")
int native_tracer_entry_perf(struct bpf_perf_event_data *ctx)
{
return collect_trace((struct pt_regs*) &ctx->regs);
}

SEC("kprobe/native_tracer_entry")
int native_tracer_entry_kprobe(struct pt_regs *ctx)
{
return collect_trace(ctx);
}
5 changes: 3 additions & 2 deletions support/ebpf/perl_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ int walk_perl_stack(PerCPURecord *record, const PerlProcInfo *perlinfo) {
// unwind_perl is the entry point for tracing when invoked from the native tracer
// or interpreter dispatcher. It does not reset the trace object and will append the
// Perl stack frames to the trace object for the current CPU.
BPF_PROBE(unwind_perl)
int unwind_perl(struct pt_regs *ctx)
static inline int unwind_perl(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record) {
Expand Down Expand Up @@ -428,3 +427,5 @@ int unwind_perl(struct pt_regs *ctx)
tail_call(ctx, unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_perl, unwind_perl, unwind_perl);
5 changes: 3 additions & 2 deletions support/ebpf/php_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ int walk_php_stack(PerCPURecord *record, PHPProcInfo *phpinfo, bool is_jitted) {
return unwinder;
}

BPF_PROBE(unwind_php)
int unwind_php(struct pt_regs *ctx)
static inline int unwind_php(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record)
Expand Down Expand Up @@ -241,3 +240,5 @@ int unwind_php(struct pt_regs *ctx)
tail_call(ctx, unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_php, unwind_php, unwind_php)
5 changes: 3 additions & 2 deletions support/ebpf/python_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ ErrorCode get_PyFrame(const PyProcInfo *pyinfo, void **frame) {
// unwind_python is the entry point for tracing when invoked from the native tracer
// or interpreter dispatcher. It does not reset the trace object and will append the
// Python stack frames to the trace object for the current CPU.
BPF_PROBE(unwind_python)
int unwind_python(struct pt_regs *ctx)
static inline int unwind_python(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record)
Expand Down Expand Up @@ -320,3 +319,5 @@ int unwind_python(struct pt_regs *ctx)
tail_call(ctx, unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_python, unwind_python, unwind_python);
5 changes: 3 additions & 2 deletions support/ebpf/ruby_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ ErrorCode walk_ruby_stack(PerCPURecord *record, const RubyProcInfo *rubyinfo,
return ERR_OK;
}

BPF_PROBE(unwind_ruby)
int unwind_ruby(struct pt_regs *ctx)
static inline int unwind_ruby(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record)
Expand Down Expand Up @@ -275,3 +274,5 @@ int unwind_ruby(struct pt_regs *ctx)
tail_call(ctx, unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_ruby, unwind_ruby, unwind_ruby);
Binary file modified support/ebpf/tracer.ebpf.release.amd64
Binary file not shown.
Binary file removed support/ebpf/tracer.ebpf.release.external.amd64
Binary file not shown.
5 changes: 3 additions & 2 deletions support/ebpf/v8_tracer.ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ ErrorCode unwind_one_v8_frame(PerCPURecord *record, V8ProcInfo *vi, bool top) {
// unwind_v8 is the entry point for tracing when invoked from the native tracer
// or interpreter dispatcher. It does not reset the trace object and will append the
// V8 stack frames to the trace object for the current CPU.
BPF_PROBE(unwind_v8)
int unwind_v8(struct pt_regs *ctx)
static inline int unwind_v8(struct pt_regs *ctx)
{
PerCPURecord *record = get_per_cpu_record();
if (!record) {
Expand Down Expand Up @@ -330,3 +329,5 @@ int unwind_v8(struct pt_regs *ctx)
DEBUG_PRINT("v8: tail call for next frame unwinder (%d) failed", unwinder);
return -1;
}

DEFINE_DUAL_PROGRAM(unwind_v8, unwind_v8, unwind_v8);

0 comments on commit f9a1f63

Please sign in to comment.