dotnet-stack: Fix parsing of thread names (#3860)
authorGrisha Kotler <grisha-kotler@users.noreply.github.com>
Tue, 2 May 2023 22:49:57 +0000 (01:49 +0300)
committerGitHub <noreply@github.com>
Tue, 2 May 2023 22:49:57 +0000 (15:49 -0700)
src/Tools/dotnet-stack/ReportCommand.cs

index 324c299532cce0c7c7c459f03a8c8deebcacfe56..76ca818eadf28dbadc65be9f07f10eecb3927d10 100644 (file)
@@ -121,7 +121,11 @@ namespace Microsoft.Diagnostics.Tools.Stack
                         // 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))
                         {