Skip to content

Commit

Permalink
Better statistics logging
Browse files Browse the repository at this point in the history
  • Loading branch information
HakanL committed Sep 1, 2023
1 parent 8a9695a commit ec2a3d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Haukcode.sACN/Model/SendStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class SendStatistics

public int QueueLength { get; set; }

public int DestinationCount { get; set; }

public int SlowSends { get; set; }
}
}
21 changes: 16 additions & 5 deletions src/Haukcode.sACN/SACNClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public SendData()
private readonly MemoryPool<byte> memoryPool = MemoryPool<byte>.Shared;
private int droppedPackets;
private int slowSends;
private readonly HashSet<(IPAddress Destination, ushort UniverseId)> usedDestinations = new();

public SACNClient(Guid senderId, string senderName, IPAddress localAddress, int port = 5568)
{
Expand Down Expand Up @@ -195,12 +196,14 @@ public SendStatistics SendStatistics
{
DroppedPackets = this.droppedPackets,
QueueLength = this.sendQueue.Count,
SlowSends = this.slowSends
SlowSends = this.slowSends,
DestinationCount = this.usedDestinations.Count
};

// Reset
this.droppedPackets = 0;
this.slowSends = 0;
this.usedDestinations.Clear();

return sendStatistics;
}
Expand Down Expand Up @@ -264,8 +267,11 @@ private async Task Receiver()
}
catch (Exception ex)
{
Console.WriteLine($"Exception in Receiver handler: {ex.Message}");
this.errorSubject.OnNext(ex);
if (!(ex is OperationCanceledException))
{
Console.WriteLine($"Exception in Receiver handler: {ex.Message}");
this.errorSubject.OnNext(ex);
}
}
}
}
Expand Down Expand Up @@ -300,8 +306,11 @@ private async Task Sender()
}
catch (Exception ex)
{
Console.WriteLine($"Exception in Sender handler: {ex.Message}");
this.errorSubject.OnNext(ex);
if (!(ex is OperationCanceledException))
{
Console.WriteLine($"Exception in Sender handler: {ex.Message}");
this.errorSubject.OnNext(ex);
}
}
}
}
Expand Down Expand Up @@ -455,6 +464,7 @@ public void SendPacket(ushort universeId, IPAddress destination, SACNPacket pack
Destination = ipEndPoint
};

this.usedDestinations.Add((destination, universeId));
this.sendQueue.Add(newSendData);
}

Expand All @@ -476,6 +486,7 @@ public void SendPacket(ushort universeId, SACNPacket packet)
DataLength = packetLength
};

this.usedDestinations.Add((null, universeId));
this.sendQueue.Add(newSendData);

//var socketData = GetSendSocket(universeId);
Expand Down

0 comments on commit ec2a3d6

Please sign in to comment.