Skip to content
Merged
Changes from 2 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(")");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int firstIndex = threadFrame.IndexOf(")");
int firstIndex = threadFrame.IndexOf(')');

The char-overload is cheaper than the string-ovrelaod.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

int threadId = int.Parse(threadFrame.Substring(template.Length, firstIndex - template.Length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Substring the span-overload for int.Parse could be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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