Refactored to store entities by entity ids

Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com>
This commit is contained in:
AMZN-Olex
2021-07-26 23:45:09 -04:00
parent a2f3066fa3
commit 59f65f2656
4 changed files with 23 additions and 32 deletions
@@ -163,25 +163,6 @@ namespace MultiplayerDiagnostics
MultiplayerDebugByteReporter::AggregateBytes(byteSize); 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<int>(index) << "]" << " " << componentName;
m_currentComponentReport = &m_componentReports[component.str().c_str()];
}
m_currentComponentReport->ReportDirtyBits(byteSize);
m_gdeDirtyBytes.AggregateBytes(byteSize);
}
void EntityReporter::ReportFragmentEnd() void EntityReporter::ReportFragmentEnd()
{ {
if (m_currentComponentReport) if (m_currentComponentReport)
@@ -203,6 +184,7 @@ namespace MultiplayerDiagnostics
m_componentReports[componentIter.first].Combine(componentIter.second); m_componentReports[componentIter.first].Combine(componentIter.second);
} }
SetEntityName(other.GetEntityName());
m_gdeDirtyBytes.Combine(other.m_gdeDirtyBytes); m_gdeDirtyBytes.Combine(other.m_gdeDirtyBytes);
} }
@@ -54,7 +54,6 @@ namespace MultiplayerDiagnostics
ComponentReporter() = default; ComponentReporter() = default;
void ReportField(const char* fieldName, size_t byteSize); void ReportField(const char* fieldName, size_t byteSize);
void ReportDirtyBits(size_t byteSize) { m_componentDirtyBytes.AggregateBytes(byteSize); }
void ReportFragmentEnd(); void ReportFragmentEnd();
using Report = AZStd::pair<AZStd::string, MultiplayerDebugByteReporter*>; using Report = AZStd::pair<AZStd::string, MultiplayerDebugByteReporter*>;
@@ -75,12 +74,18 @@ namespace MultiplayerDiagnostics
EntityReporter() = default; EntityReporter() = default;
void ReportField(AZ::u32 index, const char* componentName, const char* fieldName, size_t byteSize); 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 ReportFragmentEnd();
void Combine(const EntityReporter& other); void Combine(const EntityReporter& other);
void Reset() override; 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<AZStd::string, ComponentReporter>& GetComponentReports(); AZStd::map<AZStd::string, ComponentReporter>& GetComponentReports();
AZStd::size_t GetTotalDirtyBits() const { return m_gdeDirtyBytes.GetTotalBytes(); } AZStd::size_t GetTotalDirtyBits() const { return m_gdeDirtyBytes.GetTotalBytes(); }
float GetAvgDirtyBits() const { return m_gdeDirtyBytes.GetAverageBytes(); } float GetAvgDirtyBits() const { return m_gdeDirtyBytes.GetAverageBytes(); }
@@ -89,5 +94,6 @@ namespace MultiplayerDiagnostics
ComponentReporter* m_currentComponentReport = nullptr; ComponentReporter* m_currentComponentReport = nullptr;
AZStd::map<AZStd::string, ComponentReporter> m_componentReports; AZStd::map<AZStd::string, ComponentReporter> m_componentReports;
MultiplayerDebugByteReporter m_gdeDirtyBytes; MultiplayerDebugByteReporter m_gdeDirtyBytes;
AZStd::string m_entityName;
}; };
} }
@@ -119,15 +119,15 @@ namespace MultiplayerDiagnostics
if (ImGui::CollapsingHeader("Receiving Entities")) if (ImGui::CollapsingHeader("Receiving Entities"))
{ {
for (auto& entityPair : m_receivingEntityReports) for (AZStd::pair<AZ::EntityId, EntityReporter>& entityPair : m_receivingEntityReports)
{ {
if (!filter.PassFilter(entityPair.first.c_str())) if (!filter.PassFilter(entityPair.second.GetEntityName()))
{ {
continue; continue;
} }
ImGui::Separator(); 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); DisplayReplicatedStateReport(entityPair.second.GetComponentReports(), m_replicatedStateKbpsWarn, m_replicatedStateMaxSizeWarn);
ImGui::TreePop(); ImGui::TreePop();
@@ -137,15 +137,16 @@ namespace MultiplayerDiagnostics
if (ImGui::CollapsingHeader("Sending Entities")) if (ImGui::CollapsingHeader("Sending Entities"))
{ {
for (auto& entityPair : m_sendingEntityReports) for (AZStd::pair<AZ::EntityId, EntityReporter>& entityPair : m_sendingEntityReports)
{ {
if (!filter.PassFilter(entityPair.first.c_str())) const char* name = entityPair.second.GetEntityName();
if (!filter.PassFilter(name))
{ {
continue; continue;
} }
ImGui::Separator(); 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); DisplayReplicatedStateReport(entityPair.second.GetComponentReports(), m_replicatedStateKbpsWarn, m_replicatedStateMaxSizeWarn);
ImGui::TreePop(); ImGui::TreePop();
@@ -162,9 +163,11 @@ namespace MultiplayerDiagnostics
{ {
case AzNetworking::SerializerMode::ReadFromObject: case AzNetworking::SerializerMode::ReadFromObject:
m_currentSendingEntityReport.Reset(); m_currentSendingEntityReport.Reset();
m_currentSendingEntityReport.SetEntityName(entityName);
break; break;
case AzNetworking::SerializerMode::WriteToObject: case AzNetworking::SerializerMode::WriteToObject:
m_currentReceivingEntityReport.Reset(); m_currentReceivingEntityReport.Reset();
m_currentReceivingEntityReport.SetEntityName(entityName);
break; break;
} }
} }
@@ -183,15 +186,15 @@ namespace MultiplayerDiagnostics
} }
void MultiplayerDebugPerEntityReporter::RecordEntitySerializeStop(AzNetworking::SerializerMode mode, 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) switch (mode)
{ {
case AzNetworking::SerializerMode::ReadFromObject: case AzNetworking::SerializerMode::ReadFromObject:
m_sendingEntityReports[entityName].Combine(m_currentSendingEntityReport); m_sendingEntityReports[entityId].Combine(m_currentSendingEntityReport);
break; break;
case AzNetworking::SerializerMode::WriteToObject: case AzNetworking::SerializerMode::WriteToObject:
m_receivingEntityReports[entityName].Combine(m_currentReceivingEntityReport); m_receivingEntityReports[entityId].Combine(m_currentReceivingEntityReport);
break; break;
} }
} }
@@ -42,10 +42,10 @@ namespace MultiplayerDiagnostics
private: private:
AZStd::map<AZStd::string, EntityReporter> m_sendingEntityReports{}; AZStd::map<AZ::EntityId, EntityReporter> m_sendingEntityReports{};
EntityReporter m_currentSendingEntityReport; EntityReporter m_currentSendingEntityReport;
AZStd::map<AZStd::string, EntityReporter> m_receivingEntityReports{}; AZStd::map<AZ::EntityId, EntityReporter> m_receivingEntityReports{};
EntityReporter m_currentReceivingEntityReport; EntityReporter m_currentReceivingEntityReport;
float m_replicatedStateKbpsWarn = 10.f; float m_replicatedStateKbpsWarn = 10.f;