/// <summary> /// Retrieves summary statistics for a given message type for the last <see cref="numFrames"/> frames. /// </summary> /// <param name="messageType">The type of message to get summary statistics for.</param> /// <param name="numFrames">The number of frames to query against.</param> /// <param name="direction">The direction of the message type to get summary statistics for.</param> /// <returns> /// A tuple where: /// - the first element is a summed <see cref="DataPoint"/> for the given message type over the last <see cref="numFrames"/> frames. /// - the second element is the summed time that the last <see cref="numFrames"/> took. /// </returns> /// <exception cref="ArgumentOutOfRangeException">Thrown if <see cref="numFrames"/> is larger than the number of frames this stores.</exception> public (DataPoint, float) GetSummary(MessageTypeUnion messageType, int numFrames, Direction direction) { if (numFrames > sequenceLength) { throw new ArgumentOutOfRangeException($"Cannot fetch {numFrames} worth of data. This instance can only store to up {sequenceLength} frames."); } float totalTime = 0.0f; for (var i = 1; i <= numFrames; i++) { // Iterate through the ring buffer (can potentially wrap around). var index = (nextFrameIndex + i) % sequenceLength; totalTime += frameTimes[index]; } if (!Data.TryGetValue(messageType, out var data)) { return(new DataPoint(), totalTime); } DataPoint[] frameData; switch (direction) { case Direction.Incoming: frameData = data.Incoming; break; case Direction.Outgoing: frameData = data.Outgoing; break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } var summary = new DataPoint(); for (var i = 1; i <= numFrames; i++) { // Iterate through the ring buffer (can potentially wrap around). var index = (nextFrameIndex + i) % sequenceLength; summary += frameData[index]; } return(summary, totalTime); }
public (DataPoint, float) GetSummary(MessageTypeUnion messageType, int numFrames, Direction direction) { return(netStats.GetSummary(messageType, numFrames, direction)); }