Refactored to store entities by entity ids
Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com>
This commit is contained in:
@@ -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<int>(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AZStd::string, MultiplayerDebugByteReporter*>;
|
||||
@@ -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<AZStd::string, ComponentReporter>& 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<AZStd::string, ComponentReporter> m_componentReports;
|
||||
MultiplayerDebugByteReporter m_gdeDirtyBytes;
|
||||
AZStd::string m_entityName;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -119,15 +119,15 @@ namespace MultiplayerDiagnostics
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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<AZ::EntityId, EntityReporter>& 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ namespace MultiplayerDiagnostics
|
||||
|
||||
private:
|
||||
|
||||
AZStd::map<AZStd::string, EntityReporter> m_sendingEntityReports{};
|
||||
AZStd::map<AZ::EntityId, EntityReporter> m_sendingEntityReports{};
|
||||
EntityReporter m_currentSendingEntityReport;
|
||||
|
||||
AZStd::map<AZStd::string, EntityReporter> m_receivingEntityReports{};
|
||||
AZStd::map<AZ::EntityId, EntityReporter> m_receivingEntityReports{};
|
||||
EntityReporter m_currentReceivingEntityReport;
|
||||
|
||||
float m_replicatedStateKbpsWarn = 10.f;
|
||||
|
||||
Reference in New Issue
Block a user