From 04c819d87351b4b881032565d5e670f5a4e297f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Wed, 27 Sep 2023 13:37:56 +0200 Subject: [PATCH] profiler: enable execution traces by default for go1.21+ (#2226) --- profiler/go_lt_1_21.go | 12 ++++++++++++ profiler/options.go | 8 +++++++- profiler/profiler_test.go | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 profiler/go_lt_1_21.go diff --git a/profiler/go_lt_1_21.go b/profiler/go_lt_1_21.go new file mode 100644 index 0000000000..bbb9a3fc03 --- /dev/null +++ b/profiler/go_lt_1_21.go @@ -0,0 +1,12 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2023 Datadog, Inc. + +//go:build !go1.21 + +package profiler + +func init() { + executionTraceEnabledDefault = false +} diff --git a/profiler/options.go b/profiler/options.go index e40593a5f1..8ee05316dd 100644 --- a/profiler/options.go +++ b/profiler/options.go @@ -552,11 +552,17 @@ type executionTraceConfig struct { warned bool } +// executionTraceEnabledDefault depends on the Go version and CPU architecture, +// see go_lt_1_21.go and this [article][] for more details. +// +// [article]: https://blog.felixge.de/waiting-for-go1-21-execution-tracing-with-less-than-one-percent-overhead/ +var executionTraceEnabledDefault = runtime.GOARCH == "arm64" || runtime.GOARCH == "amd64" + // Refresh updates the execution trace configuration to reflect any run-time // changes to the configuration environment variables, applying defaults as // needed. func (e *executionTraceConfig) Refresh() { - e.Enabled = internal.BoolEnv("DD_PROFILING_EXECUTION_TRACE_ENABLED", false) + e.Enabled = internal.BoolEnv("DD_PROFILING_EXECUTION_TRACE_ENABLED", executionTraceEnabledDefault) e.Period = internal.DurationEnv("DD_PROFILING_EXECUTION_TRACE_PERIOD", 15*time.Minute) e.Limit = internal.IntEnv("DD_PROFILING_EXECUTION_TRACE_LIMIT_BYTES", defaultExecutionTraceSizeLimit) diff --git a/profiler/profiler_test.go b/profiler/profiler_test.go index 592dc7a5b1..0721ca3a16 100644 --- a/profiler/profiler_test.go +++ b/profiler/profiler_test.go @@ -236,6 +236,10 @@ func TestProfilerPassthrough(t *testing.T) { if testing.Short() { return } + beforeExecutionTraceEnabledDefault := executionTraceEnabledDefault + executionTraceEnabledDefault = false + defer func() { executionTraceEnabledDefault = beforeExecutionTraceEnabledDefault }() + out := make(chan batch) p, err := newProfiler() require.NoError(t, err) @@ -378,6 +382,9 @@ func TestAllUploaded(t *testing.T) { "goroutines.pprof", "goroutineswait.pprof", } + if executionTraceEnabledDefault && seq == 0 { + expected = append(expected, "go.trace") + } assert.ElementsMatch(t, expected, profile.event.Attachments) assert.Contains(t, profile.tags, fmt.Sprintf("profile_seq:%d", seq))