Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Profiler] Enable ETW support by default for .NET Framework #6724

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,27 +34,47 @@ 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();
}

[TestAppFact("Samples.Computer01")]
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();
}

[TestAppFact("Samples.Computer01")]
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();
}

[TestAppFact("Samples.Computer01")]
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,16 @@ 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);
auto expectedValue =
#ifdef LINUX
false;
#else
true;
#endif
ASSERT_THAT(configuration.IsEtwEnabled(), expectedValue);
}

TEST_F(ConfigurationTest, CheckEtwIsEnabledIfEnvVarSetToTrue)
Expand Down
Loading