Skip to content

Commit 27ca282

Browse files
committed
Test frame cache
1 parent e1a17dd commit 27ca282

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

config/cli_flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ func parseCLIArgs(osArgs []string) (*Arguments, error) {
369369
Destination: &args.CollectContext,
370370
Sources: cli.EnvVars("DD_HOST_PROFILING_COLLECT_CONTEXT"),
371371
},
372+
&cli.IntFlag{
373+
Name: "frame-cache-size",
374+
Value: -1,
375+
Hidden: true,
376+
Usage: "Size of the frame cache.",
377+
Destination: &args.FrameCacheSize,
378+
Sources: cli.EnvVars("DD_HOST_PROFILING_FRAME_CACHE_SIZE"),
379+
},
372380
},
373381
Action: func(_ context.Context, cmd *cli.Command) error {
374382
args.cmd = cmd

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ type Config struct {
8282
EnableSplitByService bool
8383
SplitServiceSuffix string
8484
CollectContext bool
85+
FrameCacheSize int64
8586
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ require (
180180
// To update the Datadog/opentelemetry-ebpf-profiler dependency on latest commit on datadog branch, change the following line to:
181181
// replace go.opentelemetry.io/ebpf-profiler => github.com/DataDog/opentelemetry-ebpf-profiler datadog
182182
// and run `go mod tidy`
183-
replace go.opentelemetry.io/ebpf-profiler => github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20250924090340-f5c7be4f1db8
183+
replace go.opentelemetry.io/ebpf-profiler => github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20250923132052-1acd58a76dca

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/
4040
github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM=
4141
github.com/DataDog/jsonapi v0.12.0 h1:N4e9RpmUflcV5hzceltSz8XUpM3PMtQr5C9Bhv0g87s=
4242
github.com/DataDog/jsonapi v0.12.0/go.mod h1:FUSGF3bwMARlVfXEoFo9R/CVlYYy9BGL4C/Prf6Ke3M=
43-
github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20250924090340-f5c7be4f1db8 h1:nD9//aAtguUe/eQiBZE7Eht9YcmuomkdSPTtGPhL1PI=
44-
github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20250924090340-f5c7be4f1db8/go.mod h1:979ZsArUaDUVrCkyAbg1ZfU7yClJeHpB5vOvCjemnCE=
43+
github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20250923132052-1acd58a76dca h1:BJhB21iKkWsyHIyg49dzgVAviGHHICwztuL1hORbUYg=
44+
github.com/DataDog/opentelemetry-ebpf-profiler v0.0.0-20250923132052-1acd58a76dca/go.mod h1:979ZsArUaDUVrCkyAbg1ZfU7yClJeHpB5vOvCjemnCE=
4545
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.27.0 h1:5US5SqqhfkZkg/E64uvn7YmeTwnudJHtlPEH/LOT99w=
4646
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.27.0/go.mod h1:VRo4D6rj92AExpVBlq3Gcuol9Nm1bber12KyxRjKGWw=
4747
github.com/DataDog/sketches-go v1.4.7 h1:eHs5/0i2Sdf20Zkj0udVFWuCrXGRFig2Dcfm5rtcTxc=

runner/runner.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import (
2626
"go.opentelemetry.io/ebpf-profiler/host"
2727
"go.opentelemetry.io/ebpf-profiler/libpf"
2828
"go.opentelemetry.io/ebpf-profiler/metrics"
29-
otelreporter "go.opentelemetry.io/ebpf-profiler/reporter"
3029
"go.opentelemetry.io/ebpf-profiler/times"
31-
"go.opentelemetry.io/ebpf-profiler/tracehandler"
3230
"go.opentelemetry.io/ebpf-profiler/tracer"
3331
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
3432
"go.opentelemetry.io/otel/metric/noop"
@@ -58,19 +56,29 @@ const (
5856
defaultProcessesCacheSize = 16384
5957
)
6058

61-
func startTraceHandling(ctx context.Context, rep otelreporter.TraceReporter,
62-
intervals *times.Times, trc *tracer.Tracer, cacheSize uint32) error {
59+
func startTraceHandling(ctx context.Context, trc *tracer.Tracer) error {
6360
// Spawn monitors for the various result maps
6461
traceCh := make(chan *host.Trace)
6562

6663
if err := trc.StartMapMonitors(ctx, traceCh); err != nil {
6764
return fmt.Errorf("failed to start map monitors: %w", err)
6865
}
6966

70-
_, err := tracehandler.Start(ctx, rep, trc.TraceProcessor(),
71-
traceCh, intervals, cacheSize)
67+
go func() {
68+
// Poll the output channels
69+
for {
70+
select {
71+
case trace := <-traceCh:
72+
if trace != nil {
73+
trc.HandleTrace(trace)
74+
}
75+
case <-ctx.Done():
76+
return
77+
}
78+
}
79+
}()
7280

73-
return err
81+
return nil
7482
}
7583

7684
func appendEndpoint(symbolEndpoints []reporter.SymbolEndpoint, site, apiKey, appKey string) []reporter.SymbolEndpoint {
@@ -155,9 +163,6 @@ func Run(mainCtx context.Context, c *config.Config) ExitCode {
155163
return failure("Failed to probe eBPF syscall: %v", err)
156164
}
157165

158-
// disable trace handler cache because it consumes too much memory for almost no CPU benefit
159-
traceHandlerCacheSize := uint32(0)
160-
161166
intervals := times.New(c.ReporterInterval, c.MonitorInterval,
162167
c.ProbabilisticInterval)
163168

@@ -293,6 +298,7 @@ func Run(mainCtx context.Context, c *config.Config) ExitCode {
293298

294299
// Load the eBPF code and map definitions
295300
trc, err := tracer.NewTracer(mainCtx, &tracer.Config{
301+
TraceReporter: rep,
296302
ExecutableReporter: rep,
297303
Intervals: intervals,
298304
IncludeTracers: includeTracers,
@@ -305,6 +311,7 @@ func Run(mainCtx context.Context, c *config.Config) ExitCode {
305311
ProbabilisticInterval: c.ProbabilisticInterval,
306312
ProbabilisticThreshold: uint(c.ProbabilisticThreshold),
307313
IncludeEnvVars: includeEnvVars,
314+
FrameCacheSize: int(c.FrameCacheSize),
308315
})
309316
if err != nil {
310317
return failure("Failed to load eBPF tracer: %v", err)
@@ -340,7 +347,7 @@ func Run(mainCtx context.Context, c *config.Config) ExitCode {
340347
// change this log line update also the system test.
341348
log.Printf("Attached sched monitor")
342349

343-
if err := startTraceHandling(mainCtx, rep, intervals, trc, traceHandlerCacheSize); err != nil {
350+
if err := startTraceHandling(mainCtx, trc); err != nil {
344351
return failure("Failed to start trace handling: %v", err)
345352
}
346353

0 commit comments

Comments
 (0)