Skip to content

Commit 7e06081

Browse files
committed
feat: generic probe support
Rename uprobe-specific code to generic probe terminology and add support for kprobes alongside uprobes. Update probe-ctrl tool to handle both probe types.
1 parent 806d2fe commit 7e06081

File tree

18 files changed

+495
-74
lines changed

18 files changed

+495
-74
lines changed

cli_flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var (
7171
envVarsHelp = "Comma separated list of environment variables that will be reported with the" +
7272
"captured profiling samples."
7373
probeLinkHelper = "Attach a probe to a symbol of an executable. " +
74-
"Expected format: /path/to/executable:symbol"
74+
"Expected format: probe_type:target[:symbol]. probe_type can be kprobe, kretprobe, uprobe, or uretprobe."
7575
loadProbeHelper = "Load generic eBPF program that can be attached externally to " +
7676
"various user or kernel space hooks."
7777
)
@@ -133,8 +133,8 @@ func parseArgs() (*controller.Config, error) {
133133

134134
fs.StringVar(&args.IncludeEnvVars, "env-vars", defaultEnvVarsValue, envVarsHelp)
135135

136-
fs.Func("uprobe-link", probeLinkHelper, func(link string) error {
137-
args.UProbeLinks = append(args.UProbeLinks, link)
136+
fs.Func("probe-link", probeLinkHelper, func(link string) error {
137+
args.ProbeLinks = append(args.ProbeLinks, link)
138138
return nil
139139
})
140140

collector/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Config struct {
1919
VerboseMode bool `mapstructure:"verbose_mode"`
2020
OffCPUThreshold float64 `mapstructure:"off_cpu_threshold"`
2121
IncludeEnvVars string `mapstructure:"include_env_vars"`
22-
UProbeLinks []string `mapstructure:"u_probe_links"`
22+
ProbeLinks []string `mapstructure:"probe_links"`
2323
LoadProbe bool `mapstructure:"load_probe"`
2424
MapScaleFactor uint `mapstructure:"map_scale_factor"`
2525
BPFVerifierLogLevel uint `mapstructure:"bpf_verifier_log_level"`

internal/controller/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (c *Controller) Start(ctx context.Context) error {
8888
ProbabilisticThreshold: c.config.ProbabilisticThreshold,
8989
OffCPUThreshold: uint32(c.config.OffCPUThreshold * float64(math.MaxUint32)),
9090
IncludeEnvVars: envVars,
91-
UProbeLinks: c.config.UProbeLinks,
91+
ProbeLinks: c.config.ProbeLinks,
9292
LoadProbe: c.config.LoadProbe,
9393
ExecutableReporter: c.config.ExecutableReporter,
9494
})
@@ -118,11 +118,11 @@ func (c *Controller) Start(ctx context.Context) error {
118118
log.Infof("Enabled off-cpu profiling with p=%f", c.config.OffCPUThreshold)
119119
}
120120

121-
if len(c.config.UProbeLinks) > 0 {
122-
if err := trc.AttachUProbes(c.config.UProbeLinks); err != nil {
123-
return fmt.Errorf("failed to attach uprobes: %v", err)
121+
if len(c.config.ProbeLinks) > 0 {
122+
if err := trc.AttachProbes(c.config.ProbeLinks); err != nil {
123+
return fmt.Errorf("failed to attach probes: %v", err)
124124
}
125-
log.Info("Attached uprobes")
125+
log.Info("Attached probes")
126126
}
127127

128128
if c.config.ProbabilisticThreshold < tracer.ProbabilisticThresholdMax {

reporter/base_reporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (b *baseReporter) ReportTraceEvent(trace *libpf.Trace, meta *samples.TraceE
4545
switch meta.Origin {
4646
case support.TraceOriginSampling:
4747
case support.TraceOriginOffCPU:
48-
case support.TraceOriginUProbe:
48+
case support.TraceOriginProbe:
4949
default:
5050
return fmt.Errorf("skip reporting trace for %d origin: %w", meta.Origin,
5151
errUnknownOrigin)

reporter/internal/pdata/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (p *Pdata) Generate(tree samples.TraceEventsTree,
8282
for _, origin := range []libpf.Origin{
8383
support.TraceOriginSampling,
8484
support.TraceOriginOffCPU,
85-
support.TraceOriginUProbe,
85+
support.TraceOriginProbe,
8686
} {
8787
if len(originToEvents[origin]) == 0 {
8888
// Do not append empty profiles.
@@ -146,7 +146,7 @@ func (p *Pdata) setProfile(
146146
case support.TraceOriginOffCPU:
147147
st.SetTypeStrindex(stringSet.Add("off_cpu"))
148148
st.SetUnitStrindex(stringSet.Add("nanoseconds"))
149-
case support.TraceOriginUProbe:
149+
case support.TraceOriginProbe:
150150
st.SetTypeStrindex(stringSet.Add("events"))
151151
st.SetUnitStrindex(stringSet.Add("count"))
152152
default:
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
#include "tracemgmt.h"
33
#include "types.h"
44

5-
// uprobe__generic serves as entry point for uprobe based profiling.
6-
SEC("uprobe/generic")
7-
int uprobe__generic(void *ctx)
5+
static EBPF_INLINE int probe__generic(struct pt_regs *ctx)
86
{
97
u64 pid_tgid = bpf_get_current_pid_tgid();
108
u32 pid = pid_tgid >> 32;
@@ -16,5 +14,19 @@ int uprobe__generic(void *ctx)
1614

1715
u64 ts = bpf_ktime_get_ns();
1816

19-
return collect_trace(ctx, TRACE_UPROBE, pid, tid, ts, 0);
17+
return collect_trace(ctx, TRACE_PROBE, pid, tid, ts, 0);
18+
}
19+
20+
// uprobe__generic serves as entry point for uprobe based profiling.
21+
SEC("uprobe/generic")
22+
int uprobe__generic(void *ctx)
23+
{
24+
return probe__generic((struct pt_regs *)ctx);
25+
}
26+
27+
// kprobe__generic serves as entry point for kprobe based profiling.
28+
SEC("kprobe/generic")
29+
int kprobe__generic(struct pt_regs *ctx)
30+
{
31+
return probe__generic(ctx);
2032
}

support/ebpf/tracer.ebpf.amd64

23 KB
Binary file not shown.

support/ebpf/tracer.ebpf.arm64

23 KB
Binary file not shown.

support/ebpf/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ typedef enum TraceOrigin {
362362
TRACE_UNKNOWN,
363363
TRACE_SAMPLING,
364364
TRACE_OFF_CPU,
365-
TRACE_UPROBE,
365+
TRACE_PROBE,
366366
} TraceOrigin;
367367

368368
// MAX_FRAME_UNWINDS defines the maximum number of frames per

support/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)