New AzNetworking metrics display plus connection quality debug widgets using ImGui
Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
@@ -22,6 +22,7 @@ namespace AzNetworking
|
||||
const AZ::TimeMs deltaTimeMs = currentTimeMs - m_lastLoggedTimeMs;
|
||||
|
||||
m_atoms[m_activeAtom].m_bytesTransmitted += byteCount;
|
||||
m_atoms[m_activeAtom].m_packetsSent++;
|
||||
m_atoms[m_activeAtom].m_timeAccumulatorMs += deltaTimeMs;
|
||||
|
||||
if (m_atoms[m_activeAtom].m_timeAccumulatorMs >= m_maxSampleTimeMs)
|
||||
@@ -32,6 +33,11 @@ namespace AzNetworking
|
||||
m_lastLoggedTimeMs = currentTimeMs;
|
||||
}
|
||||
|
||||
void DatarateMetrics::LogPacketLost()
|
||||
{
|
||||
m_atoms[m_activeAtom].m_packetsLost++;
|
||||
}
|
||||
|
||||
float DatarateMetrics::GetBytesPerSecond() const
|
||||
{
|
||||
const uint32_t sampleAtom = 1 - m_activeAtom;
|
||||
@@ -47,6 +53,18 @@ namespace AzNetworking
|
||||
return (bytesLogged * 1000.0f) / sampleTime; // (* 1000) to convert from bytes per millisecond to bytes per second
|
||||
}
|
||||
|
||||
float DatarateMetrics::GetLossRatePercent() const
|
||||
{
|
||||
const uint32_t sampleAtom = 1 - m_activeAtom;
|
||||
|
||||
if (m_atoms[sampleAtom].m_packetsSent == 0)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return float(m_atoms[sampleAtom].m_packetsLost) / float(m_atoms[sampleAtom].m_packetsSent);
|
||||
}
|
||||
|
||||
void ConnectionComputeRtt::LogPacketSent(PacketId packetId, AZ::TimeMs currentTimeMs)
|
||||
{
|
||||
for (uint32_t i = 0; i < MaxTrackableEntries; i++)
|
||||
|
||||
@@ -19,8 +19,10 @@ namespace AzNetworking
|
||||
{
|
||||
DatarateAtom() = default;
|
||||
|
||||
AZ::TimeMs m_timeAccumulatorMs = AZ::TimeMs{ 0 };
|
||||
uint32_t m_bytesTransmitted = 0;
|
||||
AZ::TimeMs m_timeAccumulatorMs = AZ::TimeMs{0};
|
||||
uint32_t m_packetsSent = 0;
|
||||
uint32_t m_packetsLost = 0;
|
||||
};
|
||||
|
||||
//! @class DatarateMetrics
|
||||
@@ -40,19 +42,26 @@ namespace AzNetworking
|
||||
//! @param currentTimeMs current process time in milliseconds
|
||||
void LogPacket(uint32_t byteCount, AZ::TimeMs currentTimeMs);
|
||||
|
||||
//! Invoked whenever a packet has determined to be lost.
|
||||
void LogPacketLost();
|
||||
|
||||
//! Retrieve a sample of the datarate being incurred by this connection in bytes per second.
|
||||
//! @return datarate for traffic sent to or from the connection in bytes per second
|
||||
float GetBytesPerSecond() const;
|
||||
|
||||
//! Returns the estimated packet loss rate as a percentage of packets.
|
||||
//! @return the estimated percentage loss rate
|
||||
float GetLossRatePercent() const;
|
||||
|
||||
private:
|
||||
|
||||
//! Used internally to swap buffers used for metric gathering.
|
||||
void SwapBuffers();
|
||||
|
||||
static constexpr AZ::TimeMs MaxSampleTimeMs = AZ::TimeMs{500};
|
||||
static constexpr AZ::TimeMs MaxSampleTimeMs = AZ::TimeMs{ 2000 };
|
||||
|
||||
AZ::TimeMs m_maxSampleTimeMs = MaxSampleTimeMs;
|
||||
AZ::TimeMs m_lastLoggedTimeMs = MaxSampleTimeMs;
|
||||
AZ::TimeMs m_maxSampleTimeMs = MaxSampleTimeMs;
|
||||
AZ::TimeMs m_lastLoggedTimeMs = MaxSampleTimeMs;
|
||||
uint32_t m_activeAtom = 0;
|
||||
DatarateAtom m_atoms[2];
|
||||
};
|
||||
@@ -69,7 +78,7 @@ namespace AzNetworking
|
||||
ConnectionPacketEntry(PacketId packetId, AZ::TimeMs sendTimeMs);
|
||||
|
||||
PacketId m_packetId = InvalidPacketId;
|
||||
AZ::TimeMs m_sendTimeMs = AZ::TimeMs{0};
|
||||
AZ::TimeMs m_sendTimeMs = AZ::TimeMs{0};
|
||||
};
|
||||
|
||||
//! @class ConnectionComputeRtt
|
||||
@@ -100,8 +109,8 @@ namespace AzNetworking
|
||||
|
||||
private:
|
||||
|
||||
static constexpr uint32_t MaxTrackableEntries = 4;
|
||||
static constexpr float InitialRoundTripTime = 0.1f; //< Start off with a 100 millisecond estimate for Rtt
|
||||
static constexpr uint32_t MaxTrackableEntries = 8;
|
||||
static constexpr float InitialRoundTripTime = 0.1f; //< Start off with a 100 millisecond estimate for Rtt
|
||||
|
||||
float m_roundTripTime = InitialRoundTripTime;
|
||||
ConnectionPacketEntry m_entries[MaxTrackableEntries];
|
||||
@@ -117,6 +126,11 @@ namespace AzNetworking
|
||||
//! Resets all internal metrics to defaults.
|
||||
void Reset();
|
||||
|
||||
void LogPacketSent(uint32_t byteCount, AZ::TimeMs currentTimeMs);
|
||||
void LogPacketRecv(uint32_t byteCount, AZ::TimeMs currentTimeMs);
|
||||
void LogPacketLost();
|
||||
void LogPacketAcked();
|
||||
|
||||
uint32_t m_packetsSent = 0;
|
||||
uint32_t m_packetsRecv = 0;
|
||||
uint32_t m_packetsLost = 0;
|
||||
|
||||
@@ -40,4 +40,33 @@ namespace AzNetworking
|
||||
{
|
||||
*this = ConnectionMetrics();
|
||||
}
|
||||
|
||||
inline void ConnectionMetrics::LogPacketSent(uint32_t byteCount, AZ::TimeMs currentTimeMs)
|
||||
{
|
||||
if (byteCount > 0)
|
||||
{
|
||||
m_packetsSent++;
|
||||
}
|
||||
m_sendDatarate.LogPacket(byteCount, currentTimeMs);
|
||||
}
|
||||
|
||||
inline void ConnectionMetrics::LogPacketRecv(uint32_t byteCount, AZ::TimeMs currentTimeMs)
|
||||
{
|
||||
if (byteCount > 0)
|
||||
{
|
||||
m_packetsRecv++;
|
||||
}
|
||||
m_recvDatarate.LogPacket(byteCount, currentTimeMs);
|
||||
}
|
||||
|
||||
inline void ConnectionMetrics::LogPacketLost()
|
||||
{
|
||||
m_packetsLost++;
|
||||
m_sendDatarate.LogPacketLost();
|
||||
}
|
||||
|
||||
inline void ConnectionMetrics::LogPacketAcked()
|
||||
{
|
||||
m_packetsAcked++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,11 +95,6 @@ namespace AzNetworking
|
||||
//! @return the max transmission unit for this connection
|
||||
virtual uint32_t GetConnectionMtu() const = 0;
|
||||
|
||||
//! Sets connection quality values for testing poor connection conditions.
|
||||
//! Currently unsupported on TcpConnections
|
||||
//! @param connectionQuality simulated connection quality values to use
|
||||
virtual void SetConnectionQuality(const ConnectionQuality& connectionQuality) = 0;
|
||||
|
||||
//! Returns the connection identifier for this connection instance.
|
||||
//! @return the connection identifier for this connection instance
|
||||
ConnectionId GetConnectionId() const;
|
||||
@@ -128,12 +123,23 @@ namespace AzNetworking
|
||||
//! @return reference to the connection metric info
|
||||
ConnectionMetrics& GetMetrics();
|
||||
|
||||
//! Retrieves debug connection quality settings.
|
||||
//! Currently unsupported on TcpConnections
|
||||
//! @return connection quality structure for this connection
|
||||
const ConnectionQuality& GetConnectionQuality() const;
|
||||
|
||||
//! Retrieves debug connection quality settings, non-const.
|
||||
//! Currently unsupported on TcpConnections
|
||||
//! @return connection quality structure for this connection
|
||||
ConnectionQuality& GetConnectionQuality();
|
||||
|
||||
private:
|
||||
|
||||
// The following data members are here in the interface for performance reasons
|
||||
ConnectionId m_connectionId = InvalidConnectionId;
|
||||
IpAddress m_remoteAddress;
|
||||
ConnectionMetrics m_connectionMetrics;
|
||||
ConnectionQuality m_connectionQuality;
|
||||
void* m_userData = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,4 +59,14 @@ namespace AzNetworking
|
||||
{
|
||||
return m_connectionMetrics;
|
||||
}
|
||||
|
||||
inline const ConnectionQuality& IConnection::GetConnectionQuality() const
|
||||
{
|
||||
return m_connectionQuality;
|
||||
}
|
||||
|
||||
inline ConnectionQuality& IConnection::GetConnectionQuality()
|
||||
{
|
||||
return m_connectionQuality;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user