Skip to content
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 @@ -28,13 +28,11 @@ HANDLE FrameworkThreadInfo::GetOsThreadHandle() const
std::string FrameworkThreadInfo::GetProfileThreadId()
{
std::stringstream buffer;
buffer << "<0> [#" << _osThreadId << "]";
buffer << _osThreadId;
return buffer.str();
}

std::string FrameworkThreadInfo::GetProfileThreadName()
{
std::stringstream buffer;
buffer << "Managed thread (name unknown) [#" << _osThreadId << "]";
return buffer.str();
return std::string("");
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ inline void ManagedThreadInfo::ReleaseLock()
inline std::string ManagedThreadInfo::BuildProfileThreadId()
{
std::stringstream builder;
builder << "<" << std::dec << _profilerThreadInfoId << "> [#" << _osThreadId << "]";
builder << std::dec << _osThreadId;

return builder.str();
}
Expand All @@ -231,13 +231,10 @@ inline std::string ManagedThreadInfo::BuildProfileThreadName()
auto threadName = _threadName;
if (threadName.empty())
{
nameBuilder << "Managed thread (name unknown)";
return "";
}
else
{
nameBuilder << shared::ToString(std::move(threadName));
}
nameBuilder << " [#" << _osThreadId << "]";

nameBuilder << shared::ToString(std::move(threadName));

return nameBuilder.str();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void RawSampleTransformer::SetThreadDetails(const RawSample& rawSample, std::sha
return;
}

sample->SetThreadId("<0> [#0]");
sample->SetThreadName("Managed thread (name unknown) [#0]");
sample->SetThreadId("0");
sample->SetThreadName("");

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ShouldNotCrashWhenNullOrEmptyThreadName(string appName, string frame
return (l.Name == "thread name");
}).Value;

if (threadName.Contains("Managed thread (name unknown) ["))
if (threadName == "")
{
var stackTrace = sample.StackTrace(profile);
if (stackTrace.FramesCount == 0)
Expand All @@ -52,9 +52,13 @@ public void ShouldNotCrashWhenNullOrEmptyThreadName(string appName, string frame
return;
}
}
else if (threadName.Contains(".NET Long Running Task ["))
else if (threadName.StartsWith(".NET "))
{
// expected task that is waiting for nameless threads to join
// .NET ThreadPool IO, .NET TP Worker, .NET Long Running Task, .NET Timer, .NET TP Wait, etc...
}
else if (threadName == "CLR thread (garbage collector)")
{
// hard coded name for GC threads
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public static int GetThreadCount(string directory)
public static HashSet<int> GetThreadIds(string directory)
{
HashSet<int> ids = new();
var regex = new Regex(@"<[0-9]+> \[#(?<OsId>[0-9]+)\]", RegexOptions.Compiled);
foreach (var profile in GetProfiles(directory))
{
foreach (var sample in profile.Sample)
Expand All @@ -99,8 +98,7 @@ public static HashSet<int> GetThreadIds(string directory)
{
if (label.Name == "thread id")
{
var match = regex.Match(label.Value);
ids.Add(int.Parse(match.Groups["OsId"].Value));
ids.Add(int.Parse(label.Value));
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<ClCompile Include="FrameStoreHelper.cpp" />
<ClCompile Include="IMetricsSenderFactoryTest.cpp" />
<ClCompile Include="LinkedListTest.cpp" />
<ClCompile Include="ManagedThreadInfoTest.cpp" />
<ClCompile Include="ProfileExporterTest.cpp" />
<ClCompile Include="LinuxStackFramesCollectorTest.cpp" />
<ClCompile Include="LogTest.cpp" />
Expand Down Expand Up @@ -220,4 +221,4 @@
<Error Condition="!Exists('$(PackagesDir)\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-static.1.8.1.7\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-static.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-static.1.8.1.7\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-static.targets'))" />
<Error Condition="!Exists('..\..\..\packages\gmock.1.11.0\build\native\gmock.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\gmock.1.11.0\build\native\gmock.targets'))" />
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
<ClCompile Include="CpuSampleProviderTest.cpp">
<Filter>Tests</Filter>
</ClCompile>
<ClCompile Include="ManagedThreadInfoTest.cpp">
<Filter>Tests</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ProfilerEngine\Datadog.Profiler.Native\HResultConverter.h">
Expand Down Expand Up @@ -225,4 +228,4 @@
<ItemGroup>
<ResourceCompile Include="Resources.rc" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
TEST(ManagedThreadInfoTest, CheckGetProfileThreadId)
{
auto threadInfo = ManagedThreadInfo::CreateForTest(1);
ASSERT_EQ(threadInfo->GetProfileThreadId(), "<1> [#1]");
ASSERT_EQ(threadInfo->GetProfileThreadId(), "1");
}

TEST(ManagedThreadInfoTest, CheckGetProfileThreadIdWithSetThreadName)
{
auto threadInfo = ManagedThreadInfo::CreateForTest(42);
threadInfo->SetThreadName(WStr("Test Thread"));
ASSERT_EQ(threadInfo->GetProfileThreadId(), "<1> [#42]");
ASSERT_EQ(threadInfo->GetProfileThreadId(), "42");
}

TEST(ManagedThreadInfoTest, CheckGetProfileThreadName)
{
auto threadInfo = ManagedThreadInfo::CreateForTest(1);
ASSERT_EQ(threadInfo->GetProfileThreadName(), "Managed thread (name unknown) [#1]");
ASSERT_EQ(threadInfo->GetProfileThreadName(), "");
}

TEST(ManagedThreadInfoTest, CheckGetProfileThreadNameWithSetThreadName)
{
auto threadInfo = ManagedThreadInfo::CreateForTest(1);
threadInfo->SetThreadName(WStr("Test Thread"));
ASSERT_EQ(threadInfo->GetProfileThreadName(), "Test Thread [#1]");
ASSERT_EQ(threadInfo->GetProfileThreadName(), "Test Thread");
}
Loading