Skip to content

Commit

Permalink
Take state only
Browse files Browse the repository at this point in the history
  • Loading branch information
tebaikin committed Nov 27, 2023
1 parent 0a8cd19 commit 5f50435
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Vostok.Metrics.System/Host/TcpStateCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public void Collect(HostMetrics metrics)

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
IterateOverTcpConnections(info =>
IterateOverTcpConnections(state =>
{
if (!states.ContainsKey(info.State))
states[info.State] = 0;
states[info.State]++;
if (!states.ContainsKey(state))
states[state] = 0;
states[state]++;
});
}
else
Expand Down Expand Up @@ -65,7 +65,7 @@ public void Collect(HostMetrics metrics)
}

#if NET6_0_OR_GREATER
private unsafe void IterateOverTcpConnections(Action<TcpInfo> handle)
private static unsafe void IterateOverTcpConnections(Action<TcpState> handle)
{
var size = 0U;
uint result;
Expand Down Expand Up @@ -103,9 +103,9 @@ private unsafe void IterateOverTcpConnections(Action<TcpInfo> handle)
var localPort = row.localPort1 << 8 | row.localPort2;
var remotePort = state == TcpState.Listen ? 0 : row.remotePort1 << 8 | row.remotePort2;

var info = new TcpInfo(state, new IPEndPoint(row.localAddr, localPort), new IPEndPoint(row.remoteAddr, remotePort));
// var info = new TcpInfo(state, new IPEndPoint(row.localAddr, localPort), new IPEndPoint(row.remoteAddr, remotePort));

handle(info);
handle(state);

span = span[sizeof(Interop.IpHlpApi.MibTcpRow)..];
}
Expand Down Expand Up @@ -164,12 +164,12 @@ private unsafe void IterateOverTcpConnections(Action<TcpInfo> handle)
var localPort = row.localPort1 << 8 | row.localPort2;
var remotePort = ((state == TcpState.Listen) ? 0 : row.remotePort1 << 8 | row.remotePort2);

var info = new TcpInfo(
state,
new IPEndPoint(new IPAddress(row.localAddrAsSpan, row.localScopeId), localPort),
new IPEndPoint(new IPAddress(row.remoteAddrAsSpan, row.remoteScopeId), remotePort));
// var info = new TcpInfo(
// state,
// new IPEndPoint(new IPAddress(row.localAddrAsSpan, row.localScopeId), localPort),
// new IPEndPoint(new IPAddress(row.remoteAddrAsSpan, row.remoteScopeId), remotePort));

handle(info);
handle(state);
// We increment the pointer to the next row.
span = span.Slice(sizeof(Interop.IpHlpApi.MibTcp6RowOwnerPid));
}
Expand Down

0 comments on commit 5f50435

Please sign in to comment.