Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com>
This commit is contained in:
AMZN-Olex
2021-08-03 12:42:48 -04:00
parent 73b9daad25
commit 854e540950
6 changed files with 74 additions and 66 deletions
@@ -14,6 +14,11 @@
namespace Multiplayer
{
MultiplayerDebugByteReporter::MultiplayerDebugByteReporter()
{
MultiplayerDebugByteReporter::Reset();
}
void MultiplayerDebugByteReporter::ReportBytes(size_t byteSize)
{
m_count++;
@@ -80,9 +85,9 @@ namespace Multiplayer
m_lastUpdateTime = now;
}
constexpr float k_bitsPerByte = 8.0f;
constexpr int k_bitsPerKilobit = 1024;
return k_bitsPerByte * m_totalBytesLastSecond / k_bitsPerKilobit;
constexpr float bitsPerByte = 8.0f;
constexpr int bitsPerKilobit = 1024;
return bitsPerByte * m_totalBytesLastSecond / bitsPerKilobit;
}
void MultiplayerDebugByteReporter::Combine(const MultiplayerDebugByteReporter& other)
@@ -139,9 +144,9 @@ namespace Multiplayer
{
MultiplayerDebugByteReporter::Combine(other);
for (const auto& fieldIter : other.m_fieldReports)
for (const auto& fieldIterator : other.m_fieldReports)
{
m_fieldReports[fieldIter.first].Combine(fieldIter.second);
m_fieldReports[fieldIterator.first].Combine(fieldIterator.second);
}
m_componentDirtyBytes.Combine(other.m_componentDirtyBytes);
@@ -176,9 +181,9 @@ namespace Multiplayer
{
MultiplayerDebugByteReporter::Combine(other);
for (const auto& componentIter : other.m_componentReports)
for (const auto& componentIterator : other.m_componentReports)
{
m_componentReports[componentIter.first].Combine(componentIter.second);
m_componentReports[componentIterator.first].Combine(componentIterator.second);
}
SetEntityName(other.GetEntityName());
@@ -18,7 +18,7 @@ namespace Multiplayer
class MultiplayerDebugByteReporter
{
public:
MultiplayerDebugByteReporter() { MultiplayerDebugByteReporter::Reset(); }
MultiplayerDebugByteReporter();
virtual ~MultiplayerDebugByteReporter() = default;
void ReportBytes(size_t byteSize);
@@ -48,7 +48,8 @@ namespace Multiplayer
AZStd::chrono::monotonic_clock::time_point m_lastUpdateTime;
};
class MultiplayerDebugComponentReporter : public MultiplayerDebugByteReporter
class MultiplayerDebugComponentReporter final
: public MultiplayerDebugByteReporter
{
public:
MultiplayerDebugComponentReporter() = default;
@@ -66,7 +67,8 @@ namespace Multiplayer
MultiplayerDebugByteReporter m_componentDirtyBytes;
};
class MultiplayerDebugEntityReporter : public MultiplayerDebugByteReporter
class MultiplayerDebugEntityReporter final
: public MultiplayerDebugByteReporter
{
public:
MultiplayerDebugEntityReporter() = default;
@@ -17,16 +17,16 @@
#include <imgui/imgui.h>
#endif
AZ_CVAR(float, net_DebugNetworkEntity_ShowAboveKbps, 1.f, nullptr, AZ::ConsoleFunctorFlags::Null,
AZ_CVAR(float, net_DebugEntities_ShowAboveKbps, 1.f, nullptr, AZ::ConsoleFunctorFlags::Null,
"Prints bandwidth on network entities with higher kpbs than this value");
AZ_CVAR(float, net_DebugNetworkEntity_WarnAboveKbps, 10.f, nullptr, AZ::ConsoleFunctorFlags::Null,
AZ_CVAR(float, net_DebugEntities_WarnAboveKbps, 10.f, nullptr, AZ::ConsoleFunctorFlags::Null,
"Prints bandwidth on network entities with higher kpbs than this value");
AZ_CVAR(AZ::Color, net_DebugNetworkEntity_WarningColor, AZ::Colors::Red, nullptr, AZ::ConsoleFunctorFlags::Null,
AZ_CVAR(AZ::Color, net_DebugEntities_WarningColor, AZ::Colors::Red, nullptr, AZ::ConsoleFunctorFlags::Null,
"If true, prints debug text over entities that use a considerable amount of network traffic");
AZ_CVAR(AZ::Color, net_DebugNetworkEntity_BelowWarningColor, AZ::Colors::Grey, nullptr, AZ::ConsoleFunctorFlags::Null,
AZ_CVAR(AZ::Color, net_DebugEntities_BelowWarningColor, AZ::Colors::Grey, nullptr, AZ::ConsoleFunctorFlags::Null,
"If true, prints debug text over entities that use a considerable amount of network traffic");
namespace Multiplayer
@@ -133,7 +133,8 @@ namespace Multiplayer
{
RecordEntitySerializeStart(mode, entityId, entityName);
});
m_eventHandlers.m_componentSerializeEnd = decltype(m_eventHandlers.m_componentSerializeEnd)([this](AzNetworking::SerializerMode mode, Multiplayer::NetComponentId netComponentId)
m_eventHandlers.m_componentSerializeEnd = decltype(m_eventHandlers.m_componentSerializeEnd)([this](AzNetworking::SerializerMode mode,
NetComponentId netComponentId)
{
RecordComponentSerializeEnd(mode, netComponentId);
});
@@ -141,19 +142,25 @@ namespace Multiplayer
{
RecordEntitySerializeStop(mode, entityId, entityName);
});
m_eventHandlers.m_propertySent = decltype(m_eventHandlers.m_propertySent)([this](Multiplayer::NetComponentId netComponentId, Multiplayer::PropertyIndex propertyId, uint32_t totalBytes)
m_eventHandlers.m_propertySent = decltype(m_eventHandlers.m_propertySent)([this](NetComponentId netComponentId,
PropertyIndex propertyId, uint32_t totalBytes)
{
RecordPropertySent(netComponentId, propertyId, totalBytes);
});
m_eventHandlers.m_propertyReceived = decltype(m_eventHandlers.m_propertyReceived)([this](Multiplayer::NetComponentId netComponentId, Multiplayer::PropertyIndex propertyId, uint32_t totalBytes)
m_eventHandlers.m_propertyReceived = decltype(m_eventHandlers.m_propertyReceived)([this](NetComponentId netComponentId,
PropertyIndex propertyId, uint32_t totalBytes)
{
RecordPropertyReceived(netComponentId, propertyId, totalBytes);
});
m_eventHandlers.m_rpcSent = decltype(m_eventHandlers.m_rpcSent)([this](AZ::EntityId entityId, const char* entityName, Multiplayer::NetComponentId netComponentId, Multiplayer::RpcIndex rpcId, uint32_t totalBytes)
m_eventHandlers.m_rpcSent = decltype(m_eventHandlers.m_rpcSent)([this](AZ::EntityId entityId, const char* entityName,
NetComponentId netComponentId,
RpcIndex rpcId, uint32_t totalBytes)
{
RecordRpcSent(entityId, entityName, netComponentId, rpcId, totalBytes);
});
m_eventHandlers.m_rpcReceived = decltype(m_eventHandlers.m_rpcReceived)([this](AZ::EntityId entityId, const char* entityName, Multiplayer::NetComponentId netComponentId, Multiplayer::RpcIndex rpcId, uint32_t totalBytes)
m_eventHandlers.m_rpcReceived = decltype(m_eventHandlers.m_rpcReceived)([this](AZ::EntityId entityId, const char* entityName,
NetComponentId netComponentId,
RpcIndex rpcId, uint32_t totalBytes)
{
RecordRpcSent(entityId, entityName, netComponentId, rpcId, totalBytes);
});
@@ -161,11 +168,6 @@ namespace Multiplayer
GetMultiplayer()->GetStats().ConnectHandlers(m_eventHandlers);
}
MultiplayerDebugPerEntityReporter::~MultiplayerDebugPerEntityReporter()
{
m_updateDebugOverlay.RemoveFromQueue();
}
// --------------------------------------------------------------------------------------------
void MultiplayerDebugPerEntityReporter::OnImGuiUpdate()
{
@@ -228,7 +230,8 @@ namespace Multiplayer
}
}
void MultiplayerDebugPerEntityReporter::RecordComponentSerializeEnd(AzNetworking::SerializerMode mode, [[maybe_unused]] Multiplayer::NetComponentId netComponentId)
void MultiplayerDebugPerEntityReporter::RecordComponentSerializeEnd(AzNetworking::SerializerMode mode, [[maybe_unused]] NetComponentId
netComponentId)
{
switch (mode)
{
@@ -256,11 +259,11 @@ namespace Multiplayer
}
void MultiplayerDebugPerEntityReporter::RecordPropertySent(
Multiplayer::NetComponentId netComponentId,
Multiplayer::PropertyIndex propertyId,
NetComponentId netComponentId,
PropertyIndex propertyId,
uint32_t totalBytes)
{
if (const Multiplayer::MultiplayerComponentRegistry* componentRegistry = Multiplayer::GetMultiplayerComponentRegistry())
if (const MultiplayerComponentRegistry* componentRegistry = GetMultiplayerComponentRegistry())
{
m_currentSendingEntityReport.ReportField(static_cast<AZ::u32>(netComponentId),
componentRegistry->GetComponentName(netComponentId),
@@ -269,11 +272,11 @@ namespace Multiplayer
}
void MultiplayerDebugPerEntityReporter::RecordPropertyReceived(
Multiplayer::NetComponentId netComponentId,
Multiplayer::PropertyIndex propertyId,
NetComponentId netComponentId,
PropertyIndex propertyId,
uint32_t totalBytes)
{
if (const Multiplayer::MultiplayerComponentRegistry* componentRegistry = Multiplayer::GetMultiplayerComponentRegistry())
if (const MultiplayerComponentRegistry* componentRegistry = GetMultiplayerComponentRegistry())
{
m_currentReceivingEntityReport.ReportField(static_cast<AZ::u32>(netComponentId),
componentRegistry->GetComponentName(netComponentId),
@@ -281,9 +284,10 @@ namespace Multiplayer
}
}
void MultiplayerDebugPerEntityReporter::RecordRpcSent(AZ::EntityId entityId, const char* entityName, Multiplayer::NetComponentId netComponentId, Multiplayer::RpcIndex rpcId, uint32_t totalBytes)
void MultiplayerDebugPerEntityReporter::RecordRpcSent(AZ::EntityId entityId, const char* entityName, NetComponentId netComponentId,
RpcIndex rpcId, uint32_t totalBytes)
{
if (const Multiplayer::MultiplayerComponentRegistry* componentRegistry = Multiplayer::GetMultiplayerComponentRegistry())
if (const MultiplayerComponentRegistry* componentRegistry = GetMultiplayerComponentRegistry())
{
// MultiplayerDebugByteReporter requires a
RecordEntitySerializeStart(AzNetworking::SerializerMode::ReadFromObject, entityId, entityName);
@@ -303,7 +307,7 @@ namespace Multiplayer
RpcIndex rpcId,
uint32_t totalBytes)
{
if (const Multiplayer::MultiplayerComponentRegistry* componentRegistry = Multiplayer::GetMultiplayerComponentRegistry())
if (const MultiplayerComponentRegistry* componentRegistry = GetMultiplayerComponentRegistry())
{
RecordEntitySerializeStart(AzNetworking::SerializerMode::WriteToObject, entityId, entityName);
@@ -320,19 +324,18 @@ namespace Multiplayer
{
m_networkEntitiesTraffic.clear();
// Merging up and down traffic to provide a unified debug text per entity
for (AZStd::pair<AZ::EntityId, MultiplayerDebugEntityReporter>& entityPair : m_receivingEntityReports)
{
m_networkEntitiesTraffic[entityPair.first].m_name = entityPair.second.GetEntityName();
m_networkEntitiesTraffic[entityPair.first].m_down = entityPair.second.GetKbitsPerSecond();
}
for (AZStd::pair<AZ::EntityId, MultiplayerDebugEntityReporter>& entityPair : m_sendingEntityReports)
{
m_networkEntitiesTraffic[entityPair.first].m_name = entityPair.second.GetEntityName();
m_networkEntitiesTraffic[entityPair.first].m_up = entityPair.second.GetKbitsPerSecond();
}
//get debug display interface for the viewport
if (m_debugDisplay == nullptr)
{
AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus;
@@ -342,28 +345,28 @@ namespace Multiplayer
const AZ::u32 stateBefore = m_debugDisplay->GetState();
for (AZStd::pair<AZ::EntityId, NetworkEntityTraffic>& networkEntity : m_networkEntitiesTraffic)
for (const AZStd::pair<AZ::EntityId, NetworkEntityTraffic>& networkEntity : m_networkEntitiesTraffic)
{
if (networkEntity.second.m_down < net_DebugNetworkEntity_ShowAboveKbps && networkEntity.second.m_up < net_DebugNetworkEntity_ShowAboveKbps)
if (networkEntity.second.m_down < net_DebugEntities_ShowAboveKbps && networkEntity.second.m_up < net_DebugEntities_ShowAboveKbps)
{
continue;
}
if (networkEntity.second.m_down > net_DebugNetworkEntity_WarnAboveKbps || networkEntity.second.m_up > net_DebugNetworkEntity_WarnAboveKbps)
if (networkEntity.second.m_down > net_DebugEntities_WarnAboveKbps || networkEntity.second.m_up > net_DebugEntities_WarnAboveKbps)
{
m_debugDisplay->SetColor(net_DebugNetworkEntity_WarningColor);
m_debugDisplay->SetColor(net_DebugEntities_WarningColor);
}
else
{
m_debugDisplay->SetColor(net_DebugNetworkEntity_BelowWarningColor);
m_debugDisplay->SetColor(net_DebugEntities_BelowWarningColor);
}
if (networkEntity.second.m_down > net_DebugNetworkEntity_ShowAboveKbps && networkEntity.second.m_up > net_DebugNetworkEntity_ShowAboveKbps)
if (networkEntity.second.m_down > net_DebugEntities_ShowAboveKbps && networkEntity.second.m_up > net_DebugEntities_ShowAboveKbps)
{
azsprintf(m_statusBuffer, "[%s] %.0f down / %0.f up (kbps)", networkEntity.second.m_name,
networkEntity.second.m_down, networkEntity.second.m_up);
}
else if (networkEntity.second.m_down > net_DebugNetworkEntity_ShowAboveKbps)
else if (networkEntity.second.m_down > net_DebugEntities_ShowAboveKbps)
{
azsprintf(m_statusBuffer, "[%s] %.0f down (kbps)", networkEntity.second.m_name, networkEntity.second.m_down);
}
@@ -373,9 +376,12 @@ namespace Multiplayer
}
AZ::Vector3 entityPosition = AZ::Vector3::CreateZero();
constexpr bool centerText = true;
AZ::TransformBus::EventResult(entityPosition, networkEntity.first, &AZ::TransformBus::Events::GetWorldTranslation);
m_debugDisplay->DrawTextLabel(entityPosition, 1.0f, m_statusBuffer, centerText, 0, 0);
if (entityPosition.IsZero() == false)
{
constexpr bool centerText = true;
m_debugDisplay->DrawTextLabel(entityPosition, 1.0f, m_statusBuffer, centerText, 0, 0);
}
}
m_debugDisplay->SetState(stateBefore);
@@ -18,34 +18,34 @@
namespace Multiplayer
{
/**
* \brief GridMate network live analysis tool via ImGui.
* \brief Multiplayer traffic live analysis tool via ImGui.
*/
class MultiplayerDebugPerEntityReporter
{
public:
MultiplayerDebugPerEntityReporter();
~MultiplayerDebugPerEntityReporter();
// main update loop
//! main update loop
void OnImGuiUpdate();
//! Event handlers
// @{
void RecordEntitySerializeStart(AzNetworking::SerializerMode mode, AZ::EntityId entityId, const char* entityName);
void RecordComponentSerializeEnd(AzNetworking::SerializerMode mode, Multiplayer::NetComponentId netComponentId);
void RecordComponentSerializeEnd(AzNetworking::SerializerMode mode, NetComponentId netComponentId);
void RecordEntitySerializeStop(AzNetworking::SerializerMode mode, AZ::EntityId entityId, const char* entityName);
void RecordPropertySent(Multiplayer::NetComponentId netComponentId, Multiplayer::PropertyIndex propertyId, uint32_t totalBytes);
void RecordPropertyReceived(Multiplayer::NetComponentId netComponentId, Multiplayer::PropertyIndex propertyId, uint32_t totalBytes);
void RecordRpcSent(AZ::EntityId entityId, const char* entityName, Multiplayer::NetComponentId netComponentId, Multiplayer::RpcIndex rpcId, uint32_t totalBytes);
void RecordRpcReceived(AZ::EntityId entityId, const char* entityName, Multiplayer::NetComponentId netComponentId, Multiplayer::RpcIndex rpcId, uint32_t totalBytes);
void RecordPropertySent(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes);
void RecordPropertyReceived(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes);
void RecordRpcSent(AZ::EntityId entityId, const char* entityName, NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes);
void RecordRpcReceived(AZ::EntityId entityId, const char* entityName, NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes);
// }@
//! Draws bandwidth text over entities
void UpdateDebugOverlay();
private:
AZ::ScheduledEvent m_updateDebugOverlay;
Multiplayer::MultiplayerStats::EventHandlers m_eventHandlers;
MultiplayerStats::EventHandlers m_eventHandlers;
AZStd::map<AZ::EntityId, MultiplayerDebugEntityReporter> m_sendingEntityReports{};
MultiplayerDebugEntityReporter m_currentSendingEntityReport;
@@ -13,9 +13,9 @@
#include <AzNetworking/Framework/INetworkInterface.h>
#include <Multiplayer/IMultiplayer.h>
void OnDebugNetworkEntity_ShowBandwidth_Changed(const bool& showBandwidth);
void OnDebugEntities_ShowBandwidth_Changed(const bool& showBandwidth);
AZ_CVAR(bool, net_DebugNetworkEntity_ShowBandwidth, false, &OnDebugNetworkEntity_ShowBandwidth_Changed, AZ::ConsoleFunctorFlags::Null,
AZ_CVAR(bool, net_DebugEntities_ShowBandwidth, false, &OnDebugEntities_ShowBandwidth_Changed, AZ::ConsoleFunctorFlags::Null,
"If true, prints bandwidth values over entities that use a considerable amount of network traffic");
namespace Multiplayer
@@ -458,13 +458,10 @@ namespace Multiplayer
{
if (ImGui::Begin("Multiplayer Per Entity Stats", &m_displayPerEntityStats, ImGuiWindowFlags_AlwaysAutoResize))
{
if (ImGui::Checkbox("Show Bandwidth over Entities", &m_displayPerEntityBandwidth))
// This overrides @net_DebugNetworkEntity_ShowBandwidth value
if (m_reporter == nullptr)
{
// This overrides @net_DebugNetworkEntity_ShowBandwidth value
if (m_reporter == nullptr)
{
ShowEntityBandwidthDebugOverlay();
}
ShowEntityBandwidthDebugOverlay();
}
if (m_reporter)
@@ -477,7 +474,7 @@ namespace Multiplayer
#endif
}
void OnDebugNetworkEntity_ShowBandwidth_Changed(const bool& showBandwidth)
void OnDebugEntities_ShowBandwidth_Changed(const bool& showBandwidth)
{
if (showBandwidth)
{
@@ -43,7 +43,7 @@ namespace Multiplayer
void Deactivate() override;
//! @}
//! IMultiplayerDebugSystem overrides
//! IMultiplayerDebug overrides
//! @{
void ShowEntityBandwidthDebugOverlay() override;
void HideEntityBandwidthDebugOverlay() override;
@@ -62,8 +62,6 @@ namespace Multiplayer
bool m_displayMultiplayerStats = false;
bool m_displayPerEntityStats = false;
bool m_displayPerEntityBandwidth = false;
AZStd::unique_ptr<MultiplayerDebugPerEntityReporter> m_reporter;
};
}