From c0c22c579de29540542b248ad9029d1fcaca7d64 Mon Sep 17 00:00:00 2001 From: Christophe Nasarre Date: Thu, 27 Feb 2025 13:47:46 +0100 Subject: [PATCH 1/4] enable ETW support by default --- .../ProfilerEngine/Datadog.Profiler.Native/Configuration.cpp | 2 +- .../test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/profiler/src/ProfilerEngine/Datadog.Profiler.Native/Configuration.cpp b/profiler/src/ProfilerEngine/Datadog.Profiler.Native/Configuration.cpp index 23cc6d5dfb8f..98622ac3b7c2 100644 --- a/profiler/src/ProfilerEngine/Datadog.Profiler.Native/Configuration.cpp +++ b/profiler/src/ProfilerEngine/Datadog.Profiler.Native/Configuration.cpp @@ -90,7 +90,7 @@ Configuration::Configuration() _cpuProfilingInterval = ExtractCpuProfilingInterval(1ms); } - _isEtwEnabled = GetEnvironmentValue(EnvironmentVariables::EtwEnabled, false); + _isEtwEnabled = GetEnvironmentValue(EnvironmentVariables::EtwEnabled, true); _deploymentMode = GetEnvironmentValue(EnvironmentVariables::SsiDeployed, DeploymentMode::Manual); _isEtwLoggingEnabled = GetEnvironmentValue(EnvironmentVariables::EtwLoggingEnabled, false); _etwReplayEndpoint = GetEnvironmentValue(EnvironmentVariables::EtwReplayEndpoint, DefaultEmptyString); diff --git a/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp b/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp index acc44783b160..80939f2893e0 100644 --- a/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp +++ b/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp @@ -852,10 +852,10 @@ TEST_F(ConfigurationTest, CheckCIVisibilitySpanIdValueIfSetTo0) ASSERT_THAT(configuration.GetCIVisibilitySpanId(), 0ull); } -TEST_F(ConfigurationTest, CheckEtwIsDisabledByDefault) +TEST_F(ConfigurationTest, CheckEtwIsEnabledByDefault) { auto configuration = Configuration{}; - ASSERT_THAT(configuration.IsEtwEnabled(), false); + ASSERT_THAT(configuration.IsEtwEnabled(), true); } TEST_F(ConfigurationTest, CheckEtwIsEnabledIfEnvVarSetToTrue) From 0eecc7d0deaf4bfb85a38fd68e5a0bbde9d0ed26 Mon Sep 17 00:00:00 2001 From: Christophe Nasarre Date: Fri, 28 Feb 2025 13:01:52 +0100 Subject: [PATCH 2/4] Fix tests to avoid errors in logs --- .../SmokeTests/Computer01Test.cs | 24 +++++++++++++++++++ .../SmokeTests/ExceptionGeneratorTest.cs | 14 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/Computer01Test.cs b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/Computer01Test.cs index 0c02ef0823dd..5c261c03df35 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/Computer01Test.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/Computer01Test.cs @@ -18,6 +18,10 @@ public Computer01Test(ITestOutputHelper output) _output = output; } + // NOTE: now that .NET Framework is supported by default, the profiler tries to connect + // to connect to the Agent using namedpipe. Since the Agent does not exist in CI, + // the ETW support is disabled in the tests for .NET Framework. + // scenarios implemented in Computer01: // ----------------------------------------------------------------------------------------- // 1: start threads with specific callstacks in another appdomain @@ -30,6 +34,11 @@ public Computer01Test(ITestOutputHelper output) public void CheckAppDomain(string appName, string framework, string appAssembly) { var runner = new SmokeTestRunner(appName, framework, appAssembly, commandLine: "--scenario 1", output: _output); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } + runner.RunAndCheck(); } @@ -37,6 +46,11 @@ public void CheckAppDomain(string appName, string framework, string appAssembly) public void CheckGenerics(string appName, string framework, string appAssembly) { var runner = new SmokeTestRunner(appName, framework, appAssembly, commandLine: "--scenario 2", output: _output); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } + runner.RunAndCheck(); } @@ -44,6 +58,11 @@ public void CheckGenerics(string appName, string framework, string appAssembly) public void CheckPi(string appName, string framework, string appAssembly) { var runner = new SmokeTestRunner(appName, framework, appAssembly, commandLine: "--scenario 4", output: _output); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } + runner.RunAndCheck(); } @@ -51,6 +70,11 @@ public void CheckPi(string appName, string framework, string appAssembly) public void CheckFibonacci(string appName, string framework, string appAssembly) { var runner = new SmokeTestRunner(appName, framework, appAssembly, commandLine: "--scenario 5", output: _output); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } + runner.RunAndCheck(); } diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/ExceptionGeneratorTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/ExceptionGeneratorTest.cs index c9128ca5cc9c..66cc99a63210 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/ExceptionGeneratorTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/ExceptionGeneratorTest.cs @@ -18,10 +18,19 @@ public ExceptionGeneratorTest(ITestOutputHelper output) _output = output; } + // NOTE: now that .NET Framework is supported by default, the profiler tries to connect + // to connect to the Agent using namedpipe. Since the Agent does not exist in CI, + // the ETW support is disabled in the tests for .NET Framework. + [TestAppFact("Samples.ExceptionGenerator")] public void CheckSmoke(string appName, string framework, string appAssembly) { var runner = new SmokeTestRunner(appName, framework, appAssembly, _output); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } + runner.RunAndCheck(); } @@ -30,6 +39,11 @@ public void CheckSmoke(string appName, string framework, string appAssembly) public void CheckSmokeForOldWayToStackWalk(string appName, string framework, string appAssembly) { var runner = new SmokeTestRunner(appName, framework, appAssembly, _output); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } + runner.EnvironmentHelper.CustomEnvironmentVariables[EnvironmentVariables.UseBacktrace2] = "0"; runner.RunAndCheck(); } From 233508d84224c77182c64e9da146852afe4d9ee2 Mon Sep 17 00:00:00 2001 From: Christophe Nasarre Date: Fri, 28 Feb 2025 16:13:49 +0100 Subject: [PATCH 3/4] Fix tests for default ETW support --- .../Allocations/AllocationsProfilerTest.cs | 1 - .../Contention/ContentionProfilerTest.cs | 1 - .../CpuAndWallTime/CpuAndWallTimeTest.cs | 2 +- .../GarbageCollections/GarbageCollectionsProfilerTest.cs | 1 - .../WindowsOnly/EtwEventsTests.cs | 3 --- .../WindowsOnly/NamedPipeTestcs.cs | 8 ++++++++ 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Allocations/AllocationsProfilerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Allocations/AllocationsProfilerTest.cs index 6f8bf0196298..a73c9fc195e5 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Allocations/AllocationsProfilerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Allocations/AllocationsProfilerTest.cs @@ -135,7 +135,6 @@ public void ShouldGetAllocationSamplesViaEtw(string appName, string framework, s EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.AllocationProfilerEnabled, "1"); - runner.Environment.SetVariable(EnvironmentVariables.EtwEnabled, "1"); Guid guid = Guid.NewGuid(); runner.Environment.SetVariable(EnvironmentVariables.EtwReplayEndpoint, "\\\\.\\pipe\\DD_ETW_TEST_AGENT-" + guid); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs index 968d90841d54..4ea4db151ca7 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs @@ -95,7 +95,6 @@ public void ShouldGetLockContentionSamplesViaEtw(string appName, string framewor EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "1"); - runner.Environment.SetVariable(EnvironmentVariables.EtwEnabled, "1"); Guid guid = Guid.NewGuid(); runner.Environment.SetVariable(EnvironmentVariables.EtwReplayEndpoint, "\\\\.\\pipe\\DD_ETW_TEST_AGENT-" + guid); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs index 2a95b27776a3..0d7ae83fac88 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs @@ -101,7 +101,7 @@ public void CheckCpuDurationInSamples(string appName, string framework, string a // --> could be flacky otherwise var totalDuration = runner.TotalTestDurationInMilliseconds * 1000000L; Assert.True(cpuDuration <= totalDuration); - + var cpuSamples = SamplesHelper.GetValueSum(runner.Environment.PprofDir, 1); cpuSamples.Should().BeGreaterThan(0); } diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectionsProfilerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectionsProfilerTest.cs index e86af0af7f50..c5010b8a5026 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectionsProfilerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectionsProfilerTest.cs @@ -70,7 +70,6 @@ public void ShouldGetGarbageCollectionSamplesViaEtw(string appName, string frame runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "0"); - runner.Environment.SetVariable(EnvironmentVariables.EtwEnabled, "1"); Guid guid = Guid.NewGuid(); runner.Environment.SetVariable(EnvironmentVariables.EtwReplayEndpoint, "\\\\.\\pipe\\DD_ETW_TEST_AGENT-" + guid); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs index a8074acd0f26..1a1b56396e7d 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs @@ -28,9 +28,6 @@ public void CheckErrorWhenNoAgentIsAvailable(string appName, string framework, s { var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 1"); - // Overwrite the one set in EnvironmentHelper - runner.Environment.SetVariable(EnvironmentVariables.EtwEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs index 4d47aa468b72..f92eeea6e838 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs @@ -24,6 +24,10 @@ public NamedPipeTestcs(ITestOutputHelper output) _output = output; } + // NOTE: now that .NET Framework is supported by default, the profiler tries to connect + // to connect to the Agent using namedpipe. Since the Agent does not exist in CI, + // the ETW support is disabled in the tests for .NET Framework. + [TestAppFact("Samples.Computer01")] public void CheckProfilesSentThroughNamedPipe(string appName, string framework, string appAssembly) { @@ -33,6 +37,10 @@ public void CheckProfilesSentThroughNamedPipe(string appName, string framework, "failed ddog_prof_Exporter_send: operation was canceled" }; var runner = new SmokeTestRunner(appName, framework, appAssembly, commandLine: "--scenario 1", output: _output, transportType: TransportType.NamedPipe); + if (framework == "net462") + { + runner.EnvironmentHelper.SetVariable(EnvironmentVariables.EtwEnabled, "0"); + } runner.RunAndCheckWithRetries(RetryCount, errorExceptions); } From 1fb82cc27850beaafee17dd4517b963b64134fe7 Mon Sep 17 00:00:00 2001 From: Christophe Nasarre Date: Mon, 3 Mar 2025 17:52:09 +0100 Subject: [PATCH 4/4] Fix test for linux --- .../Datadog.Profiler.Native.Tests/ConfigurationTest.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp b/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp index 80939f2893e0..c96dcb8bca8a 100644 --- a/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp +++ b/profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp @@ -855,7 +855,13 @@ TEST_F(ConfigurationTest, CheckCIVisibilitySpanIdValueIfSetTo0) TEST_F(ConfigurationTest, CheckEtwIsEnabledByDefault) { auto configuration = Configuration{}; - ASSERT_THAT(configuration.IsEtwEnabled(), true); + auto expectedValue = +#ifdef LINUX + false; +#else + true; +#endif + ASSERT_THAT(configuration.IsEtwEnabled(), expectedValue); } TEST_F(ConfigurationTest, CheckEtwIsEnabledIfEnvVarSetToTrue)