diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.cpp index 2c0a8b5db1..5e912612b7 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.cpp +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.cpp @@ -163,25 +163,6 @@ namespace MultiplayerDiagnostics MultiplayerDebugByteReporter::AggregateBytes(byteSize); } - void EntityReporter::ReportDirtyBits(AZ::u32 index, const char* componentName, size_t byteSize) - { - const char* const prefix = "MB::"; - if (strncmp(prefix, componentName, 4) == 0) - { - componentName += strlen(prefix); - } - - if (m_currentComponentReport == nullptr) - { - std::stringstream component; - component << "[" << std::setw(2) << std::setfill('0') << static_cast(index) << "]" << " " << componentName; - m_currentComponentReport = &m_componentReports[component.str().c_str()]; - } - - m_currentComponentReport->ReportDirtyBits(byteSize); - m_gdeDirtyBytes.AggregateBytes(byteSize); - } - void EntityReporter::ReportFragmentEnd() { if (m_currentComponentReport) @@ -203,6 +184,7 @@ namespace MultiplayerDiagnostics m_componentReports[componentIter.first].Combine(componentIter.second); } + SetEntityName(other.GetEntityName()); m_gdeDirtyBytes.Combine(other.m_gdeDirtyBytes); } diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.h b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.h index 8977c2e6ba..3cef9caaac 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.h +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugByteReporter.h @@ -54,7 +54,6 @@ namespace MultiplayerDiagnostics ComponentReporter() = default; void ReportField(const char* fieldName, size_t byteSize); - void ReportDirtyBits(size_t byteSize) { m_componentDirtyBytes.AggregateBytes(byteSize); } void ReportFragmentEnd(); using Report = AZStd::pair; @@ -75,12 +74,18 @@ namespace MultiplayerDiagnostics EntityReporter() = default; void ReportField(AZ::u32 index, const char* componentName, const char* fieldName, size_t byteSize); - void ReportDirtyBits(AZ::u32 index, const char* componentName, size_t byteSize); void ReportFragmentEnd(); void Combine(const EntityReporter& other); void Reset() override; + const char* GetEntityName() const { return m_entityName.c_str(); } + void SetEntityName(const char* entityName) + { + // copying because the entity might go away + m_entityName = entityName; + } + AZStd::map& GetComponentReports(); AZStd::size_t GetTotalDirtyBits() const { return m_gdeDirtyBytes.GetTotalBytes(); } float GetAvgDirtyBits() const { return m_gdeDirtyBytes.GetAverageBytes(); } @@ -89,5 +94,6 @@ namespace MultiplayerDiagnostics ComponentReporter* m_currentComponentReport = nullptr; AZStd::map m_componentReports; MultiplayerDebugByteReporter m_gdeDirtyBytes; + AZStd::string m_entityName; }; } diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp index c839083f63..3517dfa86a 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp @@ -119,15 +119,15 @@ namespace MultiplayerDiagnostics if (ImGui::CollapsingHeader("Receiving Entities")) { - for (auto& entityPair : m_receivingEntityReports) + for (AZStd::pair& entityPair : m_receivingEntityReports) { - if (!filter.PassFilter(entityPair.first.c_str())) + if (!filter.PassFilter(entityPair.second.GetEntityName())) { continue; } ImGui::Separator(); - if (ReplicatedStateTreeNode(entityPair.first, entityPair.second, k_ImGuiDusk)) + if (ReplicatedStateTreeNode(entityPair.second.GetEntityName(), entityPair.second, k_ImGuiDusk)) { DisplayReplicatedStateReport(entityPair.second.GetComponentReports(), m_replicatedStateKbpsWarn, m_replicatedStateMaxSizeWarn); ImGui::TreePop(); @@ -137,15 +137,16 @@ namespace MultiplayerDiagnostics if (ImGui::CollapsingHeader("Sending Entities")) { - for (auto& entityPair : m_sendingEntityReports) + for (AZStd::pair& entityPair : m_sendingEntityReports) { - if (!filter.PassFilter(entityPair.first.c_str())) + const char* name = entityPair.second.GetEntityName(); + if (!filter.PassFilter(name)) { continue; } ImGui::Separator(); - if (ReplicatedStateTreeNode(entityPair.first, entityPair.second, k_ImGuiDusk)) + if (ReplicatedStateTreeNode(name, entityPair.second, k_ImGuiDusk)) { DisplayReplicatedStateReport(entityPair.second.GetComponentReports(), m_replicatedStateKbpsWarn, m_replicatedStateMaxSizeWarn); ImGui::TreePop(); @@ -162,9 +163,11 @@ namespace MultiplayerDiagnostics { case AzNetworking::SerializerMode::ReadFromObject: m_currentSendingEntityReport.Reset(); + m_currentSendingEntityReport.SetEntityName(entityName); break; case AzNetworking::SerializerMode::WriteToObject: m_currentReceivingEntityReport.Reset(); + m_currentReceivingEntityReport.SetEntityName(entityName); break; } } @@ -183,15 +186,15 @@ namespace MultiplayerDiagnostics } void MultiplayerDebugPerEntityReporter::RecordEntitySerializeStop(AzNetworking::SerializerMode mode, - [[maybe_unused]] AZ::EntityId entityId, const char* entityName) + [[maybe_unused]] AZ::EntityId entityId, [[maybe_unused]] const char* entityName) { switch (mode) { case AzNetworking::SerializerMode::ReadFromObject: - m_sendingEntityReports[entityName].Combine(m_currentSendingEntityReport); + m_sendingEntityReports[entityId].Combine(m_currentSendingEntityReport); break; case AzNetworking::SerializerMode::WriteToObject: - m_receivingEntityReports[entityName].Combine(m_currentReceivingEntityReport); + m_receivingEntityReports[entityId].Combine(m_currentReceivingEntityReport); break; } } diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.h b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.h index 121c4131ed..f34cc2cd35 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.h +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.h @@ -42,10 +42,10 @@ namespace MultiplayerDiagnostics private: - AZStd::map m_sendingEntityReports{}; + AZStd::map m_sendingEntityReports{}; EntityReporter m_currentSendingEntityReport; - AZStd::map m_receivingEntityReports{}; + AZStd::map m_receivingEntityReports{}; EntityReporter m_currentReceivingEntityReport; float m_replicatedStateKbpsWarn = 10.f;