RakNetStatistics.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief A structure that holds all statistical data returned by RakNet.
  12. ///
  13. #ifndef __RAK_NET_STATISTICS_H
  14. #define __RAK_NET_STATISTICS_H
  15. #include "PacketPriority.h"
  16. #include "Export.h"
  17. #include "RakNetTypes.h"
  18. namespace RakNet
  19. {
  20. enum RNSPerSecondMetrics
  21. {
  22. /// How many bytes per pushed via a call to RakPeerInterface::Send()
  23. USER_MESSAGE_BYTES_PUSHED,
  24. /// How many user message bytes were sent via a call to RakPeerInterface::Send(). This is less than or equal to USER_MESSAGE_BYTES_PUSHED.
  25. /// A message would be pushed, but not yet sent, due to congestion control
  26. USER_MESSAGE_BYTES_SENT,
  27. /// How many user message bytes were resent. A message is resent if it is marked as reliable, and either the message didn't arrive or the message ack didn't arrive.
  28. USER_MESSAGE_BYTES_RESENT,
  29. /// How many user message bytes were received, and returned to the user successfully.
  30. USER_MESSAGE_BYTES_RECEIVED_PROCESSED,
  31. /// How many user message bytes were received, but ignored due to data format errors. This will usually be 0.
  32. USER_MESSAGE_BYTES_RECEIVED_IGNORED,
  33. /// How many actual bytes were sent, including per-message and per-datagram overhead, and reliable message acks
  34. ACTUAL_BYTES_SENT,
  35. /// How many actual bytes were received, including overead and acks.
  36. ACTUAL_BYTES_RECEIVED,
  37. /// \internal
  38. RNS_PER_SECOND_METRICS_COUNT
  39. };
  40. /// \brief Network Statisics Usage
  41. ///
  42. /// Store Statistics information related to network usage
  43. struct RAK_DLL_EXPORT RakNetStatistics
  44. {
  45. /// For each type in RNSPerSecondMetrics, what is the value over the last 1 second?
  46. uint64_t valueOverLastSecond[RNS_PER_SECOND_METRICS_COUNT];
  47. /// For each type in RNSPerSecondMetrics, what is the total value over the lifetime of the connection?
  48. uint64_t runningTotal[RNS_PER_SECOND_METRICS_COUNT];
  49. /// When did the connection start?
  50. /// \sa RakNet::GetTimeUS()
  51. RakNet::TimeUS connectionStartTime;
  52. /// Is our current send rate throttled by congestion control?
  53. /// This value should be true if you send more data per second than your bandwidth capacity
  54. bool isLimitedByCongestionControl;
  55. /// If \a isLimitedByCongestionControl is true, what is the limit, in bytes per second?
  56. uint64_t BPSLimitByCongestionControl;
  57. /// Is our current send rate throttled by a call to RakPeer::SetPerConnectionOutgoingBandwidthLimit()?
  58. bool isLimitedByOutgoingBandwidthLimit;
  59. /// If \a isLimitedByOutgoingBandwidthLimit is true, what is the limit, in bytes per second?
  60. uint64_t BPSLimitByOutgoingBandwidthLimit;
  61. /// For each priority level, how many messages are waiting to be sent out?
  62. unsigned int messageInSendBuffer[NUMBER_OF_PRIORITIES];
  63. /// For each priority level, how many bytes are waiting to be sent out?
  64. double bytesInSendBuffer[NUMBER_OF_PRIORITIES];
  65. /// How many messages are waiting in the resend buffer? This includes messages waiting for an ack, so should normally be a small value
  66. /// If the value is rising over time, you are exceeding the bandwidth capacity. See BPSLimitByCongestionControl
  67. unsigned int messagesInResendBuffer;
  68. /// How many bytes are waiting in the resend buffer. See also messagesInResendBuffer
  69. uint64_t bytesInResendBuffer;
  70. /// Over the last second, what was our packetloss? This number will range from 0.0 (for none) to 1.0 (for 100%)
  71. float packetlossLastSecond;
  72. /// What is the average total packetloss over the lifetime of the connection?
  73. float packetlossTotal;
  74. RakNetStatistics& operator +=(const RakNetStatistics& other)
  75. {
  76. unsigned i;
  77. for (i=0; i < NUMBER_OF_PRIORITIES; i++)
  78. {
  79. messageInSendBuffer[i]+=other.messageInSendBuffer[i];
  80. bytesInSendBuffer[i]+=other.bytesInSendBuffer[i];
  81. }
  82. for (i=0; i < RNS_PER_SECOND_METRICS_COUNT; i++)
  83. {
  84. valueOverLastSecond[i]+=other.valueOverLastSecond[i];
  85. runningTotal[i]+=other.runningTotal[i];
  86. }
  87. return *this;
  88. }
  89. };
  90. /// Verbosity level currently supports 0 (low), 1 (medium), 2 (high)
  91. /// \param[in] s The Statistical information to format out
  92. /// \param[in] buffer The buffer containing a formated report
  93. /// \param[in] verbosityLevel
  94. /// 0 low
  95. /// 1 medium
  96. /// 2 high
  97. /// 3 debugging congestion control
  98. void RAK_DLL_EXPORT StatisticsToString( RakNetStatistics *s, char *buffer, int verbosityLevel );
  99. } // namespace RakNet
  100. #endif
粤ICP备19079148号