Skip to content

Commit 8c82f87

Browse files
authored
[Profiler] Make timer_create-based CPU profiler default (#6315)
1 parent f15905a commit 8c82f87

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

profiler/src/ProfilerEngine/Datadog.Profiler.Native/Configuration.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ std::string const Configuration::DefaultEmptyString = "";
2525
std::chrono::seconds const Configuration::DefaultDevUploadInterval = 20s;
2626
std::chrono::seconds const Configuration::DefaultProdUploadInterval = 60s;
2727
std::chrono::milliseconds const Configuration::DefaultCpuProfilingInterval = 9ms;
28+
CpuProfilerType const Configuration::DefaultCpuProfilerType =
29+
#ifdef _WINDOWS
30+
CpuProfilerType::ManualCpuTime;
31+
#else
32+
CpuProfilerType::TimerCreate;
33+
#endif
34+
2835

2936
Configuration::Configuration()
3037
{
@@ -98,7 +105,7 @@ Configuration::Configuration()
98105
_ssiLongLivedThreshold = ExtractSsiLongLivedThreshold();
99106
_isTelemetryToDiskEnabled = GetEnvironmentValue(EnvironmentVariables::TelemetryToDiskEnabled, false);
100107
_isSsiTelemetryEnabled = GetEnvironmentValue(EnvironmentVariables::SsiTelemetryEnabled, false);
101-
_cpuProfilerType = GetEnvironmentValue(EnvironmentVariables::CpuProfilerType, CpuProfilerType::ManualCpuTime);
108+
_cpuProfilerType = GetEnvironmentValue(EnvironmentVariables::CpuProfilerType, DefaultCpuProfilerType);
102109
}
103110

104111
fs::path Configuration::ExtractLogDirectory()

profiler/src/ProfilerEngine/Datadog.Profiler.Native/Configuration.h

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Configuration final : public IConfiguration
117117
static std::chrono::seconds const DefaultDevUploadInterval;
118118
static std::chrono::seconds const DefaultProdUploadInterval;
119119
static std::chrono::milliseconds const DefaultCpuProfilingInterval;
120+
static CpuProfilerType const DefaultCpuProfilerType;
120121

121122
bool _isProfilingEnabled;
122123
bool _isCpuProfilingEnabled;

profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/SignalHandlerTest.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ public void CheckSignalHandlerIsInstalledOnce(string appName, string framework,
4747
var logFile = Directory.GetFiles(runner.Environment.LogDir)
4848
.Single(f => Path.GetFileName(f).StartsWith("DD-DotNet-Profiler-Native-"));
4949

50-
var nbSignalHandlerInstallation = File.ReadLines(logFile)
51-
.Count(l => l.Contains("Successfully setup signal handler for"));
50+
File.ReadLines(logFile)
51+
.Count(l => l.Contains("Successfully setup signal handler for User defined signal 1 signal"))
52+
.Should().Be(1);
5253

53-
nbSignalHandlerInstallation.Should().Be(1);
54+
File.ReadLines(logFile)
55+
.Count(l => l.Contains("Successfully setup signal handler for Profiling timer expired signal"))
56+
.Should().Be(1);
5457
}
5558
}
5659
}

profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -1043,20 +1043,38 @@ TEST_F(ConfigurationTest, CheckDefaultCpuProfilerType)
10431043
{
10441044
EnvironmentHelper::EnvironmentVariable ar(EnvironmentVariables::CpuProfilerType, WStr(""));
10451045
auto configuration = Configuration{};
1046-
ASSERT_THAT(configuration.GetCpuProfilerType(), CpuProfilerType::ManualCpuTime);
1046+
auto expected =
1047+
#ifdef _WINDOWS
1048+
CpuProfilerType::ManualCpuTime;
1049+
#else
1050+
CpuProfilerType::TimerCreate;
1051+
#endif
1052+
ASSERT_THAT(configuration.GetCpuProfilerType(), expected);
10471053
}
10481054

10491055
TEST_F(ConfigurationTest, CheckDefaultCpuProfilerTypeWhenEnvVarNotSet)
10501056
{
10511057
auto configuration = Configuration{};
1052-
ASSERT_THAT(configuration.GetCpuProfilerType(), CpuProfilerType::ManualCpuTime);
1058+
auto expected =
1059+
#ifdef _WINDOWS
1060+
CpuProfilerType::ManualCpuTime;
1061+
#else
1062+
CpuProfilerType::TimerCreate;
1063+
#endif
1064+
ASSERT_THAT(configuration.GetCpuProfilerType(), expected);
10531065
}
10541066

10551067
TEST_F(ConfigurationTest, CheckUnknownCpuProfilerType)
10561068
{
10571069
EnvironmentHelper::EnvironmentVariable ar(EnvironmentVariables::CpuProfilerType, WStr("UnknownCpuProfilerType"));
10581070
auto configuration = Configuration{};
1059-
ASSERT_THAT(configuration.GetCpuProfilerType(), CpuProfilerType::ManualCpuTime);
1071+
auto expected =
1072+
#ifdef _WINDOWS
1073+
CpuProfilerType::ManualCpuTime;
1074+
#else
1075+
CpuProfilerType::TimerCreate;
1076+
#endif
1077+
ASSERT_THAT(configuration.GetCpuProfilerType(), expected);
10601078
}
10611079

10621080
TEST_F(ConfigurationTest, CheckManualCpuProfilerType)

0 commit comments

Comments
 (0)