public void Update(ConnectionStasticRecord record) { LastActivate = DateTime.Now; var stData = record.StasticData; var stPath = record.StasticPath; RTT = (long)stPath.SampleRtt; // TODO: Calculate pkt lost while ((_stasticRecords.Count > 0 && record.Timestamp.Subtract(_stasticRecords.First.Value.Timestamp).Seconds > 20) || _stasticRecords.Count > 5) { _stasticRecords.RemoveFirst(); } var lost = _stasticRecords.Select(record.CalculateLost) .DefaultIfEmpty(0) .Max(); _stasticRecords.AddLast(record); Lost = (uint)lost; // if (stData.DataSegsOut != 0) // { // Lost = (uint) ((stPath.FastRetran + stPath.PktsRetrans) * 100 / stData.DataSegsOut); // } // Controller.NotifyLogMessageAppend(false, // $"TotalPkt={stData.DataSegsOut},TotalBytes={stData.DataBytesOut},FastRetran={stPath.FastRetran},PktsRetrans={stPath.PktsRetrans},SndDupAckEpisodes={stPath.SndDupAckEpisodes},BytesRetrans={stPath.BytesRetrans}"); }
public double CalculateLost(ConnectionStasticRecord start) { if (Timestamp <= start.Timestamp) { return(0); } if (StasticData.DataBytesOut <= start.StasticData.DataBytesOut) { return(0); } if (StasticPath.BytesRetrans <= start.StasticPath.BytesRetrans) { return(0); } var sendDelta = StasticData.DataBytesOut - start.StasticData.DataBytesOut; var retransDelta = StasticPath.BytesRetrans - start.StasticPath.BytesRetrans; return((retransDelta * 100.0 / sendDelta).Clamp(0, 100)); }
protected override void DoWork(ProbeContext context) { var service = context.Service; var delay = context.Delay; while (!WorkingThreadStopping) { try { var currentPid = _gamePids; var connections = currentPid.Count > 0 ? Win32PInvoke_iphlpapi.GetAllTcpConnections() : null; if (connections != null) { var gameConnections = connections .Where(it => currentPid.Contains(it.ProcessId)) .GroupBy(it => it.ProcessId).ToDictionary(g => g.Key, g => g.ToList()); if (gameConnections.Count > 0) { var records = new List <ConnectionStasticRecord>(); foreach (var connection in gameConnections) { foreach (var row in connection.Value) { var stasticData = new Win32PInvoke_iphlpapi.TCP_ESTATS_DATA_ROD_v0(); var stasticPath = new Win32PInvoke_iphlpapi.TCP_ESTATS_PATH_ROD_v0(); if ( Win32PInvoke_iphlpapi.GetPerTcpConnectionEStats_Data(row, ref stasticData) && Win32PInvoke_iphlpapi.GetPerTcpConnectionEStats_Path(row, ref stasticPath) ) { var record = new ConnectionStasticRecord { Timestamp = DateTime.Now, TcpRow = row, StasticData = stasticData, StasticPath = stasticPath }; records.Add(record); } } } service.SubmitRecords(records); } else { service.SubmitRecords(null); } } else { service.SubmitRecords(null); } } catch (Exception ex) { service._controller?.NotifyLogMessageAppend(false, ex + "\n"); } SafeSleep(delay); } }