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 @@ -407,15 +407,25 @@ internal static IPInterfaceStatisticsTable ParseInterfaceStatisticsTableFromFile
{
sr.ReadLine();
sr.ReadLine();
int index = 0;
Span<Range> pieces = stackalloc Range[18]; // [0]-[16] used, +1 to ensure any additional segment goes into [17]
while (!sr.EndOfStream)
{
string line = sr.ReadLine()!;
if (line.Contains(name))
{
Comment on lines 414 to 415
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to remove the Contains here since we're checking with SequenceEqual later again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the Contains is cheap so let it do a precheck might have a better performance.

Span<Range> pieces = stackalloc Range[18]; // [0] skipped, [1]-[16] used, +1 to ensure any additional segment goes into [17]
ReadOnlySpan<char> lineSpan = line;
pieces = pieces.Slice(0, lineSpan.SplitAny(pieces, " :", StringSplitOptions.RemoveEmptyEntries));
int pieceCount = lineSpan.SplitAny(pieces, " :", StringSplitOptions.RemoveEmptyEntries);

if (pieceCount < 17)
{
continue;
}

if (!lineSpan[pieces[0]].SequenceEqual(name))
{
// The adapter name doesn't exactly match.
continue;
}

return new IPInterfaceStatisticsTable()
{
Expand All @@ -438,7 +448,6 @@ internal static IPInterfaceStatisticsTable ParseInterfaceStatisticsTableFromFile
CompressedPacketsTransmitted = ParseUInt64AndClampToInt64(lineSpan[pieces[16]]),
};
}
index += 1;
}

throw ExceptionHelper.CreateForParseFailure();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
wlan0a: 20000 394 2 4 6 8 10 12 429496730000 208 1 2 3 4 5 6
wlan0: 26622 394 2 4 6 8 10 12 429496730000 208 1 2 3 4 5 6
lo: 18446744073709551615 302 0 0 0 0 0 0 30008 302 0 0 0 0 0 0