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

Fix parsing of thread names #3860

Merged
merged 4 commits into from
May 2, 2023
Merged
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
6 changes: 5 additions & 1 deletion src/Tools/dotnet-stack/ReportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ private static async Task<int> Report(CancellationToken ct, IConsole console, in
// Thread id is in the frame name as "Thread (<ID>)"
string template = "Thread (";
string threadFrame = stackSource.GetFrameName(stackSource.GetFrameIndex(stackIndex), false);
int threadId = int.Parse(threadFrame.Substring(template.Length, threadFrame.Length - (template.Length + 1)));

// we are looking for the first index of ) because
// we need to handle a thread name like: Thread (4008) (.NET IO ThreadPool Worker)
int firstIndex = threadFrame.IndexOf(')');
int threadId = int.Parse(threadFrame.AsSpan(template.Length, firstIndex - template.Length));

if (samplesForThread.TryGetValue(threadId, out List<StackSourceSample> samples))
{
Expand Down