From fc81458e2dc306efacd1979525b4014e2beac35a Mon Sep 17 00:00:00 2001 From: UnrealGDK Bot Date: Fri, 21 May 2021 13:44:10 +0000 Subject: [PATCH 01/14] Release candidate for version 0.13.1. --- CHANGELOG.md | 2 ++ SpatialGDK/SpatialGDK.uplugin | 4 ++-- UnrealGDKEngineNetTestVersion.txt | 2 +- UnrealGDKTestGymsVersion.txt | 2 +- ci/unreal-engine.version | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3345bb08c4..78aa061c28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [`x.y.z`] - Unreleased +## [`0.13.1`] - 2021-05-21 + ## [`0.13.0`] - 2021-05-17 ### Breaking changes: - Removed support for Unreal Engine 4.24. diff --git a/SpatialGDK/SpatialGDK.uplugin b/SpatialGDK/SpatialGDK.uplugin index 2469ea6d59..7d25b8ed3e 100644 --- a/SpatialGDK/SpatialGDK.uplugin +++ b/SpatialGDK/SpatialGDK.uplugin @@ -1,7 +1,7 @@ { "FileVersion": 3, - "Version": 10, - "VersionName": "0.13.0", + "Version": 11, + "VersionName": "0.13.1", "FriendlyName": "SpatialOS GDK for Unreal", "Description": "The SpatialOS Game Development Kit (GDK) for Unreal Engine allows you to host your game and combine multiple dedicated server instances across one seamless game world whilst using the Unreal Engine networking API.", "Category": "SpatialOS", diff --git a/UnrealGDKEngineNetTestVersion.txt b/UnrealGDKEngineNetTestVersion.txt index 51de3305bb..6515fdf9f4 100644 --- a/UnrealGDKEngineNetTestVersion.txt +++ b/UnrealGDKEngineNetTestVersion.txt @@ -1 +1 @@ -0.13.0 \ No newline at end of file +0.13.1-rc \ No newline at end of file diff --git a/UnrealGDKTestGymsVersion.txt b/UnrealGDKTestGymsVersion.txt index 51de3305bb..6515fdf9f4 100644 --- a/UnrealGDKTestGymsVersion.txt +++ b/UnrealGDKTestGymsVersion.txt @@ -1 +1 @@ -0.13.0 \ No newline at end of file +0.13.1-rc \ No newline at end of file diff --git a/ci/unreal-engine.version b/ci/unreal-engine.version index a5b2893629..15b38d1fcc 100644 --- a/ci/unreal-engine.version +++ b/ci/unreal-engine.version @@ -1,2 +1,2 @@ -dd42c1703769d1ed5510e0d56fb54646956d98d5 -59cf76706893d89f407e34518e8e7fbc90dd7e28 +HEAD 4.26-SpatialOSUnrealGDK-0.13.1-rc +HEAD 4.25-SpatialOSUnrealGDK-0.13.1-rc From c7a90c0ee15a19090ed1472b7d81056466a39635 Mon Sep 17 00:00:00 2001 From: Simon Sarginson Date: Fri, 21 May 2021 15:56:32 +0100 Subject: [PATCH 02/14] Update premerge.steps.yaml --- .buildkite/premerge.steps.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.buildkite/premerge.steps.yaml b/.buildkite/premerge.steps.yaml index 13cee93db2..e327f4e651 100755 --- a/.buildkite/premerge.steps.yaml +++ b/.buildkite/premerge.steps.yaml @@ -33,9 +33,9 @@ steps: env: BUILD_TYPE: "GDK" GDK_BRANCH: "${BUILDKITE_BRANCH}" - ENGINE_BRANCH: "${ENGINE_BRANCH_426:-4.26-SpatialOSUnrealGDK-0.13.0}" # NOTE: temp fix for new ci release interop issues + ENGINE_BRANCH: "${ENGINE_BRANCH_426:-4.26-SpatialOSUnrealGDK-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues ENGINE_MAJOR: "4.26" - PROJECT_BRANCH: "${PROJECT_BRANCH:-0.13.0}" # NOTE: temp fix for new ci release interop issues + PROJECT_BRANCH: "${PROJECT_BRANCH:-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues USE_FASTBUILD: "True" IS_BUILDKITE_BUILD: "True" BUILD_ANDROID: "False" @@ -52,9 +52,9 @@ steps: env: BUILD_TYPE: "GDK" # GDK or ENGINE GDK_BRANCH: "${BUILDKITE_BRANCH}" - ENGINE_BRANCH: "${ENGINE_BRANCH_425:-4.25-SpatialOSUnrealGDK-0.13.0}" # NOTE: temp fix for new ci release interop issues + ENGINE_BRANCH: "${ENGINE_BRANCH_425:-4.25-SpatialOSUnrealGDK-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues ENGINE_MAJOR: "4.25" - PROJECT_BRANCH: "${PROJECT_BRANCH:-0.13.0}" # NOTE: temp fix for new ci release interop issues + PROJECT_BRANCH: "${PROJECT_BRANCH:-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues USE_FASTBUILD: "True" IS_BUILDKITE_BUILD: "True" BUILD_ANDROID: "False" From 22f9c96625439456a587cadcb51915218e0fc994 Mon Sep 17 00:00:00 2001 From: Michael Samiec Date: Tue, 25 May 2021 21:59:35 +0100 Subject: [PATCH 03/14] Revert "Cherry pick Insights work UNR-5207 (#3044)" (#3146) This reverts commit e3424194755354b9f1d438d81d5ea8aa133ee86f. --- .../Extras/insights-proxy/InsightsProxy.py | 43 ------------------- SpatialGDK/Extras/insights-proxy/README.md | 4 -- 2 files changed, 47 deletions(-) delete mode 100644 SpatialGDK/Extras/insights-proxy/InsightsProxy.py delete mode 100644 SpatialGDK/Extras/insights-proxy/README.md diff --git a/SpatialGDK/Extras/insights-proxy/InsightsProxy.py b/SpatialGDK/Extras/insights-proxy/InsightsProxy.py deleted file mode 100644 index 1eba521269..0000000000 --- a/SpatialGDK/Extras/insights-proxy/InsightsProxy.py +++ /dev/null @@ -1,43 +0,0 @@ -# EXPERIMENTAL: We do not support this functionality currently: Do not use it unless you are Improbable staff. - -import socket -import sys - -TARGET_IP = "127.0.0.1" -LOCAL_IP = "127.0.0.1" -TARGET_PORT = 1981 # Our listen port, see Control.cpp for target usage (C:/work/dev/UnrealEngine4.26/Engine/Source/Runtime/TraceLog/Private/Trace/Control.cpp) -INSIGHTS_PORT = 1980 # See - -def main(): - while True: - try: - print("Attempting connection to server worker %s:%s" % (TARGET_IP, TARGET_PORT)) - worker_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - worker_connection.connect((TARGET_IP, TARGET_PORT)) - worker_connection.settimeout(1.0) - break - except socket.error: - print("Connecting failed. Is the port-foward to the server worker active and listening?") - - print("Connecting to the running Insights instance %s:%s" % (LOCAL_IP, INSIGHTS_PORT)) - proxy_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - proxy_connection.connect((LOCAL_IP, INSIGHTS_PORT)) - - print("Waiting for target..") - - while True: - try: - chunk = worker_connection.recv(16*1024*1024) - except socket.timeout: - continue - print("Forwarding " + str(len(chunk))) - if chunk == b'': - print("Connection dropped, exiting.") - sys.exit(0) - proxy_connection.send(chunk) - -try: - main() -except KeyboardInterrupt: - print("Received `KeyboardInterrupt`, exiting.") - sys.exit(0) diff --git a/SpatialGDK/Extras/insights-proxy/README.md b/SpatialGDK/Extras/insights-proxy/README.md deleted file mode 100644 index 90aaa047c1..0000000000 --- a/SpatialGDK/Extras/insights-proxy/README.md +++ /dev/null @@ -1,4 +0,0 @@ -EXPERIMENTAL: We do not support this functionality currently: Do not use it unless you are Improbable staff. - -# Insights Proxy -This Python script is used to allow proxying insights data from a SpatialOS worker to Insights running on the local machine. See UNR-5207 for more information. This program runs with both Python 2 and Python 3 versions. \ No newline at end of file From fc0443cc93f63b079821bda727a7019776091573 Mon Sep 17 00:00:00 2001 From: Simon Sarginson Date: Tue, 25 May 2021 23:40:32 +0100 Subject: [PATCH 04/14] Update premerge.steps.yaml (#3145) --- .buildkite/premerge.steps.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.buildkite/premerge.steps.yaml b/.buildkite/premerge.steps.yaml index e327f4e651..8a35b96348 100755 --- a/.buildkite/premerge.steps.yaml +++ b/.buildkite/premerge.steps.yaml @@ -1,5 +1,5 @@ --- -ci_version: &ci_version "1.1" +ci_version: &ci_version "1.2" # This is designed to trap and retry failures because agent lost # connection. Agent exits with -1 in this case. agent_transients: &agent_transients @@ -32,10 +32,10 @@ steps: message: "gdk-4.26 ${BUILDKITE_MESSAGE}" env: BUILD_TYPE: "GDK" - GDK_BRANCH: "${BUILDKITE_BRANCH}" - ENGINE_BRANCH: "${ENGINE_BRANCH_426:-4.26-SpatialOSUnrealGDK-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues + GDK_BRANCH: "main_branch::${BUILDKITE_BRANCH}" + ENGINE_BRANCH: "${ENGINE_BRANCH_426:-match_branch_name_pref_engine::4.26-SpatialOSUnrealGDK-0.13.1-rc}" ENGINE_MAJOR: "4.26" - PROJECT_BRANCH: "${PROJECT_BRANCH:-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues + PROJECT_BRANCH: "${PROJECT_BRANCH:-match_branch_name_pref::0.13.1-rc}" USE_FASTBUILD: "True" IS_BUILDKITE_BUILD: "True" BUILD_ANDROID: "False" @@ -51,10 +51,10 @@ steps: message: "gdk-4.25 ${BUILDKITE_MESSAGE}" env: BUILD_TYPE: "GDK" # GDK or ENGINE - GDK_BRANCH: "${BUILDKITE_BRANCH}" - ENGINE_BRANCH: "${ENGINE_BRANCH_425:-4.25-SpatialOSUnrealGDK-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues + GDK_BRANCH: "main_branch::${BUILDKITE_BRANCH}" + ENGINE_BRANCH: "${ENGINE_BRANCH_425:-match_branch_name_pref_engine::4.25-SpatialOSUnrealGDK-0.13.1-rc}" ENGINE_MAJOR: "4.25" - PROJECT_BRANCH: "${PROJECT_BRANCH:-0.13.1-rc}" # NOTE: temp fix for new ci release interop issues + PROJECT_BRANCH: "${PROJECT_BRANCH:-match_branch_name_pref::0.13.1-rc}" USE_FASTBUILD: "True" IS_BUILDKITE_BUILD: "True" BUILD_ANDROID: "False" From 69bc7d82300d5247672270e159d243a50c23aaac Mon Sep 17 00:00:00 2001 From: martin-improbable Date: Wed, 26 May 2021 10:20:34 +0100 Subject: [PATCH 05/14] [UNR-5438] Change UNetDriver GetActorEntityId to not lazy construct Changed GetActorEntityId() to not lazy construct an entityid, and the API to be const. --- .../Private/EngineClasses/SpatialNetDriver.cpp | 12 ++---------- .../Public/EngineClasses/SpatialNetDriver.h | 2 +- .../SpatialGDK/Public/Utils/EngineVersionCheck.h | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriver.cpp b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriver.cpp index a16a33fc19..80bac48ac5 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriver.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriver.cpp @@ -3113,22 +3113,14 @@ int64 USpatialNetDriver::GetClientID() const return SpatialConstants::INVALID_ENTITY_ID; } -int64 USpatialNetDriver::GetActorEntityId(AActor& Actor) +int64 USpatialNetDriver::GetActorEntityId(const AActor& Actor) const { if (PackageMap == nullptr) { return SpatialConstants::INVALID_ENTITY_ID; } - int64 EntityId = PackageMap->GetEntityIdFromObject(&Actor); - if (EntityId == SpatialConstants::INVALID_ENTITY_ID) - { - if (IsServer() && Actor.GetIsReplicated() && (Actor.Role == ROLE_Authority)) - { - EntityId = PackageMap->AllocateEntityIdAndResolveActor(&Actor); - } - } - return EntityId; + return PackageMap->GetEntityIdFromObject(&Actor); } bool USpatialNetDriver::HasTimedOut(const float Interval, uint64& TimeStamp) diff --git a/SpatialGDK/Source/SpatialGDK/Public/EngineClasses/SpatialNetDriver.h b/SpatialGDK/Source/SpatialGDK/Public/EngineClasses/SpatialNetDriver.h index 3c6bd2c69d..e2ada81b93 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/EngineClasses/SpatialNetDriver.h +++ b/SpatialGDK/Source/SpatialGDK/Public/EngineClasses/SpatialNetDriver.h @@ -266,7 +266,7 @@ class SPATIALGDK_API USpatialNetDriver : public UIpNetDriver virtual int64 GetClientID() const override; - virtual int64 GetActorEntityId(AActor& Actor) override; + virtual int64 GetActorEntityId(const AActor& Actor) const override; FShutdownEvent OnShutdown; diff --git a/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h b/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h index d649efd6ed..f6a7649a28 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h @@ -7,7 +7,7 @@ // GDK Version to be updated with SPATIAL_ENGINE_VERSION // when breaking changes are made to the engine that requires // changes to the GDK to remain compatible -#define SPATIAL_GDK_VERSION 36 +#define SPATIAL_GDK_VERSION 37 // Check if GDK is compatible with the current version of Unreal Engine // SPATIAL_ENGINE_VERSION is incremented in engine when breaking changes From f600985d3d3fdae1dcef35d2af322a9fdee3572f Mon Sep 17 00:00:00 2001 From: Michael Samiec Date: Thu, 27 May 2021 00:02:00 +0100 Subject: [PATCH 06/14] Add remote insights enabling (#3134) * Add server command logic --- CHANGELOG.md | 3 + RequireSetup | 2 +- SpatialGDK/Extras/schema/debug_metrics.schema | 7 + SpatialGDK/Extras/schema/server_worker.schema | 12 +- .../Private/Interop/DebugMetricsSystem.cpp | 48 +++-- .../Private/Utils/SpatialMetrics.cpp | 178 +++++++++++++++++- .../SpatialGDK/Public/SpatialConstants.h | 7 + .../SpatialGDK/Public/Utils/SpatialMetrics.h | 6 +- 8 files changed, 235 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78aa061c28..80f3c7c854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [`x.y.z`] - Unreleased ## [`0.13.1`] - 2021-05-21 +- Added `SpatialExecServerCmd` console command with one command `StartInsights` to dynamically enable insights capturing. + - Format: SpatialExecServerCmd < server > < command > < args > + - Example usage: "SpatialExecServerCmd local StartInsights -trace=CustomChannel -tracefile=MyNewTrace" ## [`0.13.0`] - 2021-05-17 ### Breaking changes: diff --git a/RequireSetup b/RequireSetup index d513a12e1d..331ad12cbc 100644 --- a/RequireSetup +++ b/RequireSetup @@ -1,4 +1,4 @@ Increment the below number whenever it is required to run Setup.bat as part of a new commit. Our git hooks will detect this file has been updated and automatically run Setup.bat on pull. -85 +86 diff --git a/SpatialGDK/Extras/schema/debug_metrics.schema b/SpatialGDK/Extras/schema/debug_metrics.schema index 80fef2824d..fc7e3ba16a 100644 --- a/SpatialGDK/Extras/schema/debug_metrics.schema +++ b/SpatialGDK/Extras/schema/debug_metrics.schema @@ -8,9 +8,16 @@ type ModifySettingPayload { float setting_value = 2; } +type ExecServerCommandPayload { + string server_worker = 1; + string command = 2; + string args = 3; +} + component DebugMetrics { id = 9984; command Void start_rpc_metrics(Void); command Void stop_rpc_metrics(Void); command Void modify_spatial_settings(ModifySettingPayload); + command Void exec_server_command(ExecServerCommandPayload); } \ No newline at end of file diff --git a/SpatialGDK/Extras/schema/server_worker.schema b/SpatialGDK/Extras/schema/server_worker.schema index 67b48bd830..7866fd5275 100644 --- a/SpatialGDK/Extras/schema/server_worker.schema +++ b/SpatialGDK/Extras/schema/server_worker.schema @@ -2,6 +2,7 @@ package unreal; import "unreal/gdk/core_types.schema"; +import "unreal/gdk/debug_metrics.schema"; import "unreal/gdk/spawner.schema"; import "unreal/generated/rpc_endpoints.schema"; import "improbable/standard_library.schema"; @@ -22,15 +23,16 @@ component ServerWorker { bool ready_to_begin_play = 2; EntityId server_system_entity_id = 3; command ForwardSpawnPlayerResponse forward_spawn_player(ForwardSpawnPlayerRequest); + command Void exec_server_command(ExecServerCommandPayload); } component_set ServerWorkerAuthComponentSet { id = 9908; components = [ - improbable.Position, - improbable.Metadata, - improbable.Interest, - unreal.ServerWorker, - unreal.generated.UnrealCrossServerSenderRPCs + improbable.Position, + improbable.Metadata, + improbable.Interest, + unreal.ServerWorker, + unreal.generated.UnrealCrossServerSenderRPCs ]; } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp index c1ac08687d..7a21dd4f05 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp @@ -34,6 +34,7 @@ void DebugMetricsSystem::ProcessOps(const TArray& Ops) const const Worker_ComponentId ComponentId = CommandRequest.request.component_id; const Worker_CommandIndex CommandIndex = CommandRequest.request.command_index; const Worker_EntityId EntityId = CommandRequest.entity_id; + bool bCommandHandled = false; if (ComponentId == SpatialConstants::DEBUG_METRICS_COMPONENT_ID) { @@ -51,29 +52,52 @@ void DebugMetricsSystem::ProcessOps(const TArray& Ops) const SpatialMetrics.OnModifySettingCommand(Payload); break; } + case SpatialConstants::DEBUG_METRICS_EXEC_SERVER_COMMAND_ID: + { + Schema_Object* Payload = Schema_GetCommandRequestObject(CommandRequest.request.schema_type); + SpatialMetrics.OnExecServerCmdCommand(Payload); + break; + } default: UE_LOG(LogSpatialDebugMetrics, Error, TEXT("Unknown command index for DebugMetrics component: %d, entity: %lld"), CommandIndex, EntityId); break; } + bCommandHandled = true; + } + + if (ComponentId == SpatialConstants::SERVER_WORKER_COMPONENT_ID) + { + switch (CommandIndex) + { + case SpatialConstants::SERVER_WORKER_EXEC_SERVER_COMMAND_COMMAND_ID: { - Worker_CommandResponse Response = {}; - Response.component_id = ComponentId; - Response.command_index = CommandIndex; - Response.schema_type = Schema_CreateCommandResponse(); + Schema_Object* Payload = Schema_GetCommandRequestObject(CommandRequest.request.schema_type); + SpatialMetrics.OnExecServerCmdCommand(Payload); + bCommandHandled = true; + break; + } + } + } - const FSpatialGDKSpanId CauseSpanId(Op.span_id); - FSpatialGDKSpanId SpanId; + if (bCommandHandled) + { + Worker_CommandResponse Response = {}; + Response.component_id = ComponentId; + Response.command_index = CommandIndex; + Response.schema_type = Schema_CreateCommandResponse(); - if (EventTracer != nullptr) - { - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendCommandResponse(RequestId, true), - CauseSpanId.GetConstId(), 1); - } + const FSpatialGDKSpanId CauseSpanId(Op.span_id); + FSpatialGDKSpanId SpanId; - Connection.SendCommandResponse(RequestId, &Response, SpanId); + if (EventTracer != nullptr) + { + SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendCommandResponse(RequestId, true), + CauseSpanId.GetConstId(), 1); } + + Connection.SendCommandResponse(RequestId, &Response, SpanId); } } } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Utils/SpatialMetrics.cpp b/SpatialGDK/Source/SpatialGDK/Private/Utils/SpatialMetrics.cpp index aae41335d7..7959fdf524 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Utils/SpatialMetrics.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Utils/SpatialMetrics.cpp @@ -4,13 +4,48 @@ #include "Engine/Engine.h" #include "EngineGlobals.h" +#if ENGINE_MINOR_VERSION >= 26 +#include "ProfilingDebugging/TraceAuxiliary.h" +#endif #include "Interop/Connection/SpatialWorkerConnection.h" +#include "Schema/ServerWorker.h" #include "SpatialGDKSettings.h" #include "Utils/SchemaUtils.h" DEFINE_LOG_CATEGORY(LogSpatialMetrics); +namespace SpatialMetricsPrivate +{ +enum class EServerCommands : uint8 +{ + StartInsights, + + ServerCommandsCount, + ServerCommandInvalid = ServerCommandsCount, +}; + +const FString ServerCommandNames[static_cast(EServerCommands::ServerCommandsCount) + 1] = { TEXT("StartInsights"), TEXT("Invalid") }; + +const FString& ServerCommandsEnumToString(const EServerCommands Command) +{ + return ServerCommandNames[static_cast(Command)]; +} + +const EServerCommands ServerCommandsStringToEnum(const FString& Command) +{ + for (uint8 i = 0; i < static_cast(EServerCommands::ServerCommandsCount); ++i) + { + if (Command.Equals(ServerCommandNames[i], ESearchCase::IgnoreCase)) + { + return static_cast(i); + } + } + + return EServerCommands::ServerCommandInvalid; +} +} // namespace SpatialMetricsPrivate + void USpatialMetrics::Init(USpatialWorkerConnection* InConnection, float InNetServerMaxTickRate, bool bInIsServer) { Connection = InConnection; @@ -142,8 +177,8 @@ void USpatialMetrics::SpatialStartRPCMetrics() // If RPC tracking is activated on a client, send a command to the server to start tracking. if (!bIsServer && ControllerRefProvider.IsBound()) { - FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); - Worker_EntityId ControllerEntityId = PCObjectRef.Entity; + const FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); + const Worker_EntityId ControllerEntityId = PCObjectRef.Entity; if (ControllerEntityId != SpatialConstants::INVALID_ENTITY_ID) { @@ -242,8 +277,8 @@ void USpatialMetrics::SpatialStopRPCMetrics() // If RPC tracking is stopped on a client, send a command to the server to stop tracking. if (!bIsServer && ControllerRefProvider.IsBound()) { - FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); - Worker_EntityId ControllerEntityId = PCObjectRef.Entity; + const FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); + const Worker_EntityId ControllerEntityId = PCObjectRef.Entity; if (ControllerEntityId != SpatialConstants::INVALID_ENTITY_ID) { @@ -267,12 +302,12 @@ void USpatialMetrics::OnStopRPCMetricsCommand() SpatialStopRPCMetrics(); } -void USpatialMetrics::SpatialModifySetting(const FString& Name, float Value) +void USpatialMetrics::SpatialModifySetting(const FString& Name, const float Value) { if (!bIsServer && ControllerRefProvider.IsBound()) { - FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); - Worker_EntityId ControllerEntityId = PCObjectRef.Entity; + const FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); + const Worker_EntityId ControllerEntityId = PCObjectRef.Entity; if (ControllerEntityId != SpatialConstants::INVALID_ENTITY_ID) { @@ -338,12 +373,137 @@ void USpatialMetrics::SpatialModifySetting(const FString& Name, float Value) void USpatialMetrics::OnModifySettingCommand(Schema_Object* CommandPayload) { - FString Name = SpatialGDK::GetStringFromSchema(CommandPayload, SpatialConstants::MODIFY_SETTING_PAYLOAD_NAME_ID); - float Value = Schema_GetFloat(CommandPayload, SpatialConstants::MODIFY_SETTING_PAYLOAD_VALUE_ID); + const FString Name = SpatialGDK::GetStringFromSchema(CommandPayload, SpatialConstants::MODIFY_SETTING_PAYLOAD_NAME_ID); + const float Value = Schema_GetFloat(CommandPayload, SpatialConstants::MODIFY_SETTING_PAYLOAD_VALUE_ID); SpatialModifySetting(Name, Value); } +void USpatialMetrics::SpatialExecServerCmd(const FString& ServerName, const FString& Command, const FString& Args) +{ + const SpatialMetricsPrivate::EServerCommands ServerCommand = SpatialMetricsPrivate::ServerCommandsStringToEnum(Command); + if (ServerCommand == SpatialMetricsPrivate::EServerCommands::ServerCommandInvalid) + { + UE_LOG(LogSpatialMetrics, Error, TEXT("SpatialExecServerCmd: Failed to execute server command. Command not found. Command %s (%s)"), + *Command, *Args); + return; + } + + if (!bIsServer && ControllerRefProvider.IsBound()) + { + const FUnrealObjectRef PCObjectRef = ControllerRefProvider.Execute(); + const Worker_EntityId ControllerEntityId = PCObjectRef.Entity; + + if (ControllerEntityId != SpatialConstants::INVALID_ENTITY_ID) + { + Worker_CommandRequest Request = {}; + Request.component_id = SpatialConstants::DEBUG_METRICS_COMPONENT_ID; + Request.command_index = SpatialConstants::DEBUG_METRICS_EXEC_SERVER_COMMAND_ID; + Request.schema_type = Schema_CreateCommandRequest(); + + Schema_Object* RequestObject = Schema_GetCommandRequestObject(Request.schema_type); + + SpatialGDK::AddStringToSchema(RequestObject, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_SERVER_NAME_ID, ServerName); + SpatialGDK::AddStringToSchema(RequestObject, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_COMMAND_ID, Command); + SpatialGDK::AddStringToSchema(RequestObject, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_ARGS_ID, Args); + + Connection->SendCommandRequest(ControllerEntityId, &Request, SpatialGDK::RETRY_MAX_TIMES, {}); + } + else + { + UE_LOG(LogSpatialMetrics, Warning, + TEXT("SpatialExecServerCmd: Could not resolve local PlayerController entity! Command will not be sent to server.")); + } + } + else + { + bool bExecuteLocally = ServerName.Equals(TEXT("local"), ESearchCase::IgnoreCase); + Worker_EntityId ServerWorkerEntityId = SpatialConstants::INVALID_ENTITY_ID; + if (!bExecuteLocally) + { + for (const auto& Iter : Connection->GetView()) + { + const Worker_EntityId EntityId = Iter.Key; + const SpatialGDK::EntityViewElement& Element = Iter.Value; + const SpatialGDK::ComponentData* Data = Element.Components.FindByPredicate([](const SpatialGDK::ComponentData& Component) { + return Component.GetComponentId() == SpatialConstants::SERVER_WORKER_COMPONENT_ID; + }); + + if (Data != nullptr) + { + SpatialGDK::ServerWorker ServerWorkerData(Data->GetWorkerComponentData()); + + if (ServerWorkerData.WorkerName.Equals(ServerName, ESearchCase::IgnoreCase)) + { + ServerWorkerEntityId = EntityId; + bExecuteLocally = Element.Authority.Contains(SpatialConstants::SERVER_WORKER_ENTITY_AUTH_COMPONENT_SET_ID); + break; + } + } + } + } + + if (bExecuteLocally) + { + UE_LOG(LogSpatialMetrics, Log, TEXT("SpatialExecServerCmd: Executing server command. Command %s (%s)"), *Command, *Args); + + switch (ServerCommand) + { + case SpatialMetricsPrivate::EServerCommands::StartInsights: +#if ENGINE_MINOR_VERSION >= 26 + FTraceAuxiliary::UpdateTraceCapture(*Args); +#else + UE_LOG(LogSpatialMetrics, Warning, + TEXT("SpatialExecServerCmd: Failed to execute server StartInsights command. Command only available prior to 4.26."), + *Command, *Args); +#endif + break; + + default: + UE_LOG(LogSpatialMetrics, Error, + TEXT("SpatialExecServerCmd: Failed to execute server command. Command not handled. Command %s (%s)"), *Command, + *Args); + break; + } + } + else if (ServerWorkerEntityId != SpatialConstants::INVALID_ENTITY_ID) + { + UE_LOG(LogSpatialMetrics, Log, TEXT("SpatialExecServerCmd: Forwarding server command. ServerName %s. Command %s (%s)"), + *ServerName, *Command, *Args); + + // Forward command to correct server. + Worker_CommandRequest Request = {}; + Request.component_id = SpatialConstants::SERVER_WORKER_COMPONENT_ID; + Request.command_index = SpatialConstants::SERVER_WORKER_EXEC_SERVER_COMMAND_COMMAND_ID; + Request.schema_type = Schema_CreateCommandRequest(); + + Schema_Object* RequestObject = Schema_GetCommandRequestObject(Request.schema_type); + + SpatialGDK::AddStringToSchema(RequestObject, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_SERVER_NAME_ID, ServerName); + SpatialGDK::AddStringToSchema(RequestObject, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_COMMAND_ID, Command); + SpatialGDK::AddStringToSchema(RequestObject, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_ARGS_ID, Args); + + Connection->SendCommandRequest(ServerWorkerEntityId, &Request, SpatialGDK::RETRY_MAX_TIMES, {}); + } + else + { + UE_LOG(LogSpatialMetrics, Error, + TEXT("SpatialExecServerCmd: Failed to execute server command. Server not found. ServerName %s. Command %s (%s)"), + *ServerName, *Command, *Args); + } + } +} + +void USpatialMetrics::OnExecServerCmdCommand(Schema_Object* CommandPayload) +{ + const FString ServerName = + SpatialGDK::GetStringFromSchema(CommandPayload, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_SERVER_NAME_ID); + const FString Command = SpatialGDK::GetStringFromSchema(CommandPayload, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_COMMAND_ID); + const FString Args = SpatialGDK::GetStringFromSchema(CommandPayload, SpatialConstants::EXEC_SERVER_COMMAND_PAYLOAD_ARGS_ID); + + SpatialExecServerCmd(ServerName, Command, Args); +} + void USpatialMetrics::TrackSentRPC(UFunction* Function, ERPCType RPCType, int PayloadSize) { if (!bRPCTrackingEnabled) diff --git a/SpatialGDK/Source/SpatialGDK/Public/SpatialConstants.h b/SpatialGDK/Source/SpatialGDK/Public/SpatialConstants.h index cf397b260d..7f29298d64 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/SpatialConstants.h +++ b/SpatialGDK/Source/SpatialGDK/Public/SpatialConstants.h @@ -173,11 +173,17 @@ const Schema_FieldId SHUTDOWN_ADDITIONAL_SERVERS_EVENT_ID = 1; const Schema_FieldId DEBUG_METRICS_START_RPC_METRICS_ID = 1; const Schema_FieldId DEBUG_METRICS_STOP_RPC_METRICS_ID = 2; const Schema_FieldId DEBUG_METRICS_MODIFY_SETTINGS_ID = 3; +const Schema_FieldId DEBUG_METRICS_EXEC_SERVER_COMMAND_ID = 4; // ModifySettingPayload Field IDs const Schema_FieldId MODIFY_SETTING_PAYLOAD_NAME_ID = 1; const Schema_FieldId MODIFY_SETTING_PAYLOAD_VALUE_ID = 2; +// ExecServerCommandPayload Field IDs +const Schema_FieldId EXEC_SERVER_COMMAND_PAYLOAD_SERVER_NAME_ID = 1; +const Schema_FieldId EXEC_SERVER_COMMAND_PAYLOAD_COMMAND_ID = 2; +const Schema_FieldId EXEC_SERVER_COMMAND_PAYLOAD_ARGS_ID = 3; + // UnrealObjectRef Field IDs const Schema_FieldId UNREAL_OBJECT_REF_ENTITY_ID = 1; const Schema_FieldId UNREAL_OBJECT_REF_OFFSET_ID = 2; @@ -234,6 +240,7 @@ const Schema_FieldId SERVER_WORKER_NAME_ID = 1; const Schema_FieldId SERVER_WORKER_READY_TO_BEGIN_PLAY_ID = 2; const Schema_FieldId SERVER_WORKER_SYSTEM_ENTITY_ID = 3; const Schema_FieldId SERVER_WORKER_FORWARD_SPAWN_REQUEST_COMMAND_ID = 1; +const Schema_FieldId SERVER_WORKER_EXEC_SERVER_COMMAND_COMMAND_ID = 2; // SpawnPlayerRequest type IDs. const Schema_FieldId SPAWN_PLAYER_URL_ID = 1; diff --git a/SpatialGDK/Source/SpatialGDK/Public/Utils/SpatialMetrics.h b/SpatialGDK/Source/SpatialGDK/Public/Utils/SpatialMetrics.h index 8f2442b6ad..9262e32dd9 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Utils/SpatialMetrics.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Utils/SpatialMetrics.h @@ -41,9 +41,13 @@ class SPATIALGDK_API USpatialMetrics : public UObject void OnStopRPCMetricsCommand(); UFUNCTION(Exec) - void SpatialModifySetting(const FString& Name, float Value); + void SpatialModifySetting(const FString& Name, const float Value); void OnModifySettingCommand(Schema_Object* CommandPayload); + UFUNCTION(Exec) + void SpatialExecServerCmd(const FString& ServerName, const FString& Command, const FString& Args); + void OnExecServerCmdCommand(Schema_Object* CommandPayload); + void TrackSentRPC(UFunction* Function, ERPCType RPCType, int PayloadSize); void HandleWorkerMetrics(const Worker_Op& Op); From b7bf9f31f2db6a055a503a530786792b3d2557a5 Mon Sep 17 00:00:00 2001 From: Danny Birch Date: Thu, 27 May 2021 16:16:55 +0100 Subject: [PATCH 07/14] Cherry pick "UNR-5290: Optimizing event tracing to reduce overheads" (#3152) --- CHANGELOG.md | 1 + .../EngineClasses/SpatialActorChannel.cpp | 1 - .../EngineClasses/SpatialNetDriverRPC.cpp | 34 +- .../Private/Interop/ActorSystem.cpp | 56 ++- .../Interop/Connection/SpatialEventTracer.cpp | 112 ++---- .../SpatialEventTracerUserInterface.cpp | 59 ++- .../Connection/SpatialTraceEventBuilder.cpp | 375 ------------------ .../SpatialTraceEventDataBuilder.cpp | 223 +++++++++++ .../Private/Interop/CrossServerRPCHandler.cpp | 11 +- .../Private/Interop/CrossServerRPCSender.cpp | 12 +- .../Private/Interop/DebugMetricsSystem.cpp | 8 +- .../Private/Interop/GlobalStateManager.cpp | 10 +- .../Interop/MigrationDiagnosticsSystem.cpp | 8 +- .../Private/Interop/RPCExecutor.cpp | 21 +- .../Interop/RPCs/SpatialRPCService.cpp | 53 ++- .../Private/Interop/SpatialPlayerSpawner.cpp | 39 +- .../Private/Interop/SpatialSender.cpp | 15 +- .../SpatialView/ReceivedOpEventHandler.cpp | 2 - .../Private/SpatialView/ViewDelta.cpp | 1 - .../Private/Utils/ComponentReader.cpp | 16 +- .../Interop/Connection/SpatialEventTracer.h | 65 ++- .../SpatialEventTracerUserInterface.h | 46 ++- .../Interop/Connection/SpatialTraceEvent.h | 50 --- .../Connection/SpatialTraceEventBuilder.h | 80 ---- .../Connection/SpatialTraceEventDataBuilder.h | 128 ++++++ .../Interop/Connection/SpatialTraceUniqueId.h | 1 + .../SpatialGDKEditorSnapshotGenerator.cpp | 2 +- .../RelevancyTest/RelevancyTest.cpp | 3 +- .../Connection/SpatialEventTracingTest.cpp | 186 +++++++++ 29 files changed, 888 insertions(+), 730 deletions(-) delete mode 100644 SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventBuilder.cpp create mode 100644 SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp delete mode 100644 SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEvent.h delete mode 100644 SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventBuilder.h create mode 100644 SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h create mode 100644 SpatialGDK/Source/SpatialGDKTests/SpatialGDK/Interop/Connection/SpatialEventTracingTest.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 80f3c7c854..7b258e648b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,7 @@ These functions and structs can be referenced in both code and blueprints and it - Running without Ring Buffered RPCs is no longer supported, and the option has been removed from SpatialGDKSettings. - The schema database format has been updated and versioning introduced. Please regenerate your schema after updating. - The CookAndGenerateSchemaCommandlet no longer automatically deletes previously generated schema. Deletion of previously generated schema is now controlled by the `-DeleteExistingGeneratedSchema` flag. +- Event tracing has been optimised to reduce overhead when tracing events in general and in particular when events are not sampled. The tracing API has been modified to accommodate these improvements. You will have to modify your project if you use the API. ### Features: - The DeploymentLauncher tool can be used to start multiple simulated player deployments at once. diff --git a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialActorChannel.cpp b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialActorChannel.cpp index fcd21fa83d..d6240112eb 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialActorChannel.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialActorChannel.cpp @@ -20,7 +20,6 @@ #include "EngineStats.h" #include "Interop/ActorSystem.h" #include "Interop/Connection/SpatialEventTracer.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/GlobalStateManager.h" #include "Interop/SpatialReceiver.h" #include "Interop/SpatialSender.h" diff --git a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriverRPC.cpp b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriverRPC.cpp index ba062affa7..49ec9463cc 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriverRPC.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialNetDriverRPC.cpp @@ -4,7 +4,6 @@ #include "EngineClasses/SpatialNetBitReader.h" #include "EngineClasses/SpatialNetDriver.h" #include "EngineClasses/SpatialPackageMapClient.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "Utils/RPCRingBuffer.h" #include "Utils/RepLayoutUtils.h" @@ -19,10 +18,12 @@ void FRPCMetaData::ComputeSpanId(SpatialGDK::SpatialEventTracer& Tracer, Spatial { TArray ComponentUpdateSpans = Tracer.GetAndConsumeSpansForComponent(EntityComponent); + const Trace_SpanIdType* Causes = reinterpret_cast(ComponentUpdateSpans.GetData()); SpanId = Tracer.TraceEvent( - FSpatialTraceEventBuilder::CreateReceiveRPC(EventTraceUniqueId::GenerateForNamedRPC(EntityComponent.EntityId, RPCName, RPCId)), - /* Causes */ reinterpret_cast(ComponentUpdateSpans.GetData()), - /* NumCauses */ ComponentUpdateSpans.Num()); + RECEIVE_RPC_EVENT_NAME, "", Causes, ComponentUpdateSpans.Num(), + [this, EntityComponent, RPCId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForNamedRPC(EntityComponent.EntityId, RPCName, RPCId)); + }); } void FRPCPayload::ReadFromSchema(const Schema_Object* RPCObject) @@ -43,9 +44,11 @@ void FSpatialNetDriverRPC::OnRPCSent(SpatialGDK::SpatialEventTracer& EventTracer Worker_EntityId EntityId, Worker_ComponentId ComponentId, uint64 RPCId, const FSpatialGDKSpanId& SpanId) { - const EventTraceUniqueId LinearTraceId = EventTraceUniqueId::GenerateForNamedRPC(EntityId, Name, RPCId); - const FSpatialGDKSpanId NewSpanId = EventTracer.TraceEvent(FSpatialTraceEventBuilder::CreateSendRPC(LinearTraceId), - /* Causes */ SpanId.GetConstId(), /* NumCauses */ 1); + FSpatialGDKSpanId NewSpanId = + EventTracer.TraceEvent(SEND_RPC_EVENT_NAME, "", SpanId.GetConstId(), /* NumCauses */ 1, + [EntityId, Name, RPCId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForNamedRPC(EntityId, Name, RPCId)); + }); if (OutUpdates.Num() == 0 || OutUpdates.Last().EntityId != EntityId || OutUpdates.Last().Update.component_id != ComponentId) { @@ -191,9 +194,13 @@ struct FSpatialNetDriverRPC::RAIIUpdateContext : FStackOnly FSpatialGDKSpanId SpanId; if (RPCSystem.EventTracer != nullptr) { - SpanId = RPCSystem.EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreateMergeSendRPCs(Update.EntityId, Update.Update.component_id), - /* Causes */ Update.Spans.GetData()->GetConstId(), /* NumCauses */ Update.Spans.Num()); + TArray& Causes = Update.Spans; + + SpanId = RPCSystem.EventTracer->TraceEvent(MERGE_SEND_RPCS_EVENT_NAME, "", Causes.GetData()->GetConstId(), Causes.Num(), + [Update](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddEntityId(Update.EntityId); + EventBuilder.AddComponentId(Update.Update.component_id); + }); } RPCSystem.NetDriver.Connection->SendComponentUpdate(Update.EntityId, &Update.Update, SpanId); } @@ -376,8 +383,11 @@ bool FSpatialNetDriverRPC::ApplyRPC(Worker_EntityId EntityId, SpatialGDK::Receiv const bool bUseEventTracer = EventTracer != nullptr; if (bUseEventTracer) { - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateApplyRPC(TargetObject, Function), - /* Causes */ MetaData.SpanId.GetConstId(), /* NumCauses */ 1); + FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(APPLY_RPC_EVENT_NAME, "", MetaData.SpanId.GetConstId(), /* NumCauses */ 1, + [TargetObject, Function](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(TargetObject); + EventBuilder.AddFunction(Function); + }); EventTracer->AddToStack(SpanId); } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp index 01219ea6da..e32b82ec42 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp @@ -7,7 +7,6 @@ #include "EngineClasses/SpatialNetConnection.h" #include "EngineClasses/SpatialNetDriver.h" #include "GameFramework/PlayerState.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/InitialOnlyFilter.h" #include "Interop/SpatialReceiver.h" #include "Interop/SpatialSender.h" @@ -567,9 +566,17 @@ void ActorSystem::ComponentUpdated(const Worker_EntityId EntityId, const Worker_ if (EventTracer != nullptr) { + const AActor* Object = Channel->Actor; TArray CauseSpanIds = EventTracer->GetAndConsumeSpansForComponent(EntityComponentId(EntityId, ComponentId)); - EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateComponentUpdate(Channel->Actor, TargetObject, EntityId, ComponentId), - (const Trace_SpanIdType*)CauseSpanIds.GetData(), /* NumCauses */ 1); + const Trace_SpanIdType* Causes = (const Trace_SpanIdType*)CauseSpanIds.GetData(); + + EventTracer->TraceEvent(COMPONENT_UPDATE_EVENT_NAME, "", Causes, CauseSpanIds.Num(), + [Object, TargetObject, EntityId, ComponentId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(Object); + EventBuilder.AddObject(TargetObject, "TargetObject"); + EventBuilder.AddEntityId(EntityId); + EventBuilder.AddComponentId(ComponentId); + }); } ESchemaComponentType Category = NetDriver->ClassInfoManager->GetCategoryByComponentId(ComponentId); @@ -1787,7 +1794,11 @@ void ActorSystem::RetireEntity(Worker_EntityId EntityId, bool bIsNetStartupActor if (EventTracer != nullptr) { - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendRetireEntity(Actor, EntityId)); + FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(SEND_RETIRE_ENTITY_EVENT_NAME, "", /* Causes */ nullptr, /* NumCauses */ 0, + [Actor, EntityId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(Actor); + EventBuilder.AddEntityId(EntityId); + }); } NetDriver->Connection->SendDeleteEntityRequest(EntityId, RETRY_UNTIL_COMPLETE); @@ -1821,12 +1832,15 @@ void ActorSystem::SendComponentUpdates(UObject* Object, const FClassInfo& Info, for (FChangeListPropertyIterator Itr(RepChanges); Itr; ++Itr) { - GDK_PROPERTY(Property)* Property = *Itr; - - EventTraceUniqueId LinearTraceId = EventTraceUniqueId::GenerateForProperty(EntityId, Property); - FSpatialGDKSpanId PropertySpan = EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreatePropertyChanged(Object, EntityId, Property->GetName(), LinearTraceId), - /* Causes */ CauseSpanId.GetConstId(), /* NumCauses */ 1); + FSpatialGDKSpanId PropertySpan = + EventTracer->TraceEvent(PROPERTY_CHANGED_EVENT_NAME, "", CauseSpanId.GetConstId(), /* NumCauses */ 1, + [Object, EntityId, Itr](FSpatialTraceEventDataBuilder& EventBuilder) { + GDK_PROPERTY(Property)* Property = *Itr; + EventBuilder.AddObject(Object); + EventBuilder.AddEntityId(EntityId); + EventBuilder.AddKeyValue("PropertyName", Property->GetName()); + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForProperty(EntityId, Property)); + }); PropertySpans.Push(PropertySpan); } @@ -1848,8 +1862,13 @@ void ActorSystem::SendComponentUpdates(UObject* Object, const FClassInfo& Info, FSpatialGDKSpanId SpanId; if (EventTracer != nullptr) { - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendPropertyUpdate(Object, EntityId, Update.component_id), - (const Trace_SpanIdType*)PropertySpans.GetData(), PropertySpans.Num()); + const Trace_SpanIdType* Causes = (const Trace_SpanIdType*)PropertySpans.GetData(); + SpanId = EventTracer->TraceEvent(SEND_PROPERTY_UPDATE_EVENT_NAME, "", Causes, PropertySpans.Num(), + [Object, EntityId, Update](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(Object); + EventBuilder.AddEntityId(EntityId); + EventBuilder.AddComponentId(Update.component_id); + }); } NetDriver->Connection->SendComponentUpdate(EntityId, &Update, SpanId); @@ -1967,7 +1986,11 @@ void ActorSystem::SendCreateEntityRequest(USpatialActorChannel& ActorChannel, ui FSpatialGDKSpanId SpanId; if (EventTracer != nullptr) { - SpanId = EventTracer->TraceEvent(SpatialGDK::FSpatialTraceEventBuilder::CreateSendCreateEntity(Actor, EntityId)); + SpanId = EventTracer->TraceEvent(SEND_CREATE_ENTITY_EVENT_NAME, "", /* Causes */ nullptr, /* NumCauses */ 0, + [Actor, EntityId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(Actor); + EventBuilder.AddEntityId(EntityId); + }); } const Worker_RequestId CreateEntityRequestId = @@ -2020,8 +2043,11 @@ void ActorSystem::OnEntityCreated(const Worker_CreateEntityResponseOp& Op, FSpat if (EventTracer != nullptr) { - EventTracer->TraceEvent(SpatialGDK::FSpatialTraceEventBuilder::CreateReceiveCreateEntitySuccess(Actor, EntityId), - /* Causes */ CreateOpSpan.GetConstId(), /* NumCauses */ 1); + EventTracer->TraceEvent(RECEIVE_CREATE_ENTITY_SUCCESS_EVENT_NAME, "", CreateOpSpan.GetConstId(), /* NumCauses */ 1, + [Actor, EntityId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(Actor); + EventBuilder.AddEntityId(EntityId); + }); } check(NetDriver->GetNetMode() < NM_Client); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp index adabe1b777..fe69f19ae7 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp @@ -2,12 +2,10 @@ #include "Interop/Connection/SpatialEventTracer.h" -#include #include #include "HAL/PlatformFile.h" #include "HAL/PlatformFilemanager.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "SpatialGDKSettings.h" DEFINE_LOG_CATEGORY(LogSpatialEventTracer); @@ -96,7 +94,7 @@ SpatialEventTracer::SpatialEventTracer(const FString& WorkerId) const FString& EventName = Pair.Key.ToString(); UE_LOG(LogSpatialEventTracer, Log, TEXT("Adding trace event sampling override. Event: %s Probability: %f."), *EventName, Pair.Value); - int32 Index = AnsiStrings.Add((const char*)TCHAR_TO_ANSI(*EventName)); + int32 Index = AnsiStrings.Add(TCHAR_TO_ANSI(*EventName)); SpanSamplingProbabilities.Add({ AnsiStrings[Index].c_str(), Pair.Value }); } @@ -154,80 +152,6 @@ FSpatialGDKSpanId SpatialEventTracer::UserSpanIdToGDKSpanId(const FUserSpanId& U return TraceSpanId; } -FSpatialGDKSpanId SpatialEventTracer::TraceEvent(const FSpatialTraceEvent& SpatialTraceEvent, const Trace_SpanIdType* Causes /* = nullptr*/, - int32 NumCauses /* = 0*/) const -{ - if (Causes == nullptr && NumCauses > 0) - { - return {}; - } - - // Worker requires ansi const char* - std::string MessageSrc = (const char*)TCHAR_TO_ANSI(*SpatialTraceEvent.Message); // Worker requires platform ansi const char* - std::string TypeSrc = (const char*)TCHAR_TO_ANSI(*SpatialTraceEvent.Type.ToString()); // Worker requires platform ansi const char* - - // We could add the data to this event if a custom sampling callback was used. - // This would allow for sampling dependent on trace event data. - Trace_Event Event = { nullptr, 0, MessageSrc.c_str(), TypeSrc.c_str(), nullptr }; - - Trace_SamplingResult SpanSamplingResult = Trace_EventTracer_ShouldSampleSpan(EventTracer, Causes, NumCauses, &Event); - if (SpanSamplingResult.decision == Trace_SamplingDecision::TRACE_SHOULD_NOT_SAMPLE) - { - return {}; - } - - FSpatialGDKSpanId TraceSpanId; - Trace_EventTracer_AddSpan(EventTracer, Causes, NumCauses, &Event, TraceSpanId.GetId()); - Event.span_id = TraceSpanId.GetConstId(); - - Trace_SamplingResult EventSamplingResult = Trace_EventTracer_ShouldSampleEvent(EventTracer, &Event); - switch (EventSamplingResult.decision) - { - case Trace_SamplingDecision::TRACE_SHOULD_NOT_SAMPLE: - { - return TraceSpanId; - } - case Trace_SamplingDecision::TRACE_SHOULD_SAMPLE_WITHOUT_DATA: - { - Trace_EventTracer_AddEvent(EventTracer, &Event); - return TraceSpanId; - } - case Trace_SamplingDecision::TRACE_SHOULD_SAMPLE: - { - Trace_EventData* EventData = Trace_EventData_Create(); - - for (const auto& Pair : SpatialTraceEvent.Data) - { - std::string KeySrc = (const char*)TCHAR_TO_ANSI(*Pair.Key); // Worker requires platform ansi const char* - const char* Key = KeySrc.c_str(); - std::string ValueSrc = (const char*)TCHAR_TO_ANSI(*Pair.Value); // Worker requires platform ansi const char* - const char* Value = ValueSrc.c_str(); - Trace_EventData_AddStringFields(EventData, 1, &Key, &Value); - } - - // Frame counter - { - const char* FrameCountStr = "FrameNum"; - char TmpBuffer[64]; - FCStringAnsi::Sprintf(TmpBuffer, "%" PRIu64, GFrameCounter); - const char* TmpBufferPtr = TmpBuffer; - Trace_EventData_AddStringFields(EventData, 1, &FrameCountStr, &TmpBufferPtr); - } - - Event.data = EventData; - Trace_EventTracer_AddEvent(EventTracer, &Event); - Trace_EventData_Destroy(EventData); - return TraceSpanId; - } - default: - { - UE_LOG(LogSpatialEventTracer, Log, TEXT("Could not handle invalid sampling decision %d."), - static_cast(EventSamplingResult.decision)); - return {}; - } - } -} - void SpatialEventTracer::StreamDeleter::operator()(Io_Stream* StreamToDestroy) const { Io_Stream_Destroy(StreamToDestroy); @@ -244,19 +168,34 @@ void SpatialEventTracer::BeginOpsForFrame() void SpatialEventTracer::AddEntity(const Worker_AddEntityOp& Op, const FSpatialGDKSpanId& SpanId) { - TraceEvent(FSpatialTraceEventBuilder::CreateReceiveCreateEntity(Op.entity_id), /* Causes */ SpanId.GetConstId(), /* NumCauses */ 1); + Worker_EntityId EntityId = Op.entity_id; + TraceEvent(RECEIVE_CREATE_ENTITY_EVENT_NAME, "", SpanId.GetConstId(), /* NumCauses */ 1, + [EntityId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddEntityId(EntityId); + }); } void SpatialEventTracer::RemoveEntity(const Worker_RemoveEntityOp& Op, const FSpatialGDKSpanId& SpanId) { - TraceEvent(FSpatialTraceEventBuilder::CreateReceiveRemoveEntity(Op.entity_id), /* Causes */ SpanId.GetConstId(), /* NumCauses */ 1); + Worker_EntityId EntityId = Op.entity_id; + TraceEvent(RECEIVE_REMOVE_ENTITY_EVENT_NAME, "", SpanId.GetConstId(), /* NumCauses */ 1, + [EntityId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddEntityId(EntityId); + }); } void SpatialEventTracer::AuthorityChange(const Worker_ComponentSetAuthorityChangeOp& Op, const FSpatialGDKSpanId& SpanId) { - TraceEvent( - FSpatialTraceEventBuilder::CreateAuthorityChange(Op.entity_id, Op.component_set_id, static_cast(Op.authority)), - /* Causes */ SpanId.GetConstId(), /* NumCauses */ 1); + Worker_EntityId EntityId = Op.entity_id; + Worker_ComponentSetId ComponentSetId = Op.component_set_id; + Worker_Authority Authority = static_cast(Op.authority); + + TraceEvent(AUTHORITY_CHANGE_EVENT_NAME, "", SpanId.GetConstId(), /* NumCauses */ 1, + [EntityId, ComponentSetId, Authority](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddEntityId(EntityId); + EventBuilder.AddComponentSetId(ComponentSetId); + EventBuilder.AddAuthority(Authority); + }); } void SpatialEventTracer::AddComponent(const Worker_AddComponentOp& Op, const FSpatialGDKSpanId& SpanId) @@ -345,8 +284,13 @@ void SpatialEventTracer::AddLatentPropertyUpdateSpanId(const TWeakObjectPtr(&CauseSpanIds), /* NumCauses */ 2); + uint8_t* Causes = reinterpret_cast(&CauseSpanIds); + const UObject* ObjectPtr = Object.Get(); + + *ExistingSpanId = TraceEvent(MERGE_PROPERTY_UPDATE_EVENT_NAME, "", Causes, /* NumCauses */ 2, + [ObjectPtr](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(ObjectPtr); + }); } } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp index 63679548db..cc55026b16 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp @@ -5,7 +5,7 @@ #include "Engine/Engine.h" #include "EngineClasses/SpatialNetDriver.h" #include "EngineClasses/SpatialPackageMapClient.h" -#include "Interop/Connection/SpatialEventTracer.h" + #include "Interop/Connection/SpatialWorkerConnection.h" #include "Interop/SpatialClassInfoManager.h" @@ -32,7 +32,8 @@ TArray ConvertSpanIds(const TArray& Causes) } } // namespace -FUserSpanId USpatialEventTracerUserInterface::TraceEvent(UObject* WorldContextObject, const FSpatialTraceEvent& SpatialTraceEvent) +FUserSpanId USpatialEventTracerUserInterface::TraceEvent(UObject* WorldContextObject, const FString& EventType, const FString& EventMessage, + const TMap& Data) { SpatialGDK::SpatialEventTracer* EventTracer = GetEventTracer(WorldContextObject); if (EventTracer == nullptr) @@ -40,12 +41,19 @@ FUserSpanId USpatialEventTracerUserInterface::TraceEvent(UObject* WorldContextOb return {}; } - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(SpatialTraceEvent, /* Causes */ nullptr, /* NumCauses */ 0); + FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(TCHAR_TO_ANSI(*EventType), TCHAR_TO_ANSI(*EventMessage), /* Causes */ nullptr, + /* NumCauses */ 0, [Data](SpatialGDK::FSpatialTraceEventDataBuilder& EventBuilder) { + for (const auto& Pair : Data) + { + EventBuilder.AddKeyValue(Pair.Key, Pair.Value); + } + }); + return SpatialGDK::SpatialEventTracer::GDKSpanIdToUserSpanId(SpanId); } -FUserSpanId USpatialEventTracerUserInterface::TraceEventBasic(UObject* WorldContextObject, FName Type, FString Message, - const TArray& Causes) +FUserSpanId USpatialEventTracerUserInterface::TraceEvent(UObject* WorldContextObject, const char* EventType, const char* EventMessage, + FEventTracerAddDataDelegate AddDataDelegate) { SpatialGDK::SpatialEventTracer* EventTracer = GetEventTracer(WorldContextObject); if (EventTracer == nullptr) @@ -53,16 +61,16 @@ FUserSpanId USpatialEventTracerUserInterface::TraceEventBasic(UObject* WorldCont return {}; } - FSpatialTraceEvent TraceEvent; - TraceEvent.Type = Type; - TraceEvent.Message = Message; + FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(EventType, EventMessage, /* Causes */ nullptr, /* NumCauses */ 0, + [AddDataDelegate](SpatialGDK::FSpatialTraceEventDataBuilder& EventBuilder) { + AddDataDelegate.ExecuteIfBound(EventBuilder); + }); - TArray CauseSpanIds = ConvertSpanIds(Causes); - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(TraceEvent, (const Trace_SpanIdType*)CauseSpanIds.GetData(), CauseSpanIds.Num()); return SpatialGDK::SpatialEventTracer::GDKSpanIdToUserSpanId(SpanId); } -FUserSpanId USpatialEventTracerUserInterface::TraceEventWithCauses(UObject* WorldContextObject, const FSpatialTraceEvent& SpatialTraceEvent, +FUserSpanId USpatialEventTracerUserInterface::TraceEventWithCauses(UObject* WorldContextObject, const FString& EventType, + const FString& EventMessage, const TMap& Data, const TArray& Causes) { SpatialGDK::SpatialEventTracer* EventTracer = GetEventTracer(WorldContextObject); @@ -72,7 +80,34 @@ FUserSpanId USpatialEventTracerUserInterface::TraceEventWithCauses(UObject* Worl } TArray CauseSpanIds = ConvertSpanIds(Causes); - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(SpatialTraceEvent, CauseSpanIds.GetData()->GetId(), CauseSpanIds.Num()); + FSpatialGDKSpanId SpanId = + EventTracer->TraceEvent(TCHAR_TO_ANSI(*EventType), TCHAR_TO_ANSI(*EventMessage), CauseSpanIds.GetData()->GetId(), + CauseSpanIds.Num(), [Data](SpatialGDK::FSpatialTraceEventDataBuilder& EventBuilder) { + for (const auto& Pair : Data) + { + EventBuilder.AddKeyValue(Pair.Key, Pair.Value); + } + }); + + return SpatialGDK::SpatialEventTracer::GDKSpanIdToUserSpanId(SpanId); +} + +FUserSpanId USpatialEventTracerUserInterface::TraceEventWithCauses(UObject* WorldContextObject, const char* EventType, + const char* EventMessage, const TArray& Causes, + FEventTracerAddDataDelegate AddDataDelegate) +{ + SpatialGDK::SpatialEventTracer* EventTracer = GetEventTracer(WorldContextObject); + if (EventTracer == nullptr) + { + return {}; + } + + TArray CauseSpanIds = ConvertSpanIds(Causes); + FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(EventType, EventMessage, CauseSpanIds.GetData()->GetId(), CauseSpanIds.Num(), + [AddDataDelegate](SpatialGDK::FSpatialTraceEventDataBuilder& EventBuilder) { + AddDataDelegate.ExecuteIfBound(EventBuilder); + }); + return SpatialGDK::SpatialEventTracer::GDKSpanIdToUserSpanId(SpanId); } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventBuilder.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventBuilder.cpp deleted file mode 100644 index 173b5c5d9d..0000000000 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventBuilder.cpp +++ /dev/null @@ -1,375 +0,0 @@ -// Copyright (c) Improbable Worlds Ltd, All Rights Reserved - -#include "Interop/Connection/SpatialTraceEventBuilder.h" - -#include "EngineClasses/SpatialNetDriver.h" -#include "EngineClasses/SpatialPackageMapClient.h" -#include "Utils/SpatialActorUtils.h" - -namespace SpatialGDK -{ -FSpatialTraceEventBuilder::FSpatialTraceEventBuilder(FName InType) - : SpatialTraceEvent(MoveTemp(InType), "") -{ -} - -FSpatialTraceEventBuilder::FSpatialTraceEventBuilder(FName InType, FString InMessage) - : SpatialTraceEvent(MoveTemp(InType), MoveTemp(InMessage)) -{ -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddObject(FString Key, const UObject* Object) -{ - if (Object != nullptr) - { - if (const AActor* Actor = Cast(Object)) - { - AddKeyValue(Key + TEXT("ActorPosition"), Actor->GetTransform().GetTranslation().ToString()); - } - if (UWorld* World = Object->GetWorld()) - { - if (USpatialNetDriver* NetDriver = Cast(World->GetNetDriver())) - { - AddKeyValue(Key + TEXT("NetGuid"), NetDriver->PackageMap->GetNetGUIDFromObject(Object).ToString()); - } - } - AddKeyValue(MoveTemp(Key), Object->GetName()); - } - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddFunction(FString Key, const UFunction* Function) -{ - if (Function != nullptr) - { - AddKeyValue(MoveTemp(Key), Function->GetName()); - } - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddEntityId(FString Key, const Worker_EntityId EntityId) -{ - AddKeyValue(MoveTemp(Key), FString::FromInt(EntityId)); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddComponentId(FString Key, const Worker_ComponentId ComponentId) -{ - AddKeyValue(MoveTemp(Key), FString::FromInt(ComponentId)); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddFieldId(FString Key, const uint32 FieldId) -{ - AddKeyValue(MoveTemp(Key), FString::FromInt(FieldId)); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddNewWorkerId(FString Key, const uint32 NewWorkerId) -{ - AddKeyValue(MoveTemp(Key), FString::FromInt(NewWorkerId)); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddCommand(FString Key, const FString& Command) -{ - AddKeyValue(MoveTemp(Key), Command); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddRequestId(FString Key, const int64 RequestId) -{ - AddKeyValue(MoveTemp(Key), FString::FromInt(RequestId)); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddAuthority(FString Key, const Worker_Authority Authority) -{ - AddKeyValue(MoveTemp(Key), AuthorityToString(Authority)); - return *this; -} - -FSpatialTraceEventBuilder FSpatialTraceEventBuilder::AddKeyValue(FString Key, FString Value) -{ - SpatialTraceEvent.AddData(MoveTemp(Key), MoveTemp(Value)); - return *this; -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::GetEvent() && -{ - return MoveTemp(SpatialTraceEvent); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateApplyRPC(const UObject* Object, UFunction* Function) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "apply_rpc") - .AddObject(TEXT("Object"), Object) - .AddFunction(TEXT("Function"), Function) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveRPC(const EventTraceUniqueId& LinearTraceId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_rpc") - .AddKeyValue(TEXT("LinearTraceId"), LinearTraceId.ToString()) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreatePushRPC(const UObject* Object, UFunction* Function) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "push_rpc") - .AddObject(TEXT("Object"), Object) - .AddFunction(TEXT("Function"), Function) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendCrossServerRPC(const UObject* Object, UFunction* Function, - const EventTraceUniqueId& LinearTraceId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_cross_server_rpc") - .AddObject(TEXT("Object"), Object) - .AddFunction(TEXT("Function"), Function) - .AddKeyValue(TEXT("LinearTraceId"), LinearTraceId.ToString()) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCrossServerRPC(const EventTraceUniqueId& LinearTraceId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_cross_server_rpc") - .AddKeyValue(TEXT("LinearTraceId"), LinearTraceId.ToString()) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateApplyCrossServerRPC(const UObject* Object, UFunction* Function) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "apply_cross_server_rpc") - .AddObject(TEXT("Object"), Object) - .AddFunction(TEXT("Function"), Function) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendRPC(const EventTraceUniqueId& LinearTraceId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_rpc") - .AddKeyValue(TEXT("LinearTraceId"), LinearTraceId.ToString()) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateQueueRPC() -{ - return FSpatialTraceEventBuilder("queue_rpc").GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateRetryRPC() -{ - return FSpatialTraceEventBuilder("retry_rpc").GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreatePropertyChanged(const UObject* Object, const Worker_EntityId EntityId, - const FString& PropertyName, EventTraceUniqueId LinearTraceId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "property_changed") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .AddKeyValue(TEXT("PropertyName"), PropertyName) - .AddKeyValue(TEXT("LinearTraceId"), LinearTraceId.ToString()) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendPropertyUpdate(const UObject* Object, const Worker_EntityId EntityId, - const Worker_ComponentId ComponentId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_property_update") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .AddEntityId(TEXT("ComponentId"), ComponentId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceivePropertyUpdate(const UObject* Object, const Worker_EntityId EntityId, - const Worker_ComponentId ComponentId, const FString& PropertyName, - EventTraceUniqueId LinearTraceId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_property_update") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .AddComponentId(TEXT("ComponentId"), ComponentId) - .AddKeyValue("PropertyName", PropertyName) - .AddKeyValue(TEXT("LinearTraceId"), LinearTraceId.ToString()) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateMergeSendRPCs(const Worker_EntityId EntityId, const Worker_ComponentId ComponentId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "merge_send_rpcs") - .AddEntityId(TEXT("EntityId"), EntityId) - .AddComponentId(TEXT("ComponentId"), ComponentId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateObjectPropertyComponentUpdate(const UObject* Object) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "merge_property_update").AddObject(TEXT("Object"), Object).GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendCommandRequest(const FString& Command, const int64 RequestId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_command_request") - .AddCommand(TEXT("Command"), Command) - .AddRequestId(TEXT("RequestId"), RequestId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCommandRequest(const FString& Command, const int64 RequestId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_command_request") - .AddCommand(TEXT("Command"), Command) - .AddRequestId(TEXT("RequestId"), RequestId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCommandRequest(const FString& Command, const UObject* Actor, - const UObject* TargetObject, const UFunction* Function, - const int32 TraceId, const int64 RequestId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_command_request") - .AddCommand(TEXT("Command"), Command) - .AddObject(TEXT("Object"), Actor) - .AddObject(TEXT("TargetObject"), TargetObject) - .AddFunction(TEXT("Function"), Function) - .AddKeyValue(TEXT("TraceId"), FString::FromInt(TraceId)) - .AddRequestId(TEXT("RequestId"), RequestId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendCommandResponse(const int64 RequestId, const bool bSuccess) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_command_response") - .AddRequestId(TEXT("RequestId"), RequestId) - .AddKeyValue(TEXT("Success"), BoolToString(bSuccess)) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCommandResponse(const FString& Command, const int64 RequestId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_command_response") - .AddCommand(TEXT("Command"), Command) - .AddRequestId(TEXT("RequestId"), RequestId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCommandResponse(const UObject* Actor, const int64 RequestId, const bool bSuccess) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_command_response") - .AddObject(TEXT("Object"), Actor) - .AddRequestId(TEXT("RequestId"), RequestId) - .AddKeyValue(TEXT("Success"), BoolToString(bSuccess)) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCommandResponse(const UObject* Actor, const UObject* TargetObject, - const UFunction* Function, int64 RequestId, const bool bSuccess) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_command_response") - .AddObject(TEXT("Object"), Actor) - .AddObject(TEXT("TargetObject"), TargetObject) - .AddFunction(TEXT("Function"), Function) - .AddRequestId(TEXT("RequestId"), RequestId) - .AddKeyValue(TEXT("Success"), BoolToString(bSuccess)) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendRemoveEntity(const UObject* Object, const Worker_EntityId EntityId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_remove_entity") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveRemoveEntity(const Worker_EntityId EntityId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_remove_entity").AddEntityId(TEXT("EntityId"), EntityId).GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendCreateEntity(const UObject* Object, const Worker_EntityId EntityId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_create_entity") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCreateEntity(const Worker_EntityId EntityId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_create_entity").AddEntityId(TEXT("EntityId"), EntityId).GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateReceiveCreateEntitySuccess(const UObject* Object, const Worker_EntityId EntityId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "receive_create_entity_success") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateSendRetireEntity(const UObject* Object, const Worker_EntityId EntityId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "send_retire_entity") - .AddObject(TEXT("Object"), Object) - .AddEntityId(TEXT("EntityId"), EntityId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateAuthorityIntentUpdate(VirtualWorkerId WorkerId, const UObject* Object) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "authority_intent_update") - .AddObject(TEXT("Object"), Object) - .AddNewWorkerId(TEXT("NewWorkerId"), WorkerId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateAuthorityChange(const Worker_EntityId EntityId, const Worker_ComponentId ComponentId, - const Worker_Authority Authority) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "authority_change") - .AddEntityId(TEXT("EntityId"), EntityId) - .AddComponentId(TEXT("ComponentId"), ComponentId) - .AddAuthority(TEXT("Authority"), Authority) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateComponentUpdate(const UObject* Object, const UObject* TargetObject, - const Worker_EntityId EntityId, const Worker_ComponentId ComponentId) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "component_update") - .AddObject(TEXT("Object"), Object) - .AddObject(TEXT("TargetObject"), TargetObject) - .AddEntityId(TEXT("EntityId"), EntityId) - .AddComponentId(TEXT("ComponentId"), ComponentId) - .GetEvent(); -} - -FSpatialTraceEvent FSpatialTraceEventBuilder::CreateGenericMessage(FString Message) -{ - return FSpatialTraceEventBuilder(GDK_EVENT_NAMESPACE "generic_message", MoveTemp(Message)).GetEvent(); -} - -FString FSpatialTraceEventBuilder::AuthorityToString(Worker_Authority Authority) -{ - switch (Authority) - { - case Worker_Authority::WORKER_AUTHORITY_NOT_AUTHORITATIVE: - return TEXT("NotAuthoritative"); - case Worker_Authority::WORKER_AUTHORITY_AUTHORITATIVE: - return TEXT("Authoritative"); - default: - return TEXT("Unknown"); - } -} - -FString FSpatialTraceEventBuilder::BoolToString(bool bInput) -{ - return bInput ? TEXT("True") : TEXT("False"); -} -} // namespace SpatialGDK diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp new file mode 100644 index 0000000000..e88775b097 --- /dev/null +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp @@ -0,0 +1,223 @@ +// Copyright (c) Improbable Worlds Ltd, All Rights Reserved + +#include "Interop/Connection/SpatialTraceEventDataBuilder.h" + +#include + +#include "EngineClasses/SpatialNetDriver.h" +#include "EngineClasses/SpatialPackageMapClient.h" +#include "Utils/SpatialActorUtils.h" + +#include "Math/UnrealMathUtility.h" + +DEFINE_LOG_CATEGORY(FSpatialTraceEventDataBuilderLog); + +namespace SpatialGDK +{ +// ---- FStringCache ---- + +int32 FSpatialTraceEventDataBuilder::FStringCache::CombineStrings(const char* A, const char* B) +{ + int32 InsertIndex = NextIndex; + AddString(A); + NextIndex--; + AddString(B); + return InsertIndex; +} + +int32 FSpatialTraceEventDataBuilder::FStringCache::AddString(const char* String) +{ + if (NextIndex >= BufferSize) + { + return BufferSize - 1; + } + + int32 InsertIndex = NextIndex; + int32 InitialRemainingSize = BufferSize - NextIndex; + FCStringAnsi::Strncpy(&Buffer[NextIndex], String, InitialRemainingSize); + + int32 CharSize = sizeof(char); + int32 StringLength = CharSize * (FCStringAnsi::Strlen(&Buffer[NextIndex]) + 1); + int32 RemainingSize = InitialRemainingSize - StringLength; + + NextIndex += InitialRemainingSize - RemainingSize; + return InsertIndex; +} + +int32 FSpatialTraceEventDataBuilder::FStringCache::AddFString(const FString& String) +{ + return AddString(TCHAR_TO_ANSI(*String)); +} + +int32 FSpatialTraceEventDataBuilder::FStringCache::AddUInt32(uint32 Value) +{ + return AddInteger(Value, "%" PRIu32); +} + +int32 FSpatialTraceEventDataBuilder::FStringCache::AddUInt64(uint64 Value) +{ + return AddInteger(Value, "%" PRIu64); +} + +int32 FSpatialTraceEventDataBuilder::FStringCache::AddInt32(int32 Value) +{ + return AddInteger(Value, "%" PRId32); +} + +int32 FSpatialTraceEventDataBuilder::FStringCache::AddInt64(int64 Value) +{ + return AddInteger(Value, "%" PRId64); +} + +const char* FSpatialTraceEventDataBuilder::FStringCache::Get(int32 Handle) const +{ + return &Buffer[Handle]; +} + +// ---- FSpatialTraceEventDataBuilder ---- + +FSpatialTraceEventDataBuilder::FSpatialTraceEventDataBuilder() + : EventData(Trace_EventData_Create()) +{ +} + +FSpatialTraceEventDataBuilder::~FSpatialTraceEventDataBuilder() +{ + Trace_EventData_Destroy(EventData); +} + +void FSpatialTraceEventDataBuilder::AddObject(const UObject* Object, const char* Key /*="Object"*/) +{ + if (Object != nullptr) + { + if (const AActor* Actor = Cast(Object)) + { + FString PositionString = Actor->GetTransform().GetTranslation().ToString(); + AddKeyValue(StringConverter.CombineStrings(Key, "ActorPosition"), StringConverter.AddFString(PositionString)); + } + if (UWorld* World = Object->GetWorld()) + { + if (USpatialNetDriver* NetDriver = Cast(World->GetNetDriver())) + { + FString NetGuidString = NetDriver->PackageMap->GetNetGUIDFromObject(Object).ToString(); + AddKeyValue(StringConverter.CombineStrings(Key, "NetGuid"), StringConverter.AddFString(NetGuidString)); + } + } + AddKeyValue(Key, Object->GetName()); + } +} + +void FSpatialTraceEventDataBuilder::AddFunction(const UFunction* Function, const char* Key /*="Function"*/) +{ + if (Function != nullptr) + { + AddKeyValue(Key, Function->GetName()); + } +} + +void FSpatialTraceEventDataBuilder::AddEntityId(const Worker_EntityId EntityId, const char* Key /*="EntityId"*/) +{ + AddKeyValue(Key, static_cast(EntityId)); +} + +void FSpatialTraceEventDataBuilder::AddComponentId(const Worker_ComponentId ComponentId, const char* Key /*="ComponentId"*/) +{ + AddKeyValue(Key, static_cast(ComponentId)); +} + +void FSpatialTraceEventDataBuilder::AddComponentSetId(const Worker_ComponentSetId ComponentSetId, const char* Key /*="ComponentSetId"*/) +{ + AddKeyValue(Key, static_cast(ComponentSetId)); +} + +void FSpatialTraceEventDataBuilder::AddFieldId(const uint32 FieldId, const char* Key /*="FieldId"*/) +{ + AddKeyValue(Key, FieldId); +} + +void FSpatialTraceEventDataBuilder::AddWorkerId(const uint32 WorkerId, const char* Key /*="WorkerId"*/) +{ + AddKeyValue(Key, WorkerId); +} + +void FSpatialTraceEventDataBuilder::AddCommand(const char* Command, const char* Key /*="Command"*/) +{ + AddKeyValue(Key, Command); +} + +void FSpatialTraceEventDataBuilder::AddRequestId(const int64 RequestId, const char* Key /*="RequestId"*/) +{ + AddKeyValue(Key, RequestId); +} + +void FSpatialTraceEventDataBuilder::AddAuthority(const Worker_Authority Authority, const char* Key /*="Authority"*/) +{ + AddKeyValue(Key, AuthorityToString(Authority)); +} + +void FSpatialTraceEventDataBuilder::AddLinearTraceId(const EventTraceUniqueId LinearTraceId, const char* Key /*="LinearTraceId"*/) +{ + AddKeyValue(Key, LinearTraceId.Get()); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const char* Value) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddString(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const FString& Value) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddFString(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const FString& Key, const FString& Value) +{ + AddKeyValue(StringConverter.AddFString(Key), StringConverter.AddFString(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const uint32 Value) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddUInt32(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const uint64 Value) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddUInt64(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const int32 Value) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddInt32(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const int64 Value) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddInt64(Value)); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const bool bValue) +{ + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddString(bValue ? "True" : "False")); +} + +void FSpatialTraceEventDataBuilder::AddKeyValue(int32 KeyHandle, int32 ValueHandle) +{ + const char* Key = StringConverter.Get(KeyHandle); + const char* Value = StringConverter.Get(ValueHandle); + Trace_EventData_AddStringFields(EventData, 1, &Key, &Value); +} + +const char* FSpatialTraceEventDataBuilder::AuthorityToString(Worker_Authority Authority) +{ + switch (Authority) + { + case Worker_Authority::WORKER_AUTHORITY_NOT_AUTHORITATIVE: + return "NotAuthoritative"; + case Worker_Authority::WORKER_AUTHORITY_AUTHORITATIVE: + return "Authoritative"; + default: + return "Unknown"; + } +} + +} // namespace SpatialGDK diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCHandler.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCHandler.cpp index eed3c2af0e..cc7aff1847 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCHandler.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCHandler.cpp @@ -3,7 +3,6 @@ #include "Interop/CrossServerRPCHandler.h" #include "Interop/Connection/SpatialEventTracer.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "SpatialGDKSettings.h" @@ -81,10 +80,12 @@ void CrossServerRPCHandler::HandleWorkerOp(const Worker_Op& Op) { if (ensureMsgf(Params->Payload.Id.IsSet(), TEXT("Cross-server RPCs are expected to have a payload ID for event tracing."))) { - SpanId = EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreateReceiveCrossServerRPC( - EventTraceUniqueId::GenerateForCrossServerRPC(CommandOp.entity_id, Params->Payload.Id.GetValue())), - /* Causes */ EventTracer->GetAndConsumeSpanForRequestId(Op.op.command_request.request_id).GetConstId(), /* NumCauses */ 1); + SpanId = EventTracer->TraceEvent(RECEIVE_CROSS_SERVER_RPC_EVENT_NAME, "", + EventTracer->GetAndConsumeSpanForRequestId(Op.op.command_request.request_id).GetConstId(), + /* NumCauses */ 1, [CommandOp, &Params](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForCrossServerRPC( + CommandOp.entity_id, Params->Payload.Id.GetValue())); + }); } } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCSender.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCSender.cpp index ee84ce3587..3d5ff8b794 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCSender.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/CrossServerRPCSender.cpp @@ -1,9 +1,8 @@ -// Copyright (c) Improbable Worlds Ltd, All Rights Reserved +// Copyright (c) Improbable Worlds Ltd, All Rights Reserved #include "Interop/CrossServerRPCSender.h" #include "Interop/Connection/SpatialEventTracer.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "Utils/SpatialMetrics.h" @@ -37,9 +36,12 @@ void CrossServerRPCSender::SendCommand(const FUnrealObjectRef InTargetObjectRef, if (EventTracer) { SpanId = EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreateSendCrossServerRPC( - TargetObject, Function, EventTraceUniqueId::GenerateForCrossServerRPC(InTargetObjectRef.Entity, UniqueRPCId)), - /* Causes */ EventTracer->GetFromStack().GetConstId(), /* NumCauses */ 1); + SEND_CROSS_SERVER_RPC_EVENT_NAME, "", EventTracer->GetFromStack().GetConstId(), /* NumCauses */ 1, + [TargetObject, Function, InTargetObjectRef, UniqueRPCId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(TargetObject); + EventBuilder.AddFunction(Function); + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForCrossServerRPC(InTargetObjectRef.Entity, UniqueRPCId)); + }); } if (Function->HasAnyFunctionFlags(FUNC_NetReliable)) diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp index 7a21dd4f05..73d34d72af 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp @@ -3,7 +3,6 @@ #include "Interop/DebugMetricsSystem.h" #include "EngineClasses/SpatialNetDriver.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" DEFINE_LOG_CATEGORY_STATIC(LogSpatialDebugMetrics, Log, All); @@ -93,8 +92,11 @@ void DebugMetricsSystem::ProcessOps(const TArray& Ops) const if (EventTracer != nullptr) { - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendCommandResponse(RequestId, true), - CauseSpanId.GetConstId(), 1); + SpanId = EventTracer->TraceEvent(SEND_COMMAND_RESPONSE_EVENT_NAME, "", CauseSpanId.GetConstId(), /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddRequestId(RequestId); + EventBuilder.AddKeyValue("Success", true); + }); } Connection.SendCommandResponse(RequestId, &Response, SpanId); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/GlobalStateManager.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/GlobalStateManager.cpp index bc252ff66c..7e0f1d965c 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/GlobalStateManager.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/GlobalStateManager.cpp @@ -15,7 +15,6 @@ #include "EngineClasses/SpatialPackageMapClient.h" #include "EngineClasses/SpatialVirtualWorkerTranslator.h" #include "EngineUtils.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "Interop/SpatialReceiver.h" #include "Interop/SpatialSender.h" @@ -222,9 +221,12 @@ void UGlobalStateManager::OnReceiveShutdownCommand(const Worker_Op& Op, const Wo if (EventTracer != nullptr) { - EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateReceiveCommandRequest(TEXT("SHUTDOWN_MULTI_PROCESS_REQUEST"), - Op.op.command_request.request_id), - /* Causes */ Op.span_id, /* NumCauses */ 1); + Worker_RequestId RequestId = Op.op.command_request.request_id; + EventTracer->TraceEvent(RECEIVE_COMMAND_REQUEST_EVENT_NAME, "", Op.span_id, /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddCommand("SHUTDOWN_MULTI_PROCESS_REQUEST"); + EventBuilder.AddRequestId(RequestId); + }); } } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp index f7fb3a9461..ecc9c58608 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp @@ -3,7 +3,6 @@ #include "Interop/MigrationDiagnosticsSystem.h" #include "EngineClasses/SpatialNetDriver.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "Schema/MigrationDiagnostic.h" @@ -38,8 +37,11 @@ void MigrationDiagnosticsSystem::OnMigrationDiagnosticRequest(const Worker_Op& O if (EventTracer != nullptr) { - EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendCommandResponse(RequestId, true), - /* Causes */ CauseSpanId.GetConstId(), /* NumCauses */ 1); + EventTracer->TraceEvent(SEND_COMMAND_RESPONSE_EVENT_NAME, "", CauseSpanId.GetConstId(), /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddRequestId(RequestId); + EventBuilder.AddKeyValue("Success", true); + }); } Connection.SendCommandResponse(RequestId, &Response, CauseSpanId); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp index f15362a03b..4c630124df 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp @@ -3,7 +3,6 @@ #include "Interop/RPCExecutor.h" #include "Interop/Connection/SpatialEventTracer.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/SpatialPlayerSpawner.h" #include "Interop/SpatialReceiver.h" #include "Interop/SpatialSender.h" @@ -54,8 +53,12 @@ bool RPCExecutor::ExecuteCommand(const FCrossServerRPCParams& Params) { if (EventTracer != nullptr) { - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateApplyCrossServerRPC(TargetObject, Function), - /* Causes */ Params.SpanId.GetConstId(), /* NumCauses*/ 1); + FSpatialGDKSpanId SpanId = + EventTracer->TraceEvent(APPLY_CROSS_SERVER_RPC_EVENT_NAME, "", Params.SpanId.GetConstId(), /* NumCauses */ 1, + [TargetObject, Function](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(TargetObject); + EventBuilder.AddFunction(Function); + }); EventTracer->AddToStack(SpanId); } @@ -119,9 +122,15 @@ TOptional RPCExecutor::TryRetrieveCrossServerRPCParams(co FSpatialGDKSpanId SpanId; if (EventTracer != nullptr) { - UObject* TraceTargetObject = TargetActor != TargetObject ? TargetObject : nullptr; - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateReceiveCommandRequest( - "RPC_COMMAND_REQUEST", TargetActor, TraceTargetObject, Function, TraceId, Op.op.command_request.request_id)); + SpanId = EventTracer->TraceEvent(RECEIVE_COMMAND_REQUEST_EVENT_NAME, "", /* Causes */ nullptr, /* NumCauses */ 0, + [TargetActor, TargetObject, Function, TraceId, Op](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddCommand("RPC_COMMAND_REQUEST"); + EventBuilder.AddObject(TargetActor); + EventBuilder.AddObject(TargetActor != TargetObject ? TargetObject : nullptr, "TargetObject"); + EventBuilder.AddFunction(Function); + EventBuilder.AddKeyValue("TraceId", TraceId); + EventBuilder.AddRequestId(Op.op.command_request.request_id); + }); } FCrossServerRPCParams Params(ObjectRef, Op.op.command_request.request_id, MoveTemp(Payload), SpanId); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCs/SpatialRPCService.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCs/SpatialRPCService.cpp index 0f87d8287a..5734faf198 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCs/SpatialRPCService.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCs/SpatialRPCService.cpp @@ -6,7 +6,6 @@ #include "EngineClasses/SpatialNetBitReader.h" #include "EngineClasses/SpatialNetConnection.h" #include "EngineClasses/SpatialPackageMapClient.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "Net/NetworkProfiler.h" #include "SpatialConstants.h" @@ -130,8 +129,8 @@ EPushRPCResult SpatialRPCService::PushRPC(const Worker_EntityId EntityId, const { if (EventTracer != nullptr) { - PendingPayload.SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateQueueRPC(), - /* Causes */ PendingPayload.SpanId.GetConstId(), /* NumCauses */ 1); + PendingPayload.SpanId = EventTracer->TraceEvent(QUEUE_RPC_EVENT_NAME, "", PendingPayload.SpanId.GetConstId(), + /* NumCauses */ 1, [](FSpatialTraceEventDataBuilder& EventBuilder) {}); } // Already has queued RPCs of this type, queue until those are pushed. @@ -184,8 +183,8 @@ void SpatialRPCService::PushOverflowedRPCs() } if (EventTracer != nullptr) { - Payload.SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateQueueRPC(), - /* Causes */ Payload.SpanId.GetConstId(), /* NumCauses */ 1); + Payload.SpanId = EventTracer->TraceEvent(QUEUE_RPC_EVENT_NAME, "", Payload.SpanId.GetConstId(), /* NumCauses */ 1, + [](FSpatialTraceEventDataBuilder& EventBuilder) {}); } break; case EPushRPCResult::DropOverflowed: @@ -248,9 +247,12 @@ TArray SpatialRPCService::GetRPCsAndAcksToSend( if (EventTracer != nullptr) { - UpdateToSend.SpanId = EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreateMergeSendRPCs(UpdateToSend.EntityId, UpdateToSend.Update.component_id), - /* Causes */ It.Value.SpanIds.GetData()->GetConstId(), /* NumCauses */ It.Value.SpanIds.Num()); + TArray& Causes = It.Value.SpanIds; + UpdateToSend.SpanId = EventTracer->TraceEvent(MERGE_SEND_RPC_EVENT_NAME, "", Causes.GetData()->GetConstId(), Causes.Num(), + [UpdateToSend](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddEntityId(UpdateToSend.EntityId); + EventBuilder.AddComponentId(UpdateToSend.Update.component_id); + }); } #if TRACE_LIB_ACTIVE @@ -351,10 +353,13 @@ void SpatialRPCService::ProcessOrQueueIncomingRPC(const FUnrealObjectRef& InTarg { TArray ComponentUpdateSpans = EventTracer->GetAndConsumeSpansForComponent( EntityComponentId(InTargetObjectRef.Entity, RPCRingBufferUtils::GetRingBufferComponentId(Type))); - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateReceiveRPC(EventTraceUniqueId::GenerateForRPC( - InTargetObjectRef.Entity, static_cast(Type), RPCIdForLinearEventTrace.GetValue())), - /* Causes */ reinterpret_cast(ComponentUpdateSpans.GetData()), - /* NumCauses */ ComponentUpdateSpans.Num()); + + const Trace_SpanIdType* Causes = reinterpret_cast(ComponentUpdateSpans.GetData()); + SpanId = EventTracer->TraceEvent(RECEIVE_RPC_EVENT_NAME, "", Causes, ComponentUpdateSpans.Num(), + [InTargetObjectRef, Type, RPCIdForLinearEventTrace](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForRPC( + InTargetObjectRef.Entity, static_cast(Type), RPCIdForLinearEventTrace.GetValue())); + }); } IncomingRPCs.ProcessOrQueueRPC(InTargetObjectRef, InSender, Type, MoveTemp(InPayload), SpanId); @@ -448,9 +453,11 @@ EPushRPCResult SpatialRPCService::PushRPCInternal(const Worker_EntityId EntityId { if (EventTracer != nullptr) { - EventTraceUniqueId LinearTraceId = EventTraceUniqueId::GenerateForRPC(EntityId, static_cast(Type), NewRPCId); - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateSendRPC(LinearTraceId), - /* Causes */ Payload.SpanId.GetConstId(), /* NumCauses */ 1); + FSpatialGDKSpanId SpanId = EventTracer->TraceEvent( + SEND_RPC_EVENT_NAME, "", Payload.SpanId.GetConstId(), /* NumCauses */ 1, + [EntityId, Type, NewRPCId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForRPC(EntityId, static_cast(Type), NewRPCId)); + }); RPCStore.AddSpanIdForComponentUpdate(EntityComponent, SpanId); } @@ -583,8 +590,13 @@ FRPCErrorInfo SpatialRPCService::ApplyRPCInternal(UObject* TargetObject, UFuncti bool bUseEventTracer = EventTracer != nullptr && RPCType != ERPCType::CrossServer; if (bUseEventTracer) { - FSpatialGDKSpanId SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateApplyRPC(TargetObject, Function), - /* Causes */ PendingRPCParams.SpanId.GetConstId(), /* NumCauses */ 1); + FSpatialGDKSpanId SpanId = + EventTracer->TraceEvent(APPLY_RPC_EVENT_NAME, "", PendingRPCParams.SpanId.GetConstId(), /* NumCauses */ 1, + [TargetObject, Function](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(TargetObject); + EventBuilder.AddFunction(Function); + }); + EventTracer->AddToStack(SpanId); } @@ -768,8 +780,11 @@ void SpatialRPCService::ProcessOrQueueOutgoingRPC(const FUnrealObjectRef& InTarg FSpatialGDKSpanId SpanId; if (EventTracer != nullptr) { - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreatePushRPC(TargetObject, Function), - /* Causes */ EventTracer->GetFromStack().GetConstId(), /* NumCauses */ 1); + SpanId = EventTracer->TraceEvent(PUSH_RPC_EVENT_NAME, "", EventTracer->GetFromStack().GetConstId(), /* NumCauses */ 1, + [TargetObject, Function](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(TargetObject); + EventBuilder.AddFunction(Function); + }); } OutgoingRPCs.ProcessOrQueueRPC(InTargetObjectRef, InSenderInfo, RPCInfo.Type, MoveTemp(InPayload), SpanId); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialPlayerSpawner.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialPlayerSpawner.cpp index b0c4647036..c01d254807 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialPlayerSpawner.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialPlayerSpawner.cpp @@ -24,8 +24,6 @@ #include #include -#include "Interop/Connection/SpatialTraceEventBuilder.h" - DEFINE_LOG_CATEGORY(LogSpatialPlayerSpawner); using namespace SpatialGDK; @@ -62,9 +60,12 @@ void USpatialPlayerSpawner::OnPlayerSpawnCommandReceived(const Worker_Op& Op, co SpatialEventTracer* EventTracer = NetDriver->Connection->GetEventTracer(); if (EventTracer != nullptr) { - EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreateReceiveCommandRequest(TEXT("SPAWN_PLAYER_COMMAND"), CommandRequestOp.request_id), - /* Causes */ Op.span_id, /* NumCauses */ 1); + Worker_RequestId RequestId = CommandRequestOp.request_id; + EventTracer->TraceEvent(RECEIVE_COMMAND_REQUEST_EVENT_NAME, "", Op.span_id, /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddCommand("SPAWN_PLAYER_COMMAND"); + EventBuilder.AddRequestId(RequestId); + }); } } @@ -75,10 +76,12 @@ void USpatialPlayerSpawner::OnPlayerSpawnResponseReceived(const Worker_Op& Op, c SpatialEventTracer* EventTracer = NetDriver->Connection->GetEventTracer(); if (EventTracer != nullptr) { - EventTracer->TraceEvent( - FSpatialTraceEventBuilder::CreateReceiveCommandResponse(TEXT("SPAWN_PLAYER_COMMAND"), CommandResponseOp.request_id), - /* Causes */ EventTracer->GetAndConsumeSpanForRequestId(CommandResponseOp.request_id).GetConstId(), - /* NumCauses */ 1); + Worker_RequestId RequestId = CommandResponseOp.request_id; + EventTracer->TraceEvent(RECEIVE_COMMAND_RESPONSE_EVENT_NAME, "", Op.span_id, 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddCommand("SPAWN_PLAYER_COMMAND"); + EventBuilder.AddRequestId(RequestId); + }); } } @@ -89,9 +92,12 @@ void USpatialPlayerSpawner::OnForwardedPlayerSpawnCommandReceived(const Worker_O SpatialEventTracer* EventTracer = NetDriver->Connection->GetEventTracer(); if (EventTracer != nullptr) { - EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateReceiveCommandRequest(TEXT("SERVER_WORKER_FORWARD_SPAWN_REQUEST_COMMAND"), - CommandRequestOp.request_id), - /* Causes */ Op.span_id, /* NumCauses */ 1); + Worker_RequestId RequestId = CommandRequestOp.request_id; + EventTracer->TraceEvent(RECEIVE_COMMAND_REQUEST_EVENT_NAME, "", Op.span_id, /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddCommand("SERVER_WORKER_FORWARD_SPAWN_REQUEST_COMMAND"); + EventBuilder.AddRequestId(RequestId); + }); } } @@ -100,9 +106,12 @@ void USpatialPlayerSpawner::OnForwardedPlayerSpawnResponseReceived(const Worker_ SpatialEventTracer* EventTracer = NetDriver->Connection->GetEventTracer(); if (EventTracer != nullptr) { - EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateReceiveCommandResponse(TEXT("SERVER_WORKER_FORWARD_SPAWN_REQUEST_COMMAND"), - CommandResponseOp.request_id), - /* Causes */ EventTracer->GetAndConsumeSpanForRequestId(CommandResponseOp.request_id).GetConstId(), 1); + Worker_RequestId RequestId = CommandResponseOp.request_id; + EventTracer->TraceEvent(RECEIVE_COMMAND_RESPONSE_EVENT_NAME, "", Op.span_id, /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddCommand("SERVER_WORKER_FORWARD_SPAWN_REQUEST_COMMAND"); + EventBuilder.AddRequestId(RequestId); + }); } ReceiveForwardPlayerSpawnResponse(CommandResponseOp); } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp index 98e5dbae2f..e5a3914d8d 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp @@ -16,7 +16,6 @@ #include "EngineClasses/SpatialPackageMapClient.h" #include "EngineClasses/SpatialVirtualWorkerTranslator.h" #include "Interop/Connection/SpatialEventTracer.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/Connection/SpatialWorkerConnection.h" #include "Interop/GlobalStateManager.h" #include "Interop/SpatialReceiver.h" @@ -97,9 +96,9 @@ void USpatialSender::UpdatePartitionEntityInterestAndPosition() Connection->SendComponentUpdate(PartitionId, &Update); } -void USpatialSender::SendAuthorityIntentUpdate(const AActor& Actor, VirtualWorkerId NewAuthoritativeVirtualWorkerId) const +void USpatialSender::SendAuthorityIntentUpdate(const AActor& InActor, VirtualWorkerId NewAuthoritativeVirtualWorkerId) const { - const Worker_EntityId EntityId = PackageMap->GetEntityIdFromObject(&Actor); + const Worker_EntityId EntityId = PackageMap->GetEntityIdFromObject(&InActor); check(EntityId != SpatialConstants::INVALID_ENTITY_ID); TOptional AuthorityIntentComponent = @@ -110,21 +109,25 @@ void USpatialSender::SendAuthorityIntentUpdate(const AActor& Actor, VirtualWorke /* This seems to occur when using the replication graph, however we're still unsure the cause. */ UE_LOG(LogSpatialSender, Error, TEXT("Attempted to update AuthorityIntent twice to the same value. Actor: %s. Entity ID: %lld. Virtual worker: '%d'"), - *GetNameSafe(&Actor), EntityId, NewAuthoritativeVirtualWorkerId); + *GetNameSafe(&InActor), EntityId, NewAuthoritativeVirtualWorkerId); return; } AuthorityIntentComponent->VirtualWorkerId = NewAuthoritativeVirtualWorkerId; UE_LOG(LogSpatialSender, Log, TEXT("(%s) Sending AuthorityIntent update for entity id %d. Virtual worker '%d' should become authoritative over %s"), - *NetDriver->Connection->GetWorkerId(), EntityId, NewAuthoritativeVirtualWorkerId, *GetNameSafe(&Actor)); + *NetDriver->Connection->GetWorkerId(), EntityId, NewAuthoritativeVirtualWorkerId, *GetNameSafe(&InActor)); FWorkerComponentUpdate Update = AuthorityIntentComponent->CreateAuthorityIntentUpdate(); FSpatialGDKSpanId SpanId; if (EventTracer != nullptr) { - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateAuthorityIntentUpdate(NewAuthoritativeVirtualWorkerId, &Actor)); + SpanId = EventTracer->TraceEvent(AUTHORITY_INTENT_UPDATE_EVENT_NAME, "", /* Causes */ nullptr, /* NumCauses */ 0, + [&InActor, NewAuthoritativeVirtualWorkerId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(&InActor); + EventBuilder.AddWorkerId(NewAuthoritativeVirtualWorkerId, "NewWorkerId"); + }); } Connection->SendComponentUpdate(EntityId, &Update, SpanId); diff --git a/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ReceivedOpEventHandler.cpp b/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ReceivedOpEventHandler.cpp index 08b15b7a7b..47e536eab9 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ReceivedOpEventHandler.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ReceivedOpEventHandler.cpp @@ -2,8 +2,6 @@ #include "SpatialView/ReceivedOpEventHandler.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" - namespace SpatialGDK { FReceivedOpEventHandler::FReceivedOpEventHandler(TSharedPtr EventTracer) diff --git a/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ViewDelta.cpp b/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ViewDelta.cpp index b4b1871579..69bbeb8b9a 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ViewDelta.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/SpatialView/ViewDelta.cpp @@ -2,7 +2,6 @@ #include "SpatialView/ViewDelta.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "SpatialView/EntityComponentTypes.h" #include "Algo/StableSort.h" diff --git a/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp b/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp index c71c0bf531..32d94620e7 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp @@ -10,7 +10,6 @@ #include "EngineClasses/SpatialFastArrayNetSerialize.h" #include "EngineClasses/SpatialNetBitReader.h" #include "Interop/Connection/SpatialEventTracer.h" -#include "Interop/Connection/SpatialTraceEventBuilder.h" #include "Interop/SpatialConditionMapFilter.h" #include "SpatialConstants.h" #include "Utils/GDKPropertyMacros.h" @@ -335,11 +334,16 @@ void ComponentReader::ApplySchemaObject(Schema_Object* ComponentObject, UObject& FSpatialGDKSpanId SpanId; if (bEventTracerEnabled) { - EventTraceUniqueId LinearTraceId = EventTraceUniqueId::GenerateForProperty(EntityId, Cmd.Property); - SpanId = EventTracer->TraceEvent(FSpatialTraceEventBuilder::CreateReceivePropertyUpdate( - &Object, EntityId, ComponentId, Cmd.Property->GetName(), LinearTraceId), - /* Causes */ reinterpret_cast(CauseSpanIds.GetData()), - /* NumCauses */ CauseSpanIds.Num()); + const Trace_SpanIdType* Causes = reinterpret_cast(CauseSpanIds.GetData()); + SpanId = EventTracer->TraceEvent( + RECEIVE_PROPERTY_UPDATE_EVENT_NAME, "", Causes, CauseSpanIds.Num(), + [&Object, EntityId, ComponentId, Cmd](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddObject(&Object); + EventBuilder.AddEntityId(EntityId); + EventBuilder.AddComponentId(ComponentId); + EventBuilder.AddKeyValue("PropertyName", Cmd.Property->GetName()); + EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForProperty(EntityId, Cmd.Property)); + }); } // Parent.Property is the "root" replicated property, e.g. if a struct property was flattened diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h index c4b4acc612..3316ee400c 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h @@ -3,7 +3,7 @@ #pragma once #include "Interop/Connection/SpatialGDKSpanId.h" -#include "Interop/Connection/SpatialTraceEvent.h" +#include "Interop/Connection/SpatialTraceEventDataBuilder.h" #include "Interop/Connection/UserSpanId.h" #include "SpatialCommonTypes.h" #include "SpatialView/EntityComponentId.h" @@ -12,7 +12,6 @@ #include // Documentation for event tracing in the GDK can be found here: https://brevi.link/gdk-event-tracing-documentation - DECLARE_LOG_CATEGORY_EXTERN(LogSpatialEventTracer, Log, All); namespace SpatialGDK @@ -24,11 +23,12 @@ class SPATIALGDK_API SpatialEventTracer explicit SpatialEventTracer(const FString& WorkerId); ~SpatialEventTracer(); - const Trace_EventTracer* GetConstWorkerEventTracer() const { return EventTracer; }; + const Trace_EventTracer* GetConstWorkerEventTracer() const { return EventTracer; } Trace_EventTracer* GetWorkerEventTracer() const { return EventTracer; } - FSpatialGDKSpanId TraceEvent(const FSpatialTraceEvent& SpatialTraceEvent, const Trace_SpanIdType* Causes = nullptr, - int32 NumCauses = 0) const; + template + FSpatialGDKSpanId TraceEvent(const char* EventType, const char* Message, const Trace_SpanIdType* Causes, int32 NumCauses, + T&& DataCallback) const; void BeginOpsForFrame(); void AddEntity(const Worker_AddEntityOp& Op, const FSpatialGDKSpanId& SpanId); @@ -101,4 +101,59 @@ struct SpatialScopedActiveSpanId Trace_EventTracer* EventTracer; }; +template +FSpatialGDKSpanId SpatialEventTracer::TraceEvent(const char* EventType, const char* Message, const Trace_SpanIdType* Causes, + int32 NumCauses, T&& DataCallback) const +{ + if (Causes == nullptr && NumCauses > 0) + { + return {}; + } + + // We could add the data to this event if a custom sampling callback was used. + // This would allow for sampling dependent on trace event data. + Trace_Event Event = { nullptr, 0, Message, EventType, nullptr }; + + Trace_SamplingResult SpanSamplingResult = Trace_EventTracer_ShouldSampleSpan(EventTracer, Causes, NumCauses, &Event); + if (SpanSamplingResult.decision == Trace_SamplingDecision::TRACE_SHOULD_NOT_SAMPLE) + { + return {}; + } + + FSpatialGDKSpanId TraceSpanId; + Trace_EventTracer_AddSpan(EventTracer, Causes, NumCauses, &Event, TraceSpanId.GetId()); + Event.span_id = TraceSpanId.GetConstId(); + + Trace_SamplingResult EventSamplingResult = Trace_EventTracer_ShouldSampleEvent(EventTracer, &Event); + switch (EventSamplingResult.decision) + { + case Trace_SamplingDecision::TRACE_SHOULD_NOT_SAMPLE: + { + return TraceSpanId; + } + case Trace_SamplingDecision::TRACE_SHOULD_SAMPLE_WITHOUT_DATA: + { + Trace_EventTracer_AddEvent(EventTracer, &Event); + return TraceSpanId; + } + case Trace_SamplingDecision::TRACE_SHOULD_SAMPLE: + { + FSpatialTraceEventDataBuilder EventDataBuilder; + + DataCallback(EventDataBuilder); + + // Frame counter + EventDataBuilder.AddKeyValue("FrameNum", GFrameCounter); + + Event.data = EventDataBuilder.GetEventData(); + Trace_EventTracer_AddEvent(EventTracer, &Event); + return TraceSpanId; + } + default: + { + return {}; + } + } +} + } // namespace SpatialGDK diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracerUserInterface.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracerUserInterface.h index bda2c84fe5..51c3562150 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracerUserInterface.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracerUserInterface.h @@ -2,7 +2,8 @@ #pragma once -#include "Interop/Connection/SpatialTraceEvent.h" +#include "Containers/Map.h" +#include "Interop/Connection/SpatialEventTracer.h" #include "Interop/Connection/UserSpanId.h" #include "Kismet/BlueprintFunctionLibrary.h" @@ -10,17 +11,13 @@ #include "SpatialEventTracerUserInterface.generated.h" +class USpatialNetDriver; + DECLARE_DYNAMIC_DELEGATE(FEventTracerRPCDelegate); +DECLARE_DELEGATE_OneParam(FEventTracerAddDataDelegate, SpatialGDK::FSpatialTraceEventDataBuilder&); DECLARE_LOG_CATEGORY_EXTERN(LogSpatialEventTracerUserInterface, Log, All); -namespace SpatialGDK -{ -class SpatialEventTracer; -} - -class USpatialNetDriver; - // Docs on how to use the interface can be found: // https://docs.google.com/document/d/1i0fOdeldqeZ9kgBdmYcTD3fCwYXT9pX1RzpTIupgjcg/edit?usp=sharing @@ -36,15 +33,8 @@ class SPATIALGDK_API USpatialEventTracerUserInterface : public UBlueprintFunctio * (This API is subject to change) */ UFUNCTION(BlueprintCallable, Category = "SpatialOS|EventTracing", meta = (WorldContext = "WorldContextObject")) - static FUserSpanId TraceEvent(UObject* WorldContextObject, const FSpatialTraceEvent& SpatialTraceEvent); - - /** - * EXPERIMENTAL - * Will trace an event using the input data and associate it with the input SpanId - * (This API is subject to change) - */ - UFUNCTION(BlueprintCallable, Category = "SpatialOS|EventTracing", meta = (WorldContext = "WorldContextObject")) - static FUserSpanId TraceEventBasic(UObject* WorldContextObject, FName Type, FString Message, const TArray& Causes); + static FUserSpanId TraceEvent(UObject* WorldContextObject, const FString& EventType, const FString& EventMessage, + const TMap& Data); /** * EXPERIMENTAL @@ -52,8 +42,8 @@ class SPATIALGDK_API USpatialEventTracerUserInterface : public UBlueprintFunctio * (This API is subject to change) */ UFUNCTION(BlueprintCallable, Category = "SpatialOS|EventTracing", meta = (WorldContext = "WorldContextObject")) - static FUserSpanId TraceEventWithCauses(UObject* WorldContextObject, const FSpatialTraceEvent& SpatialTraceEvent, - const TArray& Causes); + static FUserSpanId TraceEventWithCauses(UObject* WorldContextObject, const FString& EventType, const FString& EventMessage, + const TMap& Data, const TArray& Causes); /** * EXPERIMENTAL @@ -81,6 +71,24 @@ class SPATIALGDK_API USpatialEventTracerUserInterface : public UBlueprintFunctio UFUNCTION(BlueprintCallable, Category = "SpatialOS|EventTracing", meta = (WorldContext = "WorldContextObject")) static bool GetActiveSpanId(UObject* WorldContextObject, FUserSpanId& OutUserSpanId); + // ----- C++ Specific API ----- + + /** + * EXPERIMENTAL + * Will trace an event using the input data and associate it with the input SpanId + * (This API is subject to change) + */ + static FUserSpanId TraceEvent(UObject* WorldContextObject, const char* EventType, const char* EventMessage, + FEventTracerAddDataDelegate AddDataDelegate = {}); + + /** + * EXPERIMENTAL + * Will trace an event using the input data and associate it with the input SpanId + * (This API is subject to change) + */ + static FUserSpanId TraceEventWithCauses(UObject* WorldContextObject, const char* EventType, const char* EventMessage, + const TArray& Causes, FEventTracerAddDataDelegate AddDataDelegate = {}); + private: static SpatialGDK::SpatialEventTracer* GetEventTracer(UObject* WorldContextObject); static USpatialNetDriver* GetSpatialNetDriver(UObject* WorldContextObject); diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEvent.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEvent.h deleted file mode 100644 index 06932b4fa1..0000000000 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEvent.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Improbable Worlds Ltd, All Rights Reserved - -#pragma once - -#include "CoreMinimal.h" - -#include "SpatialTraceEvent.generated.h" - -USTRUCT(Blueprintable) -struct FTraceData -{ - GENERATED_BODY() - - FTraceData(){}; - explicit FTraceData(FString InKey, FString InValue) - : Key(MoveTemp(InKey)) - , Value(MoveTemp(InValue)) - { - } - - UPROPERTY(BlueprintReadWrite, Category = "TraceData") - FString Key; - - UPROPERTY(BlueprintReadWrite, Category = "TraceData") - FString Value; -}; - -USTRUCT(Blueprintable) -struct FSpatialTraceEvent -{ - GENERATED_BODY() - - FSpatialTraceEvent(){}; - explicit FSpatialTraceEvent(FName InType, FString InMessage) - : Type(MoveTemp(InType)) - , Message(MoveTemp(InMessage)) - { - } - - void AddData(FString Key, FString Value) { Data.Add(FTraceData(MoveTemp(Key), MoveTemp(Value))); } - - UPROPERTY(BlueprintReadWrite, Category = "SpatialTraceEvent") - FName Type; - - UPROPERTY(BlueprintReadWrite, Category = "SpatialTraceEvent") - FString Message; - - UPROPERTY(BlueprintReadWrite, Category = "SpatialTraceEvent") - TArray Data; -}; diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventBuilder.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventBuilder.h deleted file mode 100644 index 8cbdf05469..0000000000 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventBuilder.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) Improbable Worlds Ltd, All Rights Reserved - -#pragma once - -#include "Interop/Connection/SpatialTraceEvent.h" -#include "Interop/Connection/SpatialTraceUniqueId.h" -#include "SpatialCommonTypes.h" -#include "WorkerSDK/improbable/c_worker.h" - -#define GDK_EVENT_NAMESPACE "unreal_gdk." - -namespace SpatialGDK -{ -class SPATIALGDK_API FSpatialTraceEventBuilder -{ -public: - FSpatialTraceEventBuilder(FName InType); - FSpatialTraceEventBuilder(FName InType, FString InMessage); - - FSpatialTraceEventBuilder AddObject(FString Key, const UObject* Object); - FSpatialTraceEventBuilder AddFunction(FString Key, const UFunction* Function); - FSpatialTraceEventBuilder AddEntityId(FString Key, const Worker_EntityId EntityId); - FSpatialTraceEventBuilder AddComponentId(FString Key, const Worker_ComponentId ComponentId); - FSpatialTraceEventBuilder AddFieldId(FString Key, const uint32 FieldId); - FSpatialTraceEventBuilder AddNewWorkerId(FString Key, const uint32 NewWorkerId); - FSpatialTraceEventBuilder AddCommand(FString Key, const FString& Command); - FSpatialTraceEventBuilder AddRequestId(FString Key, const int64 RequestId); - FSpatialTraceEventBuilder AddAuthority(FString Key, const Worker_Authority Role); - FSpatialTraceEventBuilder AddKeyValue(FString Key, FString Value); - FSpatialTraceEvent GetEvent() &&; - - static FSpatialTraceEvent CreateReceiveRPC(const EventTraceUniqueId& LinearTraceId); - static FSpatialTraceEvent CreateApplyRPC(const UObject* Object, UFunction* Function); - static FSpatialTraceEvent CreatePushRPC(const UObject* Object, UFunction* Function); - static FSpatialTraceEvent CreateSendRPC(const EventTraceUniqueId& LinearTraceId); - - static FSpatialTraceEvent CreateSendCrossServerRPC(const UObject* Object, UFunction* Function, const EventTraceUniqueId& LinearTraceId); - static FSpatialTraceEvent CreateReceiveCrossServerRPC(const EventTraceUniqueId& LinearTraceId); - static FSpatialTraceEvent CreateApplyCrossServerRPC(const UObject* Object, UFunction* Function); - - static FSpatialTraceEvent CreateQueueRPC(); - static FSpatialTraceEvent CreateRetryRPC(); - static FSpatialTraceEvent CreatePropertyChanged(const UObject* Object, const Worker_EntityId EntityId, const FString& PropertyName, - EventTraceUniqueId LinearTraceId); - static FSpatialTraceEvent CreateSendPropertyUpdate(const UObject* Object, const Worker_EntityId EntityId, - const Worker_ComponentId ComponentId); - static FSpatialTraceEvent CreateReceivePropertyUpdate(const UObject* Object, const Worker_EntityId EntityId, - const Worker_ComponentId ComponentId, const FString& PropertyName, - EventTraceUniqueId LinearTraceId); - static FSpatialTraceEvent CreateMergeSendRPCs(const Worker_EntityId EntityId, const Worker_ComponentId ComponentId); - static FSpatialTraceEvent CreateObjectPropertyComponentUpdate(const UObject* Object); - static FSpatialTraceEvent CreateSendCommandRequest(const FString& Command, const int64 RequestId); - static FSpatialTraceEvent CreateReceiveCommandRequest(const FString& Command, const int64 RequestId); - static FSpatialTraceEvent CreateReceiveCommandRequest(const FString& Command, const UObject* Actor, const UObject* TargetObject, - const UFunction* Function, const int32 TraceId, const int64 RequestId); - static FSpatialTraceEvent CreateSendCommandResponse(const int64 RequestId, const bool bSuccess); - static FSpatialTraceEvent CreateReceiveCommandResponse(const FString& Command, const int64 RequestId); - static FSpatialTraceEvent CreateReceiveCommandResponse(const UObject* Actor, const int64 RequestId, const bool bSuccess); - static FSpatialTraceEvent CreateReceiveCommandResponse(const UObject* Actor, const UObject* TargetObject, const UFunction* Function, - int64 RequestId, const bool bSuccess); - static FSpatialTraceEvent CreateSendRemoveEntity(const UObject* Object, const Worker_EntityId EntityId); - static FSpatialTraceEvent CreateReceiveRemoveEntity(const Worker_EntityId EntityId); - static FSpatialTraceEvent CreateSendCreateEntity(const UObject* Object, const Worker_EntityId EntityId); - static FSpatialTraceEvent CreateReceiveCreateEntity(const Worker_EntityId EntityId); - static FSpatialTraceEvent CreateReceiveCreateEntitySuccess(const UObject* Object, const Worker_EntityId EntityId); - static FSpatialTraceEvent CreateSendRetireEntity(const UObject* Object, const Worker_EntityId EntityId); - static FSpatialTraceEvent CreateAuthorityIntentUpdate(VirtualWorkerId WorkerId, const UObject* Object); - static FSpatialTraceEvent CreateAuthorityChange(const Worker_EntityId EntityId, const Worker_ComponentId ComponentId, - const Worker_Authority Authority); - static FSpatialTraceEvent CreateComponentUpdate(const UObject* Object, const UObject* TargetObject, const Worker_EntityId EntityId, - const Worker_ComponentId ComponentId); - static FSpatialTraceEvent CreateGenericMessage(FString Message); - -private: - static FString AuthorityToString(Worker_Authority Authority); - static FString BoolToString(bool bInput); - - FSpatialTraceEvent SpatialTraceEvent; -}; -} // namespace SpatialGDK diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h new file mode 100644 index 0000000000..d3e71e5cf5 --- /dev/null +++ b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h @@ -0,0 +1,128 @@ +// Copyright (c) Improbable Worlds Ltd, All Rights Reserved + +#pragma once + +#include "Interop/Connection/SpatialTraceUniqueId.h" +#include "SpatialCommonTypes.h" +#include +#include + +#define GDK_EVENT_NAMESPACE "unreal_gdk." + +#define PUSH_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "push_rpc" +#define COMPONENT_UPDATE_EVENT_NAME GDK_EVENT_NAMESPACE "component_update" +#define SEND_RETIRE_ENTITY_EVENT_NAME GDK_EVENT_NAMESPACE "send_retire_entity" +#define PROPERTY_CHANGED_EVENT_NAME GDK_EVENT_NAMESPACE "property_changed" +#define SEND_PROPERTY_UPDATE_EVENT_NAME GDK_EVENT_NAMESPACE "send_property_update" +#define SEND_CREATE_ENTITY_EVENT_NAME GDK_EVENT_NAMESPACE "send_create_entity" +#define RECEIVE_CREATE_ENTITY_SUCCESS_EVENT_NAME GDK_EVENT_NAMESPACE "receive_create_entity_success" +#define RECEIVE_PROPERTY_UPDATE_EVENT_NAME GDK_EVENT_NAMESPACE "receive_property_update" +#define AUTHORITY_INTENT_UPDATE_EVENT_NAME GDK_EVENT_NAMESPACE "authority_intent_update" +#define RECEIVE_COMMAND_RESPONSE_EVENT_NAME GDK_EVENT_NAMESPACE "receive_command_response" +#define RECEIVE_COMMAND_REQUEST_EVENT_NAME GDK_EVENT_NAMESPACE "receive_command_request" +#define APPLY_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "apply_rpc" +#define SEND_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "send_rpc" +#define QUEUE_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "queue_rpc" +#define RECEIVE_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "receive_rpc" +#define MERGE_SEND_RPCS_EVENT_NAME GDK_EVENT_NAMESPACE "merge_send_rpcs" +#define APPLY_CROSS_SERVER_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "apply_cross_server_rpc" +#define SEND_COMMAND_RESPONSE_EVENT_NAME GDK_EVENT_NAMESPACE "send_command_response" +#define SEND_COMMAND_REQEUST_EVENT_NAME GDK_EVENT_NAMESPACE "send_command_request" +#define SEND_CROSS_SERVER_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "send_cross_server_rpc" +#define MERGE_PROPERTY_EVENT_NAME GDK_EVENT_NAMESPACE "merge_property_update" +#define RECEIVE_CREATE_ENTITY_EVENT_NAME GDK_EVENT_NAMESPACE "receive_create_entity" +#define SEND_COMMAND_REQUEST_EVENT_NAME GDK_EVENT_NAMESPACE "send_command_request" +#define RECEIVE_REMOVE_ENTITY_EVENT_NAME GDK_EVENT_NAMESPACE "receive_remove_entity" +#define AUTHORITY_CHANGE_EVENT_NAME GDK_EVENT_NAMESPACE "authority_change" +#define RECEIVE_CROSS_SERVER_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "receive_cross_server_rpc" +#define MERGE_SEND_RPC_EVENT_NAME GDK_EVENT_NAMESPACE "merge_send_rpcs" +#define MERGE_PROPERTY_UPDATE_EVENT_NAME GDK_EVENT_NAMESPACE "merge_property_update" + +DECLARE_LOG_CATEGORY_EXTERN(FSpatialTraceEventDataBuilderLog, Log, All); + +namespace worker +{ +namespace c +{ +struct Trace_EventData; +} +} // namespace worker + +namespace SpatialGDK +{ +class SPATIALGDK_API FSpatialTraceEventDataBuilder +{ +public: + class SPATIALGDK_API FStringCache + { + public: + int32 CombineStrings(const char* A, const char* B); + + int32 AddString(const char* String); + int32 AddFString(const FString& String); + int32 AddUInt32(uint32 Value); + int32 AddUInt64(uint64 Value); + int32 AddInt32(int32 Value); + int32 AddInt64(int64 Value); + + const char* Get(int32 Handle) const; + int32 GetBufferSize() const { return BufferSize; } + + private: + static constexpr int32 BufferSize = 1000; + char Buffer[BufferSize]; + int32 NextIndex = 0; + + template + int32 AddInteger(IntegerType Integer, const FmtType& Fmt) + { + if (NextIndex >= BufferSize) + { + return BufferSize - 1; + } + + int32 InsertIndex = NextIndex; + int32 RemainingSize = BufferSize - NextIndex; + int32 CharSize = sizeof(char); + int32 BytesWritten = CharSize * (FCStringAnsi::Snprintf(&Buffer[NextIndex], RemainingSize, Fmt, Integer) + 1); + NextIndex += BytesWritten; + return InsertIndex; + } + }; + + FSpatialTraceEventDataBuilder(); + ~FSpatialTraceEventDataBuilder(); + + void AddObject(const UObject* Object, const char* Key = "Object"); + void AddFunction(const UFunction* Function, const char* Key = "Function"); + void AddEntityId(const Worker_EntityId EntityId, const char* Key = "EntityId"); + void AddComponentId(const Worker_ComponentId ComponentId, const char* Key = "ComponentId"); + void AddComponentSetId(const Worker_ComponentSetId ComponentId, const char* Key = "ComponentSetId"); + void AddFieldId(const uint32 FieldId, const char* Key = "FieldId"); + void AddWorkerId(const uint32 WorkerId, const char* Key = "WorkerId"); + void AddCommand(const char* Command, const char* Key = "Command"); + void AddRequestId(const int64 RequestId, const char* Key = "RequestId"); + void AddAuthority(const Worker_Authority Authority, const char* Key = "Authority"); + void AddLinearTraceId(const EventTraceUniqueId LinearTraceId, const char* Key = "LinearTraceId"); + + void AddKeyValue(const char* Key, const char* Value); + void AddKeyValue(const char* Key, const FString& Value); + void AddKeyValue(const FString& Key, const FString& Value); + void AddKeyValue(const char* Key, const uint32 Value); + void AddKeyValue(const char* Key, const uint64 Value); + void AddKeyValue(const char* Key, const int32 Value); + void AddKeyValue(const char* Key, const int64 Value); + void AddKeyValue(const char* Key, const bool bValue); + + const Trace_EventData* GetEventData() { return EventData; }; + +private: + Trace_EventData* EventData; + FStringCache StringConverter; + + void AddKeyValue(int32 KeyHandle, int32 ValueHandle); + + static const char* AuthorityToString(Worker_Authority Authority); +}; + +} // namespace SpatialGDK diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceUniqueId.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceUniqueId.h index ece40bbec0..70a8fbcb04 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceUniqueId.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceUniqueId.h @@ -22,6 +22,7 @@ class EventTraceUniqueId public: FString ToString() const; + uint32 Get() const { return Hash; }; bool IsValid() const { return Hash != 0; } diff --git a/SpatialGDK/Source/SpatialGDKEditor/Private/SnapshotGenerator/SpatialGDKEditorSnapshotGenerator.cpp b/SpatialGDK/Source/SpatialGDKEditor/Private/SnapshotGenerator/SpatialGDKEditorSnapshotGenerator.cpp index e6291cd7e6..b0065d5b84 100644 --- a/SpatialGDK/Source/SpatialGDKEditor/Private/SnapshotGenerator/SpatialGDKEditorSnapshotGenerator.cpp +++ b/SpatialGDK/Source/SpatialGDKEditor/Private/SnapshotGenerator/SpatialGDKEditorSnapshotGenerator.cpp @@ -353,7 +353,7 @@ bool FillSnapshot(Worker_SnapshotOutputStream* OutputStream, UWorld* World) UTF8_TO_TCHAR(Worker_SnapshotOutputStream_GetState(OutputStream).error_message)); return false; } - + if (!CreateRoutingWorkerPartitionEntity(OutputStream)) { UE_LOG(LogSpatialGDKSnapshot, Error, TEXT("Error generating RoutingPartitionEntity in snapshot: %s"), diff --git a/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/RelevancyTest/RelevancyTest.cpp b/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/RelevancyTest/RelevancyTest.cpp index a7d65ee214..8d59b9b518 100644 --- a/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/RelevancyTest/RelevancyTest.cpp +++ b/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/RelevancyTest/RelevancyTest.cpp @@ -164,7 +164,8 @@ void ARelevancyTest::PrepareTest() RequireEqual_Int(NumOnlyRelevantToOwnerActors, 0, TEXT("Non-owning client sees expected number of only relevant to owner actors")); - RequireEqual_Int(NumUseOwnerRelevancyActors, 0, TEXT("Non-owning client sees expected number of use owner relevancy actors")); + RequireEqual_Int(NumUseOwnerRelevancyActors, 0, + TEXT("Non-owning client sees expected number of use owner relevancy actors")); FinishStep(); // This will only actually finish if requires are satisfied }, StepTimeLimit); diff --git a/SpatialGDK/Source/SpatialGDKTests/SpatialGDK/Interop/Connection/SpatialEventTracingTest.cpp b/SpatialGDK/Source/SpatialGDKTests/SpatialGDK/Interop/Connection/SpatialEventTracingTest.cpp new file mode 100644 index 0000000000..93ae01cee9 --- /dev/null +++ b/SpatialGDK/Source/SpatialGDKTests/SpatialGDK/Interop/Connection/SpatialEventTracingTest.cpp @@ -0,0 +1,186 @@ +// Copyright (c) Improbable Worlds Ltd, All Rights Reserved + +#include "SpatialGDKTests/Public/GDKAutomationTestBase.h" +#include "Tests/TestDefinitions.h" + +#include "Interop/Connection/SpatialTraceEventDataBuilder.h" + +#include "CoreMinimal.h" +#include "Engine/Engine.h" + +#include + +#define EVENTTRACING_TEST(TestName) GDK_AUTOMATION_TEST(Core, EventTracingTests, TestName) + +using namespace SpatialGDK; + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_combing_two_string_THEN_the_strings_are_combined_and_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.CombineStrings("string1", "string2"); + bool bSuccess = FCStringAnsi::Strcmp("string1string2", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST( + GIVEN_a_string_cache_WHEN_combing_two_string_that_will_overflow_but_cant_combine_THEN_the_strings_are_combined_and_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + + FString InputString; + for (int32 i = 0; i < StringCache.GetBufferSize() - 1; ++i) + { + InputString += "a"; + } + + std::string InputSrc = (const char*)TCHAR_TO_ANSI(*InputString); + const int32 Handle = StringCache.CombineStrings(InputSrc.c_str(), "string2"); + bool bSuccess = FCStringAnsi::Strcmp(InputSrc.c_str(), StringCache.Get(Handle)) == 0; + + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST( + GIVEN_a_string_cache_WHEN_combing_two_string_that_will_overflow_but_can_partially_combine_THEN_the_strings_are_combined_and_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + + FString InputString; + for (int32 i = 0; i < StringCache.GetBufferSize() - 2; ++i) + { + InputString += "a"; + } + + FString OutputString = InputString + "s"; + + const int32 Handle = StringCache.CombineStrings(TCHAR_TO_ANSI(*InputString), "string2"); + bool bSuccess = FCStringAnsi::Strcmp(TCHAR_TO_ANSI(*OutputString), StringCache.Get(Handle)) == 0; + + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_a_string_THEN_the_string_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.AddString("string1"); + bool bSuccess = FCStringAnsi::Strcmp("string1", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_an_fstring_THEN_the_string_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.AddFString(TEXT("string1")); + bool bSuccess = FCStringAnsi::Strcmp("string1", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_a_uint32_THEN_the_string_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.AddUInt32(101); + bool bSuccess = FCStringAnsi::Strcmp("101", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_a_uint64_THEN_the_string_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.AddUInt64(101); + bool bSuccess = FCStringAnsi::Strcmp("101", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_a_int32_THEN_the_string_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.AddInt32(101); + bool bSuccess = FCStringAnsi::Strcmp("101", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_a_int64_THEN_the_string_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle = StringCache.AddInt64(101); + bool bSuccess = FCStringAnsi::Strcmp("101", StringCache.Get(Handle)) == 0; + TestTrue("String succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_multiple_strings_THEN_the_strings_is_stored_correctly) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 Handle1 = StringCache.CombineStrings("string1", "string2"); + const int32 Handle2 = StringCache.AddString("string1"); + const int32 Handle3 = StringCache.AddFString(TEXT("string1")); + const int32 Handle4 = StringCache.AddUInt32(101); + const int32 Handle5 = StringCache.AddUInt64(101); + const int32 Handle6 = StringCache.AddInt32(101); + const int32 Handle7 = StringCache.AddInt64(101); + bool bSuccess = FCStringAnsi::Strcmp("string1string2", StringCache.Get(Handle1)) == 0; + bSuccess &= FCStringAnsi::Strcmp("string1", StringCache.Get(Handle2)) == 0; + bSuccess &= FCStringAnsi::Strcmp("string1", StringCache.Get(Handle3)) == 0; + bSuccess &= FCStringAnsi::Strcmp("101", StringCache.Get(Handle4)) == 0; + bSuccess &= FCStringAnsi::Strcmp("101", StringCache.Get(Handle5)) == 0; + bSuccess &= FCStringAnsi::Strcmp("101", StringCache.Get(Handle6)) == 0; + bSuccess &= FCStringAnsi::Strcmp("101", StringCache.Get(Handle7)) == 0; + TestTrue("Strings succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_WHEN_adding_string_that_overflows_THEN_the_output_string_is_truncated_to_buffer_size) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 CacheBufferSize = StringCache.GetBufferSize(); + + FString InputString; + for (int32 i = 0; i < 2 * CacheBufferSize; ++i) + { + InputString += "a"; + } + + const int32 Handle = StringCache.AddFString(InputString); + const char* OutputString = StringCache.Get(Handle); + + const int32 StringLength = strlen(OutputString); + bool bSuccess = StringLength == CacheBufferSize - 1; + + TestTrue("Strings succesfully stored and retreived", bSuccess); + return true; +} + +EVENTTRACING_TEST(GIVEN_a_string_cache_that_is_full_WHEN_adding_string_THEN_the_output_string_empty) +{ + FSpatialTraceEventDataBuilder::FStringCache StringCache; + const int32 CacheBufferSize = StringCache.GetBufferSize(); + + FString InputString; + for (int32 i = 0; i < 2 * CacheBufferSize; ++i) + { + InputString += "a"; + } + + FString TestString; + for (int32 i = 0; i < StringCache.GetBufferSize() - 1; ++i) + { + TestString += "a"; + } + + const int32 Handle1 = StringCache.AddFString(InputString); + const int32 Handle2 = StringCache.AddString("string1"); + + bool bSuccess = FCStringAnsi::Strcmp(TCHAR_TO_ANSI(*TestString), StringCache.Get(Handle1)) == 0; + bSuccess &= FCStringAnsi::Strcmp("", StringCache.Get(Handle2)) == 0; + + TestTrue("Strings succesfully stored and retreived", bSuccess); + return true; +} From 728efe1cb16ea10e61808201b70083b2dade9286 Mon Sep 17 00:00:00 2001 From: Danny Birch Date: Thu, 27 May 2021 18:09:31 +0100 Subject: [PATCH 08/14] Update CHANGELOG.md (#3151) --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b258e648b..868d0ae89b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,7 +69,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bug where on initial replication, actors with replicated TArrays would not have the array cleared if the local state was not empty. - Fixed an issue with replicating references to stably named dynamically added subobjects of dynamic actors. - Fixed an issue during client logout where a client's corresponding Actors were not cleaned up correctly. -- Reverted a fix relating to the `dbghelp` file that previously caused the Editor to crash when loading the Session Front End. Our fix is no longer necessary, as Epic have fixed the issue and we've adopted their fix. - Fixed issue with `SpatialDebugger` crashing when client travelling. ## [`0.12.0`] - 2021-02-01 From b88f4429e6a737e9abc024f3de168d75ca2c4cee Mon Sep 17 00:00:00 2001 From: martin-improbable Date: Mon, 17 May 2021 16:21:56 +0100 Subject: [PATCH 09/14] [UNR-5544] Calculate and cache worker id as hash in game instance Calculate and cache worker id as hash (using crc32) in game instance. --- .../SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp | 2 +- SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp index 9b9c7ab260..2ec043d526 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp @@ -244,7 +244,7 @@ void USpatialGameInstance::Init() void USpatialGameInstance::HandleOnConnected(USpatialNetDriver& NetDriver) { UE_LOG(LogSpatialGameInstance, Log, TEXT("Successfully connected to SpatialOS")); - SpatialWorkerId = SpatialConnectionManager->GetWorkerConnection()->GetWorkerId(); + SetSpatialWorkerId(SpatialConnectionManager->GetWorkerConnection()->GetWorkerId()); #if TRACE_LIB_ACTIVE SpatialLatencyTracer->SetWorkerId(SpatialWorkerId); diff --git a/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h b/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h index f6a7649a28..105ecb19d4 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Utils/EngineVersionCheck.h @@ -7,7 +7,7 @@ // GDK Version to be updated with SPATIAL_ENGINE_VERSION // when breaking changes are made to the engine that requires // changes to the GDK to remain compatible -#define SPATIAL_GDK_VERSION 37 +#define SPATIAL_GDK_VERSION 39 // Check if GDK is compatible with the current version of Unreal Engine // SPATIAL_ENGINE_VERSION is incremented in engine when breaking changes From 7e41b686b378ece017ffe400a8ac062cbe6f5880 Mon Sep 17 00:00:00 2001 From: Jay Lauffer Date: Tue, 18 May 2021 15:13:15 +0800 Subject: [PATCH 10/14] Use member function to get worker id. (#3128) --- .../SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp index 2ec043d526..e0e3945f7f 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialGameInstance.cpp @@ -246,7 +246,7 @@ void USpatialGameInstance::HandleOnConnected(USpatialNetDriver& NetDriver) UE_LOG(LogSpatialGameInstance, Log, TEXT("Successfully connected to SpatialOS")); SetSpatialWorkerId(SpatialConnectionManager->GetWorkerConnection()->GetWorkerId()); #if TRACE_LIB_ACTIVE - SpatialLatencyTracer->SetWorkerId(SpatialWorkerId); + SpatialLatencyTracer->SetWorkerId(GetSpatialWorkerId()); USpatialWorkerConnection* WorkerConnection = SpatialConnectionManager->GetWorkerConnection(); WorkerConnection->OnEnqueueMessage.AddUObject(SpatialLatencyTracer, &USpatialLatencyTracer::OnEnqueueMessage); From 428511c392f22b6c10e908a97cb70702a2e894a9 Mon Sep 17 00:00:00 2001 From: martin-improbable Date: Tue, 25 May 2021 15:17:06 +0100 Subject: [PATCH 11/14] Added Visual Logger multi-worker support to Changelog (#3144) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 868d0ae89b..03bf8bbda0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [`x.y.z`] - Unreleased ## [`0.13.1`] - 2021-05-21 +### Features: - Added `SpatialExecServerCmd` console command with one command `StartInsights` to dynamically enable insights capturing. - Format: SpatialExecServerCmd < server > < command > < args > - Example usage: "SpatialExecServerCmd local StartInsights -trace=CustomChannel -tracefile=MyNewTrace" +- Visual Logger now supports multi-worker environments. ## [`0.13.0`] - 2021-05-17 ### Breaking changes: From 07a2251074bd116e0f340984b6188ac1310aa84c Mon Sep 17 00:00:00 2001 From: Danny Birch Date: Fri, 28 May 2021 11:28:43 +0100 Subject: [PATCH 12/14] ET debugger v2 (#3143) --- CHANGELOG.md | 6 + SetupIncTraceLibs.bat | 4 +- SpatialGDK/Extras/core-sdk.version | 2 +- .../Private/Interop/ActorSystem.cpp | 4 +- .../Interop/Connection/SpatialEventTracer.cpp | 126 +++++++++++++----- .../SpatialEventTracerUserInterface.cpp | 1 - .../SpatialTraceEventDataBuilder.cpp | 36 ++--- .../Private/Interop/DebugMetricsSystem.cpp | 10 +- .../Interop/MigrationDiagnosticsSystem.cpp | 2 +- .../Private/Interop/RPCExecutor.cpp | 4 +- .../Private/Interop/SpatialSender.cpp | 2 +- .../SpatialGDK/Private/SpatialGDKSettings.cpp | 39 +++++- .../Private/Utils/ComponentReader.cpp | 2 +- .../Interop/Connection/SpatialEventTracer.h | 55 ++++---- .../Connection/SpatialTraceEventDataBuilder.h | 22 +-- .../SpatialGDK/Public/SpatialGDKSettings.h | 43 +++++- .../Public/Utils/WorkerVersionCheck.h | 2 +- ...SpatialGDKDefaultLaunchConfigGenerator.cpp | 32 +++++ .../EventTracingTests/EventTracingTest.cpp | 15 ++- .../Private/LocalDeploymentManager.cpp | 22 ++- .../Public/SpatialGDKServicesConstants.h | 4 +- 21 files changed, 305 insertions(+), 128 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03bf8bbda0..0b269e9674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [`x.y.z`] - Unreleased ## [`0.13.1`] - 2021-05-21 +### Breaking changes: +- Event tracing has been optimised to reduce overhead when tracing events in general and in particular when events are not sampled. The tracing API has been modified to accomidate these improvements. You will have to modify your project if you use the API. + ### Features: - Added `SpatialExecServerCmd` console command with one command `StartInsights` to dynamically enable insights capturing. - Format: SpatialExecServerCmd < server > < command > < args > - Example usage: "SpatialExecServerCmd local StartInsights -trace=CustomChannel -tracefile=MyNewTrace" - Visual Logger now supports multi-worker environments. +- The Unreal GDK has been updated to run against SpatialOS 15.1.0, older version of SpatialOS will no longer work with the Unreal GDK. +- Event tracing rotating log support (via `bEnableEventTracingRotatingLogs`, `EventTracingRotatingLogsMaxFileSizeBytes` and `EventTracingRotatingLogsMaxFileCount`). +- Event tracing filter support (configured via `UEventTracingSamplingSettings`). ## [`0.13.0`] - 2021-05-17 ### Breaking changes: diff --git a/SetupIncTraceLibs.bat b/SetupIncTraceLibs.bat index 6b0fe9eb8a..d498fa66f8 100644 --- a/SetupIncTraceLibs.bat +++ b/SetupIncTraceLibs.bat @@ -18,8 +18,8 @@ call :MarkStartOfBlock "Create folders" call :MarkEndOfBlock "Create folders" call :MarkStartOfBlock "Retrieve dependencies" - spatial package retrieve internal trace-dynamic-x86_64-vc141_md-win32 %PINNED_CORE_SDK_VERSION% "%CORE_SDK_DIR%\trace_lib\trace-win32.zip" - spatial package retrieve internal trace-dynamic-x86_64-clang1000-linux %PINNED_CORE_SDK_VERSION% "%CORE_SDK_DIR%\trace_lib\trace-linux.zip" + spatial package retrieve internal trace-dynamic-x86_64-vc141_md-win32 15.0.1 "%CORE_SDK_DIR%\trace_lib\trace-win32.zip" + spatial package retrieve internal trace-dynamic-x86_64-clang1000-linux 15.0.1 "%CORE_SDK_DIR%\trace_lib\trace-linux.zip" call :MarkEndOfBlock "Retrieve dependencies" REM There is a race condition between retrieve and unzip, add version call to stall briefly diff --git a/SpatialGDK/Extras/core-sdk.version b/SpatialGDK/Extras/core-sdk.version index 4d0d4de516..de7fd55182 100644 --- a/SpatialGDK/Extras/core-sdk.version +++ b/SpatialGDK/Extras/core-sdk.version @@ -1,2 +1,2 @@ -15.0.1 +15.1.0 // If changing version, update SpatialGDK/Source/SpatialGDK/Public/Utils/WorkerVersionCheck.h too diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp index e32b82ec42..9d8b26c927 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/ActorSystem.cpp @@ -573,7 +573,7 @@ void ActorSystem::ComponentUpdated(const Worker_EntityId EntityId, const Worker_ EventTracer->TraceEvent(COMPONENT_UPDATE_EVENT_NAME, "", Causes, CauseSpanIds.Num(), [Object, TargetObject, EntityId, ComponentId](FSpatialTraceEventDataBuilder& EventBuilder) { EventBuilder.AddObject(Object); - EventBuilder.AddObject(TargetObject, "TargetObject"); + EventBuilder.AddObject(TargetObject, "target_object"); EventBuilder.AddEntityId(EntityId); EventBuilder.AddComponentId(ComponentId); }); @@ -1838,7 +1838,7 @@ void ActorSystem::SendComponentUpdates(UObject* Object, const FClassInfo& Info, GDK_PROPERTY(Property)* Property = *Itr; EventBuilder.AddObject(Object); EventBuilder.AddEntityId(EntityId); - EventBuilder.AddKeyValue("PropertyName", Property->GetName()); + EventBuilder.AddKeyValue("property_name", Property->GetName()); EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForProperty(EntityId, Property)); }); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp index fe69f19ae7..5e5ee83dd8 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracer.cpp @@ -2,8 +2,6 @@ #include "Interop/Connection/SpatialEventTracer.h" -#include - #include "HAL/PlatformFile.h" #include "HAL/PlatformFilemanager.h" #include "SpatialGDKSettings.h" @@ -12,6 +10,25 @@ DEFINE_LOG_CATEGORY(LogSpatialEventTracer); namespace SpatialGDK { +TraceQueryPtr ParseOrDefault(const FString& Str, const TCHAR* FilterForLog) +{ + TraceQueryPtr Ptr; + if (Str.Len() > 0) + { + Ptr.Reset(Trace_ParseSimpleQuery(TCHAR_TO_ANSI(*Str))); + UE_LOG(LogSpatialEventTracer, Log, TEXT("Applied %s query: %s"), FilterForLog, *Str); + } + + if (!Ptr.IsValid()) + { + UE_LOG(LogSpatialEventTracer, Warning, TEXT("The specified query \"%s\" is invalid; defaulting to \"false\" query. %s"), + FilterForLog, Trace_GetLastError()); + Ptr.Reset(Trace_ParseSimpleQuery("false")); + } + + return Ptr; +} + void SpatialEventTracer::TraceCallback(void* UserData, const Trace_Item* Item) { SpatialEventTracer* EventTracer = static_cast(UserData); @@ -23,27 +40,34 @@ void SpatialEventTracer::TraceCallback(void* UserData, const Trace_Item* Item) } uint32_t ItemSize = Trace_GetSerializedItemSize(Item); - if (EventTracer->BytesWrittenToStream + ItemSize <= EventTracer->MaxFileSize) + // Depends whether we are using rotating logs or single-log mode (where we track max size). + const bool bTrackFileSize = EventTracer->MaxFileSize != 0; + if (!bTrackFileSize || (EventTracer->BytesWrittenToStream + ItemSize <= EventTracer->MaxFileSize)) { - EventTracer->BytesWrittenToStream += ItemSize; + if (bTrackFileSize) + { + EventTracer->BytesWrittenToStream += ItemSize; + } + int Code = Trace_SerializeItemToStream(Stream, Item, ItemSize); - if (Code != 1) + if (Code == WORKER_RESULT_FAILURE) { - UE_LOG(LogSpatialEventTracer, Error, TEXT("Failed to serialize to with error code %d (%s)"), Code, Trace_GetLastError()); + UE_LOG(LogSpatialEventTracer, Error, TEXT("Failed to serialize to with error code %d (%s)"), Code, + ANSI_TO_TCHAR(Trace_GetLastError())); } if (FPlatformAtomics::AtomicRead_Relaxed(&EventTracer->FlushOnWriteAtomic)) { - int64_t Flushresult = Io_Stream_Flush(Stream); - if (Flushresult == -1) + if (Io_Stream_Flush(Stream) == -1) { UE_LOG(LogSpatialEventTracer, Error, TEXT("Failed to flush stream with error code %d (%s)"), Code, - Io_Stream_GetLastError(Stream)); + ANSI_TO_TCHAR(Io_Stream_GetLastError(Stream))); } } } else { + // Went over max capacity so stop writing here. EventTracer->BytesWrittenToStream = EventTracer->MaxFileSize; } } @@ -72,39 +96,50 @@ SpatialScopedActiveSpanId::~SpatialScopedActiveSpanId() SpatialEventTracer::SpatialEventTracer(const FString& WorkerId) { const USpatialGDKSettings* Settings = GetDefault(); - MaxFileSize = Settings->MaxEventTracingFileSizeBytes; + MaxFileSize = Settings->bEnableEventTracingRotatingLogs ? 0 : Settings->EventTracingSingleLogMaxFileSizeBytes; // 0 indicates unbounded. - Trace_EventTracer_Parameters parameters = {}; - parameters.user_data = this; - parameters.callback = &SpatialEventTracer::TraceCallback; - EventTracer = Trace_EventTracer_Create(¶meters); + Trace_EventTracer_Parameters Parameters = {}; + Parameters.user_data = this; + Parameters.callback = &SpatialEventTracer::TraceCallback; + Parameters.enabled = true; - Trace_SamplingParameters SamplingParameters = {}; - SamplingParameters.sampling_mode = Trace_SamplingMode::TRACE_SAMPLING_MODE_PROBABILISTIC; + UE_LOG(LogSpatialEventTracer, Log, TEXT("Spatial event tracing enabled.")); UEventTracingSamplingSettings* SamplingSettings = Settings->GetEventTracingSamplingSettings(); - UE_LOG(LogSpatialEventTracer, Log, TEXT("Setting event tracing sampling probability. Probability: %f."), + TArray SpanSamplingProbabilities; + // Storage for strings passed to the worker SDK Worker requires ansi const char* + FSpatialTraceEventDataBuilder::FStringCache AnsiStrings; + + Parameters.span_sampling_parameters.sampling_mode = Trace_SamplingMode::TRACE_SAMPLING_MODE_PROBABILISTIC; + + UE_LOG(LogSpatialEventTracer, Log, TEXT("Setting event tracing span sampling probabalistic. Probability: %f."), SamplingSettings->SamplingProbability); - TArray SpanSamplingProbabilities; - TArray AnsiStrings; // Worker requires ansi const char* + SpanSamplingProbabilities.Reserve(SamplingSettings->EventSamplingModeOverrides.Num()); for (const auto& Pair : SamplingSettings->EventSamplingModeOverrides) { const FString& EventName = Pair.Key.ToString(); UE_LOG(LogSpatialEventTracer, Log, TEXT("Adding trace event sampling override. Event: %s Probability: %f."), *EventName, Pair.Value); - int32 Index = AnsiStrings.Add(TCHAR_TO_ANSI(*EventName)); - SpanSamplingProbabilities.Add({ AnsiStrings[Index].c_str(), Pair.Value }); + SpanSamplingProbabilities.Add({ AnsiStrings.Get(AnsiStrings.AddFString(EventName)), Pair.Value }); } - SamplingParameters.probabilistic_parameters.default_probability = SamplingSettings->SamplingProbability; - SamplingParameters.probabilistic_parameters.probability_count = SpanSamplingProbabilities.Num(); - SamplingParameters.probabilistic_parameters.probabilities = SpanSamplingProbabilities.GetData(); + Parameters.span_sampling_parameters.probabilistic_parameters.default_probability = SamplingSettings->SamplingProbability; + Parameters.span_sampling_parameters.probabilistic_parameters.probability_count = SpanSamplingProbabilities.Num(); + Parameters.span_sampling_parameters.probabilistic_parameters.probabilities = SpanSamplingProbabilities.GetData(); - Trace_EventTracer_SetSampler(EventTracer, &SamplingParameters); + // Filters + TraceQueryPtr PreFilter = ParseOrDefault(SamplingSettings->GDKEventPreFilter, TEXT("pre-filter")); + TraceQueryPtr PostFilter = ParseOrDefault(SamplingSettings->GDKEventPostFilter, TEXT("post-filter")); - UE_LOG(LogSpatialEventTracer, Log, TEXT("Spatial event tracing enabled.")); + checkf(PreFilter.Get() != nullptr, TEXT("Pre-filter is invalid.")); + checkf(PostFilter.Get() != nullptr, TEXT("Post-filter is invalid.")); + + Parameters.filter_parameters.event_pre_filter_parameters.simple_query = PreFilter.Get(); + Parameters.filter_parameters.event_post_filter_parameters.simple_query = PostFilter.Get(); + + EventTracer = Trace_EventTracer_Create(&Parameters); // Open a local file FString EventTracePath = FPaths::Combine(FPaths::ProjectSavedDir(), TEXT("EventTracing")); @@ -115,14 +150,38 @@ SpatialEventTracer::SpatialEventTracer(const FString& WorkerId) } FolderPath = EventTracePath; - const FString FullFileName = FString::Printf(TEXT("EventTrace_%s_%s.trace"), *WorkerId, *FDateTime::Now().ToString()); - const FString FilePath = FPaths::Combine(FolderPath, FullFileName); + const FString FolderWorkerPath = FPaths::Combine(EventTracePath, WorkerId); IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); - if (PlatformFile.CreateDirectoryTree(*FolderPath)) + const FString FileName = TEXT("gdk"); + const FString FileExt = TEXT(".etlog"); + if (PlatformFile.CreateDirectoryTree(*FolderWorkerPath)) + { + UE_LOG(LogSpatialEventTracer, Log, TEXT("Capturing trace file%s to %s."), + (Settings->bEnableEventTracingRotatingLogs) ? TEXT("s") : TEXT(""), *FolderWorkerPath); + + if (Settings->bEnableEventTracingRotatingLogs) + { + FString FullFilePathPrefix = FString::Printf(TEXT("%s-"), *FPaths::Combine(FolderWorkerPath, FileName)); + const FString FullFilePathSuffix = FileExt; + + Io_RotatingFileStreamParameters FileParamters; + FileParamters.filename_prefix = AnsiStrings.Get(AnsiStrings.AddFString(FullFilePathPrefix)); + FileParamters.filename_suffix = AnsiStrings.Get(AnsiStrings.AddFString(FullFilePathSuffix)); + FileParamters.max_file_size_bytes = Settings->EventTracingRotatingLogsMaxFileSizeBytes; + FileParamters.max_file_count = Settings->EventTracingRotatingLogsMaxFileCount; + Stream.Reset(Io_CreateRotatingFileStream(&FileParamters)); + } + else + { + const FString FullFilename = FString::Printf(TEXT("%s%s"), *FileName, *FileExt); + const FString FullFilePath = FPaths::Combine(FolderWorkerPath, FullFilename); + Stream.Reset(Io_CreateFileStream(TCHAR_TO_ANSI(*FullFilePath), Io_OpenMode::IO_OPEN_MODE_WRITE)); + } + } + else { - UE_LOG(LogSpatialEventTracer, Log, TEXT("Capturing trace to %s."), *FilePath); - Stream.Reset(Io_CreateFileStream(TCHAR_TO_ANSI(*FilePath), Io_OpenMode::IO_OPEN_MODE_WRITE)); + UE_LOG(LogSpatialEventTracer, Error, TEXT("Error creating directory tree to %s"), *FolderWorkerPath); } } @@ -152,11 +211,6 @@ FSpatialGDKSpanId SpatialEventTracer::UserSpanIdToGDKSpanId(const FUserSpanId& U return TraceSpanId; } -void SpatialEventTracer::StreamDeleter::operator()(Io_Stream* StreamToDestroy) const -{ - Io_Stream_Destroy(StreamToDestroy); -} - void SpatialEventTracer::BeginOpsForFrame() { for (auto& ConsumedKey : EntityComponentsConsumed) diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp index cc55026b16..625f1910ec 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialEventTracerUserInterface.cpp @@ -5,7 +5,6 @@ #include "Engine/Engine.h" #include "EngineClasses/SpatialNetDriver.h" #include "EngineClasses/SpatialPackageMapClient.h" - #include "Interop/Connection/SpatialWorkerConnection.h" #include "Interop/SpatialClassInfoManager.h" diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp index e88775b097..514e16c331 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialTraceEventDataBuilder.cpp @@ -86,28 +86,28 @@ FSpatialTraceEventDataBuilder::~FSpatialTraceEventDataBuilder() Trace_EventData_Destroy(EventData); } -void FSpatialTraceEventDataBuilder::AddObject(const UObject* Object, const char* Key /*="Object"*/) +void FSpatialTraceEventDataBuilder::AddObject(const UObject* Object, const char* Key /*="object"*/) { if (Object != nullptr) { if (const AActor* Actor = Cast(Object)) { FString PositionString = Actor->GetTransform().GetTranslation().ToString(); - AddKeyValue(StringConverter.CombineStrings(Key, "ActorPosition"), StringConverter.AddFString(PositionString)); + AddKeyValue(StringConverter.CombineStrings(Key, "actor_position"), StringConverter.AddFString(PositionString)); } if (UWorld* World = Object->GetWorld()) { if (USpatialNetDriver* NetDriver = Cast(World->GetNetDriver())) { - FString NetGuidString = NetDriver->PackageMap->GetNetGUIDFromObject(Object).ToString(); - AddKeyValue(StringConverter.CombineStrings(Key, "NetGuid"), StringConverter.AddFString(NetGuidString)); + AddKeyValue(StringConverter.CombineStrings(Key, "entity_id"), + StringConverter.AddInt64((NetDriver->PackageMap->GetEntityIdFromObject(Object)))); } } AddKeyValue(Key, Object->GetName()); } } -void FSpatialTraceEventDataBuilder::AddFunction(const UFunction* Function, const char* Key /*="Function"*/) +void FSpatialTraceEventDataBuilder::AddFunction(const UFunction* Function, const char* Key /*="function"*/) { if (Function != nullptr) { @@ -115,47 +115,47 @@ void FSpatialTraceEventDataBuilder::AddFunction(const UFunction* Function, const } } -void FSpatialTraceEventDataBuilder::AddEntityId(const Worker_EntityId EntityId, const char* Key /*="EntityId"*/) +void FSpatialTraceEventDataBuilder::AddEntityId(const Worker_EntityId EntityId, const char* Key /*="entiy_id"*/) { AddKeyValue(Key, static_cast(EntityId)); } -void FSpatialTraceEventDataBuilder::AddComponentId(const Worker_ComponentId ComponentId, const char* Key /*="ComponentId"*/) +void FSpatialTraceEventDataBuilder::AddComponentId(const Worker_ComponentId ComponentId, const char* Key /*="component_id"*/) { AddKeyValue(Key, static_cast(ComponentId)); } -void FSpatialTraceEventDataBuilder::AddComponentSetId(const Worker_ComponentSetId ComponentSetId, const char* Key /*="ComponentSetId"*/) +void FSpatialTraceEventDataBuilder::AddComponentSetId(const Worker_ComponentSetId ComponentSetId, const char* Key /*="component_set_id"*/) { AddKeyValue(Key, static_cast(ComponentSetId)); } -void FSpatialTraceEventDataBuilder::AddFieldId(const uint32 FieldId, const char* Key /*="FieldId"*/) +void FSpatialTraceEventDataBuilder::AddFieldId(const uint32 FieldId, const char* Key /*="field_id"*/) { AddKeyValue(Key, FieldId); } -void FSpatialTraceEventDataBuilder::AddWorkerId(const uint32 WorkerId, const char* Key /*="WorkerId"*/) +void FSpatialTraceEventDataBuilder::AddWorkerId(const uint32 WorkerId, const char* Key /*="worker_id"*/) { AddKeyValue(Key, WorkerId); } -void FSpatialTraceEventDataBuilder::AddCommand(const char* Command, const char* Key /*="Command"*/) +void FSpatialTraceEventDataBuilder::AddCommand(const char* Command, const char* Key /*="command"*/) { AddKeyValue(Key, Command); } -void FSpatialTraceEventDataBuilder::AddRequestId(const int64 RequestId, const char* Key /*="RequestId"*/) +void FSpatialTraceEventDataBuilder::AddRequestId(const int64 RequestId, const char* Key /*="request_id"*/) { AddKeyValue(Key, RequestId); } -void FSpatialTraceEventDataBuilder::AddAuthority(const Worker_Authority Authority, const char* Key /*="Authority"*/) +void FSpatialTraceEventDataBuilder::AddAuthority(const Worker_Authority Authority, const char* Key /*="authority"*/) { AddKeyValue(Key, AuthorityToString(Authority)); } -void FSpatialTraceEventDataBuilder::AddLinearTraceId(const EventTraceUniqueId LinearTraceId, const char* Key /*="LinearTraceId"*/) +void FSpatialTraceEventDataBuilder::AddLinearTraceId(const EventTraceUniqueId LinearTraceId, const char* Key /*="linear_trace_id"*/) { AddKeyValue(Key, LinearTraceId.Get()); } @@ -197,7 +197,7 @@ void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const int64 Val void FSpatialTraceEventDataBuilder::AddKeyValue(const char* Key, const bool bValue) { - AddKeyValue(StringConverter.AddString(Key), StringConverter.AddString(bValue ? "True" : "False")); + AddKeyValue(StringConverter.AddString(Key), StringConverter.AddString(bValue ? "true" : "false")); } void FSpatialTraceEventDataBuilder::AddKeyValue(int32 KeyHandle, int32 ValueHandle) @@ -212,11 +212,11 @@ const char* FSpatialTraceEventDataBuilder::AuthorityToString(Worker_Authority Au switch (Authority) { case Worker_Authority::WORKER_AUTHORITY_NOT_AUTHORITATIVE: - return "NotAuthoritative"; + return "not_authoritative"; case Worker_Authority::WORKER_AUTHORITY_AUTHORITATIVE: - return "Authoritative"; + return "authoritative"; default: - return "Unknown"; + return "unknown"; } } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp index 73d34d72af..6684ba34c4 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/DebugMetricsSystem.cpp @@ -92,11 +92,11 @@ void DebugMetricsSystem::ProcessOps(const TArray& Ops) const if (EventTracer != nullptr) { - SpanId = EventTracer->TraceEvent(SEND_COMMAND_RESPONSE_EVENT_NAME, "", CauseSpanId.GetConstId(), /* NumCauses */ 1, - [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { - EventBuilder.AddRequestId(RequestId); - EventBuilder.AddKeyValue("Success", true); - }); + SpanId = EventTracer->TraceEvent(SEND_COMMAND_RESPONSE_EVENT_NAME, "", CauseSpanId.GetConstId(), /* NumCauses */ 1, + [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { + EventBuilder.AddRequestId(RequestId); + EventBuilder.AddKeyValue("success", true); + }); } Connection.SendCommandResponse(RequestId, &Response, SpanId); diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp index ecc9c58608..ea06a49d38 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/MigrationDiagnosticsSystem.cpp @@ -40,7 +40,7 @@ void MigrationDiagnosticsSystem::OnMigrationDiagnosticRequest(const Worker_Op& O EventTracer->TraceEvent(SEND_COMMAND_RESPONSE_EVENT_NAME, "", CauseSpanId.GetConstId(), /* NumCauses */ 1, [RequestId](FSpatialTraceEventDataBuilder& EventBuilder) { EventBuilder.AddRequestId(RequestId); - EventBuilder.AddKeyValue("Success", true); + EventBuilder.AddKeyValue("success", true); }); } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp index 4c630124df..004fa8f608 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/RPCExecutor.cpp @@ -126,9 +126,9 @@ TOptional RPCExecutor::TryRetrieveCrossServerRPCParams(co [TargetActor, TargetObject, Function, TraceId, Op](FSpatialTraceEventDataBuilder& EventBuilder) { EventBuilder.AddCommand("RPC_COMMAND_REQUEST"); EventBuilder.AddObject(TargetActor); - EventBuilder.AddObject(TargetActor != TargetObject ? TargetObject : nullptr, "TargetObject"); + EventBuilder.AddObject(TargetActor != TargetObject ? TargetObject : nullptr, "target_object"); EventBuilder.AddFunction(Function); - EventBuilder.AddKeyValue("TraceId", TraceId); + EventBuilder.AddKeyValue("trace_id", TraceId); EventBuilder.AddRequestId(Op.op.command_request.request_id); }); } diff --git a/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp b/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp index e5a3914d8d..7072b66efb 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Interop/SpatialSender.cpp @@ -126,7 +126,7 @@ void USpatialSender::SendAuthorityIntentUpdate(const AActor& InActor, VirtualWor SpanId = EventTracer->TraceEvent(AUTHORITY_INTENT_UPDATE_EVENT_NAME, "", /* Causes */ nullptr, /* NumCauses */ 0, [&InActor, NewAuthoritativeVirtualWorkerId](FSpatialTraceEventDataBuilder& EventBuilder) { EventBuilder.AddObject(&InActor); - EventBuilder.AddWorkerId(NewAuthoritativeVirtualWorkerId, "NewWorkerId"); + EventBuilder.AddWorkerId(NewAuthoritativeVirtualWorkerId, "new_worker_id"); }); } diff --git a/SpatialGDK/Source/SpatialGDK/Private/SpatialGDKSettings.cpp b/SpatialGDK/Source/SpatialGDK/Private/SpatialGDKSettings.cpp index c75f2f8b0e..31cf20ae53 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/SpatialGDKSettings.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/SpatialGDKSettings.cpp @@ -12,6 +12,7 @@ #if WITH_EDITOR #include "HAL/PlatformFilemanager.h" +#include "Interop/Connection/SpatialEventTracer.h" #include "Misc/FileHelper.h" #include "Settings/LevelEditorPlaySettings.h" @@ -94,8 +95,41 @@ void CheckCmdLineOverrideOptionalStringWithCallback(const TCHAR* CommandLine, co UE_LOG(LogSpatialGDKSettings, Log, TEXT("%s is %s."), PrettyName, OverrideValue.IsSet() ? *(OverrideValue.GetValue()) : TEXT("not set")); } + } // namespace +#if WITH_EDITOR +void UEventTracingSamplingSettings::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) +{ + auto CheckQueryValid = [](const char* QueryStr) { + if (strlen(QueryStr) > 0 && SpatialGDK::TraceQueryPtr(Trace_ParseSimpleQuery(QueryStr)).Get() == nullptr) + { + FMessageDialog::Open(EAppMsgType::Ok, + FText::Format(LOCTEXT("EventTracingSamplingSetting_QueryInvalid", "The query entered is not valid. {0}"), + FText::FromString(ANSI_TO_TCHAR(Trace_GetLastError())))); + } + }; + Super::PostEditChangeProperty(PropertyChangedEvent); + const FName Name = (PropertyChangedEvent.MemberProperty != nullptr) ? PropertyChangedEvent.MemberProperty->GetFName() : NAME_None; + if (Name == GET_MEMBER_NAME_CHECKED(UEventTracingSamplingSettings, GDKEventPreFilter)) + { + CheckQueryValid(TCHAR_TO_ANSI(*GDKEventPreFilter)); + } + else if (Name == GET_MEMBER_NAME_CHECKED(UEventTracingSamplingSettings, RuntimeEventPreFilter)) + { + CheckQueryValid(TCHAR_TO_ANSI(*RuntimeEventPreFilter)); + } + else if (Name == GET_MEMBER_NAME_CHECKED(UEventTracingSamplingSettings, GDKEventPostFilter)) + { + CheckQueryValid(TCHAR_TO_ANSI(*GDKEventPostFilter)); + } + else if (Name == GET_MEMBER_NAME_CHECKED(UEventTracingSamplingSettings, RuntimeEventPostFilter)) + { + CheckQueryValid(TCHAR_TO_ANSI(*RuntimeEventPostFilter)); + } +} +#endif + USpatialGDKSettings::USpatialGDKSettings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) , EntityPoolInitialReservationCount(3000) @@ -152,7 +186,10 @@ USpatialGDKSettings::USpatialGDKSettings(const FObjectInitializer& ObjectInitial , ActorMigrationLogRate(5.0f) , bEventTracingEnabled(false) , EventTracingSamplingSettingsClass(UEventTracingSamplingSettings::StaticClass()) - , MaxEventTracingFileSizeBytes(DefaultEventTracingFileSize) + , EventTracingSingleLogMaxFileSizeBytes(DefaultEventTracingFileSize) + , bEnableEventTracingRotatingLogs(false) + , EventTracingRotatingLogsMaxFileSizeBytes(DefaultEventTracingFileSize) + , EventTracingRotatingLogsMaxFileCount(256) , bEnableAlwaysWriteRPCs(false) , bEnableInitialOnlyReplicationCondition(false) { diff --git a/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp b/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp index 32d94620e7..5fe7e6933a 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/Utils/ComponentReader.cpp @@ -341,7 +341,7 @@ void ComponentReader::ApplySchemaObject(Schema_Object* ComponentObject, UObject& EventBuilder.AddObject(&Object); EventBuilder.AddEntityId(EntityId); EventBuilder.AddComponentId(ComponentId); - EventBuilder.AddKeyValue("PropertyName", Cmd.Property->GetName()); + EventBuilder.AddKeyValue("property_name", Cmd.Property->GetName()); EventBuilder.AddLinearTraceId(EventTraceUniqueId::GenerateForProperty(EntityId, Cmd.Property)); }); } diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h index 3316ee400c..04d513afc4 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialEventTracer.h @@ -16,6 +16,18 @@ DECLARE_LOG_CATEGORY_EXTERN(LogSpatialEventTracer, Log, All); namespace SpatialGDK { +struct TraceQueryDeleter +{ + void operator()(Trace_Query* Query) const + { + if (Query != nullptr) + { + Trace_Query_Destroy(Query); + } + } +}; +typedef TUniquePtr TraceQueryPtr; + // SpatialEventTracer wraps Trace_EventTracer related functionality class SPATIALGDK_API SpatialEventTracer { @@ -60,7 +72,13 @@ class SPATIALGDK_API SpatialEventTracer private: struct StreamDeleter { - void operator()(Io_Stream* StreamToDestroy) const; + void operator()(Io_Stream* StreamToDestroy) const + { + if (StreamToDestroy != nullptr) + { + Io_Stream_Destroy(StreamToDestroy); + } + } }; static void TraceCallback(void* UserData, const Trace_Item* Item); @@ -114,8 +132,7 @@ FSpatialGDKSpanId SpatialEventTracer::TraceEvent(const char* EventType, const ch // This would allow for sampling dependent on trace event data. Trace_Event Event = { nullptr, 0, Message, EventType, nullptr }; - Trace_SamplingResult SpanSamplingResult = Trace_EventTracer_ShouldSampleSpan(EventTracer, Causes, NumCauses, &Event); - if (SpanSamplingResult.decision == Trace_SamplingDecision::TRACE_SHOULD_NOT_SAMPLE) + if (!Trace_EventTracer_ShouldSampleSpan(EventTracer, Causes, NumCauses, &Event)) { return {}; } @@ -124,36 +141,20 @@ FSpatialGDKSpanId SpatialEventTracer::TraceEvent(const char* EventType, const ch Trace_EventTracer_AddSpan(EventTracer, Causes, NumCauses, &Event, TraceSpanId.GetId()); Event.span_id = TraceSpanId.GetConstId(); - Trace_SamplingResult EventSamplingResult = Trace_EventTracer_ShouldSampleEvent(EventTracer, &Event); - switch (EventSamplingResult.decision) - { - case Trace_SamplingDecision::TRACE_SHOULD_NOT_SAMPLE: - { - return TraceSpanId; - } - case Trace_SamplingDecision::TRACE_SHOULD_SAMPLE_WITHOUT_DATA: + if (!Trace_EventTracer_PreFilterAcceptsEvent(EventTracer, &Event)) { - Trace_EventTracer_AddEvent(EventTracer, &Event); return TraceSpanId; } - case Trace_SamplingDecision::TRACE_SHOULD_SAMPLE: - { - FSpatialTraceEventDataBuilder EventDataBuilder; - DataCallback(EventDataBuilder); + FSpatialTraceEventDataBuilder EventDataBuilder; + DataCallback(EventDataBuilder); - // Frame counter - EventDataBuilder.AddKeyValue("FrameNum", GFrameCounter); + // Frame counter + EventDataBuilder.AddKeyValue("frame_num", GFrameCounter); - Event.data = EventDataBuilder.GetEventData(); - Trace_EventTracer_AddEvent(EventTracer, &Event); - return TraceSpanId; - } - default: - { - return {}; - } - } + Event.data = EventDataBuilder.GetEventData(); + Trace_EventTracer_AddEvent(EventTracer, &Event); + return TraceSpanId; } } // namespace SpatialGDK diff --git a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h index d3e71e5cf5..b889befd71 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Interop/Connection/SpatialTraceEventDataBuilder.h @@ -93,17 +93,17 @@ class SPATIALGDK_API FSpatialTraceEventDataBuilder FSpatialTraceEventDataBuilder(); ~FSpatialTraceEventDataBuilder(); - void AddObject(const UObject* Object, const char* Key = "Object"); - void AddFunction(const UFunction* Function, const char* Key = "Function"); - void AddEntityId(const Worker_EntityId EntityId, const char* Key = "EntityId"); - void AddComponentId(const Worker_ComponentId ComponentId, const char* Key = "ComponentId"); - void AddComponentSetId(const Worker_ComponentSetId ComponentId, const char* Key = "ComponentSetId"); - void AddFieldId(const uint32 FieldId, const char* Key = "FieldId"); - void AddWorkerId(const uint32 WorkerId, const char* Key = "WorkerId"); - void AddCommand(const char* Command, const char* Key = "Command"); - void AddRequestId(const int64 RequestId, const char* Key = "RequestId"); - void AddAuthority(const Worker_Authority Authority, const char* Key = "Authority"); - void AddLinearTraceId(const EventTraceUniqueId LinearTraceId, const char* Key = "LinearTraceId"); + void AddObject(const UObject* Object, const char* Key = "object"); + void AddFunction(const UFunction* Function, const char* Key = "function"); + void AddEntityId(const Worker_EntityId EntityId, const char* Key = "entity_id"); + void AddComponentId(const Worker_ComponentId ComponentId, const char* Key = "component_id"); + void AddComponentSetId(const Worker_ComponentSetId ComponentId, const char* Key = "component_set_id"); + void AddFieldId(const uint32 FieldId, const char* Key = "field_id"); + void AddWorkerId(const uint32 WorkerId, const char* Key = "worker_id"); + void AddCommand(const char* Command, const char* Key = "command"); + void AddRequestId(const int64 RequestId, const char* Key = "request_id"); + void AddAuthority(const Worker_Authority Authority, const char* Key = "authority"); + void AddLinearTraceId(const EventTraceUniqueId LinearTraceId, const char* Key = "linear_trace_id"); void AddKeyValue(const char* Key, const char* Value); void AddKeyValue(const char* Key, const FString& Value); diff --git a/SpatialGDK/Source/SpatialGDK/Public/SpatialGDKSettings.h b/SpatialGDK/Source/SpatialGDK/Public/SpatialGDKSettings.h index 3c522093f6..5d98fbeda7 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/SpatialGDKSettings.h +++ b/SpatialGDK/Source/SpatialGDK/Public/SpatialGDKSettings.h @@ -75,6 +75,24 @@ class SPATIALGDK_API UEventTracingSamplingSettings : public UObject UPROPERTY(EditAnywhere, Category = "Event Tracing") TMap EventSamplingModeOverrides; + + UPROPERTY(EditAnywhere, Category = "Event Tracing") + FString GDKEventPreFilter; + + UPROPERTY(EditAnywhere, Category = "Event Tracing") + FString GDKEventPostFilter; + + /* The runtime filter which is used for local/cloud editor workflows (generated configs). */ + UPROPERTY(EditAnywhere, Category = "Event Tracing") + FString RuntimeEventPreFilter; + + /* The runtime filter which is used for local/cloud editor workflows (generated configs). */ + UPROPERTY(EditAnywhere, Category = "Event Tracing") + FString RuntimeEventPostFilter; + +#if WITH_EDITOR + virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override; +#endif }; UCLASS(config = SpatialGDKSettings, defaultconfig) @@ -447,10 +465,31 @@ class SPATIALGDK_API USpatialGDKSettings : public UObject /* * -- EXPERIMENTAL -- - * The maximum size of the event tracing file, in bytes + * The maximum size of a event log (non-rotating), synonymous with squid config behavior `event_tracing_single_log_max_file_size_bytes` + */ + UPROPERTY(Config) + int64 EventTracingSingleLogMaxFileSizeBytes; + + /* + * -- EXPERIMENTAL -- + * Whether to enable rotating logs, synonymous with squid config behavior `enable_event_tracing_rotating_logs` + */ + UPROPERTY(Config) + bool bEnableEventTracingRotatingLogs; + + /* + * -- EXPERIMENTAL -- + * Rotating log file size, synonymous with squid config behavior `event_tracing_rotating_logs_max_file_size_bytes` + */ + UPROPERTY(Config) + int64 EventTracingRotatingLogsMaxFileSizeBytes; + + /* + * -- EXPERIMENTAL -- + * The maximum number of rotating logs to produce, synonymous with squid config behavior `event_tracing_rotating_logs_max_file_count` */ UPROPERTY(Config) - uint64 MaxEventTracingFileSizeBytes; + int32 EventTracingRotatingLogsMaxFileCount; UPROPERTY(Config) bool bEnableAlwaysWriteRPCs; diff --git a/SpatialGDK/Source/SpatialGDK/Public/Utils/WorkerVersionCheck.h b/SpatialGDK/Source/SpatialGDK/Public/Utils/WorkerVersionCheck.h index c4713e2a7f..7c955fba2d 100644 --- a/SpatialGDK/Source/SpatialGDK/Public/Utils/WorkerVersionCheck.h +++ b/SpatialGDK/Source/SpatialGDK/Public/Utils/WorkerVersionCheck.h @@ -4,7 +4,7 @@ #include "improbable/c_worker.h" -#define WORKER_SDK_VERSION "15.0.1" +#define WORKER_SDK_VERSION "15.1.0" constexpr bool StringsEqual(char const* A, char const* B) { diff --git a/SpatialGDK/Source/SpatialGDKEditor/Private/SpatialGDKDefaultLaunchConfigGenerator.cpp b/SpatialGDK/Source/SpatialGDKEditor/Private/SpatialGDKDefaultLaunchConfigGenerator.cpp index b804431910..d497f63403 100644 --- a/SpatialGDK/Source/SpatialGDKEditor/Private/SpatialGDKDefaultLaunchConfigGenerator.cpp +++ b/SpatialGDK/Source/SpatialGDKEditor/Private/SpatialGDKDefaultLaunchConfigGenerator.cpp @@ -178,6 +178,38 @@ bool GenerateLaunchConfig(const FString& LaunchConfigPath, const FSpatialLaunchC Writer->WriteValue(TEXT("max_concurrent_workers"), LaunchConfigDescription.MaxConcurrentWorkers); + // Event tracing + if (SpatialGDKSettings->bEventTracingEnabled) + { + Writer->WriteObjectStart(TEXT("event_tracing_configuration")); + Writer->WriteValue(TEXT("enabled"), true); + + if (SpatialGDKSettings->bEnableEventTracingRotatingLogs) + { + Writer->WriteObjectStart(TEXT("rotating_event_log_file_configuration")); + Writer->WriteValue(TEXT("max_file_size_bytes"), SpatialGDKSettings->EventTracingRotatingLogsMaxFileSizeBytes); + Writer->WriteValue(TEXT("max_file_count"), SpatialGDKSettings->EventTracingRotatingLogsMaxFileCount); + Writer->WriteObjectEnd(); // rotating_event_log_file_configuration end + } + else + { + Writer->WriteObjectStart(TEXT("single_event_log_file_configuration")); + Writer->WriteValue(TEXT("max_file_size_bytes"), SpatialGDKSettings->EventTracingSingleLogMaxFileSizeBytes); + Writer->WriteObjectEnd(); // single_event_log_file_configuration end + } + + Writer->WriteObjectStart(TEXT("event_filter_configuration")); + + UEventTracingSamplingSettings* SamplingSettings = SpatialGDKSettings->GetEventTracingSamplingSettings(); + Writer->WriteValue(TEXT("event_pre_filter"), + SamplingSettings->RuntimeEventPreFilter.Len() ? *SamplingSettings->RuntimeEventPreFilter : TEXT("false")); + Writer->WriteValue(TEXT("event_post_filter"), + SamplingSettings->RuntimeEventPostFilter.Len() ? SamplingSettings->RuntimeEventPostFilter : TEXT("false")); + + Writer->WriteObjectEnd(); // event_filter_configuration end + Writer->WriteObjectEnd(); // event_tracing_configuration end + } + Writer->WriteObjectEnd(); // End of json Writer->Close(); diff --git a/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/EventTracingTests/EventTracingTest.cpp b/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/EventTracingTests/EventTracingTest.cpp index 22b9307593..07e6088922 100644 --- a/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/EventTracingTests/EventTracingTest.cpp +++ b/SpatialGDK/Source/SpatialGDKFunctionalTests/SpatialGDK/EventTracingTests/EventTracingTest.cpp @@ -123,7 +123,7 @@ void AEventTracingTest::GatherData() IFileManager& FileManager = IFileManager::Get(); TArray Files; - FileManager.FindFiles(Files, *EventsFolderPath, *FString(".trace")); + FileManager.FindFilesRecursive(Files, *EventsFolderPath, *FString("*.etlog"), true, false); if (Files.Num() < 2) { @@ -140,29 +140,26 @@ void AEventTracingTest::GatherData() TArray FileCreationTimes; for (const FString& File : Files) { - FString FilePath = FPaths::Combine(EventsFolderPath, File); - FileCreationTimes.Add({ FilePath, FileManager.GetTimeStamp(*FilePath) }); + FileCreationTimes.Add({ File, FileManager.GetTimeStamp(*File) }); } FileCreationTimes.Sort([](const FileCreationTime& A, const FileCreationTime& B) { return A.CreationTime > B.CreationTime; }); - FPlatformProcess::Sleep(1); // Worker bug means file may not be flushed by the OS (WRK-2396) - int RequiredClients = GetRequiredClients(); int RequiredWorkers = GetRequiredWorkers(); int FoundClient = 0; int FoundWorker = 0; for (const FileCreationTime& FileCreation : FileCreationTimes) { - if (FoundClient != RequiredClients && FileCreation.FilePath.Contains("UnrealClient")) + if (FoundClient != RequiredClients && FileCreation.FilePath.Contains("client")) { GatherDataFromFile(FileCreation.FilePath); FoundClient++; } - if (FoundWorker != RequiredWorkers && FileCreation.FilePath.Contains("UnrealWorker")) + if (FoundWorker != RequiredWorkers && FileCreation.FilePath.Contains("worker")) { GatherDataFromFile(FileCreation.FilePath); FoundWorker++; @@ -198,6 +195,10 @@ void AEventTracingTest::GatherDataFromFile(const FString& FilePath) while (BytesToRead != 0 && ReturnCode == 1) { BytesToRead = Trace_GetNextSerializedItemSize(Stream.Get()); + if (BytesToRead == 0) + { + break; + } Trace_Item* Item = Trace_Item_GetThreadLocal(); if (BytesToRead != 0) diff --git a/SpatialGDK/Source/SpatialGDKServices/Private/LocalDeploymentManager.cpp b/SpatialGDK/Source/SpatialGDKServices/Private/LocalDeploymentManager.cpp index 4b4d502417..a55ac7ab6f 100644 --- a/SpatialGDK/Source/SpatialGDKServices/Private/LocalDeploymentManager.cpp +++ b/SpatialGDK/Source/SpatialGDKServices/Private/LocalDeploymentManager.cpp @@ -273,16 +273,24 @@ FLocalDeploymentManager::ERuntimeStartResponse FLocalDeploymentManager::StartLoc // Use the runtime start timestamp as the log directory, e.g. `/spatial/localdeployment//` FString LocalDeploymentLogsDir = FPaths::Combine(SpatialGDKServicesConstants::LocalDeploymentLogsDir, RuntimeStartTime.ToString()); + // Store these logs alongside the GDK ones for convenience + const TCHAR* RuntimeEventLogPaths = TEXT("EventTracing/runtime"); + FString EventTracingPath = FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectSavedDir(), RuntimeEventLogPaths)); + IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); + if (!PlatformFile.CreateDirectoryTree(*EventTracingPath)) + { + UE_LOG(LogSpatialDeploymentManager, Error, TEXT("Failed to create runtime event log path.")); + } + // runtime.exe --config=squid_config.json --snapshot=snapshots/default.snapshot --worker-port 8018 --http-port 5006 --grpc-port 7777 // --worker-external-host 127.0.0.1 --snapshots-directory=spatial/snapshots/ // --schema-bundle=spatial/build/assembly/schema/schema.sb - // --event-tracing-logs-directory=`/spatial/localdeployment//` - FString RuntimeArgs = - FString::Printf(TEXT("--config=\"%s\" --snapshot=\"%s\" --worker-port %s --http-port=%s --grpc-port=%s " - "--snapshots-directory=\"%s\" --schema-bundle=\"%s\" --event-tracing-logs-directory=\"%s\" %s"), - *LaunchConfig, *SnapshotName, *FString::FromInt(WorkerPort), *FString::FromInt(HTTPPort), - *FString::FromInt(SpatialGDKServicesConstants::RuntimeGRPCPort), *SnapshotPath, *SchemaBundle, - *LocalDeploymentLogsDir, *LaunchArgs); + // --event - tracing - logs - directory = ` / spatial / localdeployment / / ` + FString RuntimeArgs = FString::Printf( + TEXT("--config=\"%s\" --snapshot=\"%s\" --worker-port %s --http-port=%s --grpc-port=%s " + "--snapshots-directory=\"%s\" --schema-bundle=\"%s\" --event-tracing-logs-directory=\"%s\" %s"), + *LaunchConfig, *SnapshotName, *FString::FromInt(WorkerPort), *FString::FromInt(HTTPPort), + *FString::FromInt(SpatialGDKServicesConstants::RuntimeGRPCPort), *SnapshotPath, *SchemaBundle, *EventTracingPath, *LaunchArgs); if (!RuntimeIPToExpose.IsEmpty()) { diff --git a/SpatialGDK/Source/SpatialGDKServices/Public/SpatialGDKServicesConstants.h b/SpatialGDK/Source/SpatialGDKServices/Public/SpatialGDKServicesConstants.h index 9f39e28cd1..e3da202211 100644 --- a/SpatialGDK/Source/SpatialGDKServices/Public/SpatialGDKServicesConstants.h +++ b/SpatialGDK/Source/SpatialGDKServices/Public/SpatialGDKServicesConstants.h @@ -52,7 +52,7 @@ static const FString GetInspectorExecutablePath(const FString& InspectorVersion) return FPaths::Combine(GDKProgramPath, InspectorPackageName, InspectorVersion, InspectorExe); } -const FString SpatialOSRuntimePinnedStandardVersion = TEXT("15.0.1"); +const FString SpatialOSRuntimePinnedStandardVersion = TEXT("15.1.0"); const int32 RuntimeGRPCPort = 7777; const int32 RuntimeHTTPPort = 5006; @@ -60,7 +60,7 @@ const int32 RuntimeHTTPPort = 5006; const FString InspectorGRPCAddress = FString::Printf(TEXT("localhost:%s"), *FString::FromInt(RuntimeGRPCPort)); const FString InspectorHTTPAddress = FString::Printf(TEXT("localhost:%s"), *FString::FromInt(RuntimeHTTPPort)); const FString InspectorV2URL = TEXT("http://localhost:33333/inspector-v2"); -const FString InspectorPinnedVersion = TEXT("15.0.1"); +const FString InspectorPinnedVersion = TEXT("15.1.0"); const FString PinnedStandardRuntimeTemplate = TEXT("n1standard4_std40_action1g1"); const FString PinnedCompatibilityModeRuntimeTemplate = TEXT("n1standard4_std40_r0500"); From 3e3373db2ddec7f802e34973485316521c4fc073 Mon Sep 17 00:00:00 2001 From: Simon Sarginson Date: Fri, 28 May 2021 16:30:05 +0100 Subject: [PATCH 13/14] Fix/downgrade stale object warning (#3156) --- .../Private/EngineClasses/SpatialPackageMapClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialPackageMapClient.cpp b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialPackageMapClient.cpp index 4b79fd138b..b3e675ab1f 100644 --- a/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialPackageMapClient.cpp +++ b/SpatialGDK/Source/SpatialGDK/Private/EngineClasses/SpatialPackageMapClient.cpp @@ -617,7 +617,7 @@ void FSpatialNetGUIDCache::RemoveEntityNetGUID(Worker_EntityId EntityId) if (UnrealMetadata->NativeClass.IsStale()) { - UE_LOG(LogSpatialPackageMap, Warning, TEXT("Attempting to remove stale object from package map - %s"), *UnrealMetadata->ClassPath); + UE_LOG(LogSpatialPackageMap, Log, TEXT("Attempting to remove stale object from package map - %s"), *UnrealMetadata->ClassPath); } else { @@ -695,7 +695,7 @@ void FSpatialNetGUIDCache::RemoveSubobjectNetGUID(const FUnrealObjectRef& Subobj if (UnrealMetadata->NativeClass.IsStale()) { - UE_LOG(LogSpatialPackageMap, Warning, TEXT("Attempting to remove stale subobject from package map - %s"), + UE_LOG(LogSpatialPackageMap, Log, TEXT("Attempting to remove stale subobject from package map - %s"), *UnrealMetadata->ClassPath); } else From 67843496bf5fb3ed7e0448c406382db4bc4effc0 Mon Sep 17 00:00:00 2001 From: UnrealGDK Bot Date: Wed, 2 Jun 2021 15:41:19 +0000 Subject: [PATCH 14/14] Prepare GDK for Unreal release 0.13.1. --- .buildkite/premerge.steps.yaml | 8 ++++---- CHANGELOG.md | 7 +++---- UnrealGDKEngineNetTestVersion.txt | 2 +- UnrealGDKTestGymsVersion.txt | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.buildkite/premerge.steps.yaml b/.buildkite/premerge.steps.yaml index 8a35b96348..d9062a60fa 100755 --- a/.buildkite/premerge.steps.yaml +++ b/.buildkite/premerge.steps.yaml @@ -33,9 +33,9 @@ steps: env: BUILD_TYPE: "GDK" GDK_BRANCH: "main_branch::${BUILDKITE_BRANCH}" - ENGINE_BRANCH: "${ENGINE_BRANCH_426:-match_branch_name_pref_engine::4.26-SpatialOSUnrealGDK-0.13.1-rc}" + ENGINE_BRANCH: "${ENGINE_BRANCH_426:-match_branch_name_pref_engine::4.26-SpatialOSUnrealGDK-0.13.1}" ENGINE_MAJOR: "4.26" - PROJECT_BRANCH: "${PROJECT_BRANCH:-match_branch_name_pref::0.13.1-rc}" + PROJECT_BRANCH: "${PROJECT_BRANCH:-match_branch_name_pref::0.13.1}" USE_FASTBUILD: "True" IS_BUILDKITE_BUILD: "True" BUILD_ANDROID: "False" @@ -52,9 +52,9 @@ steps: env: BUILD_TYPE: "GDK" # GDK or ENGINE GDK_BRANCH: "main_branch::${BUILDKITE_BRANCH}" - ENGINE_BRANCH: "${ENGINE_BRANCH_425:-match_branch_name_pref_engine::4.25-SpatialOSUnrealGDK-0.13.1-rc}" + ENGINE_BRANCH: "${ENGINE_BRANCH_425:-match_branch_name_pref_engine::4.25-SpatialOSUnrealGDK-0.13.1}" ENGINE_MAJOR: "4.25" - PROJECT_BRANCH: "${PROJECT_BRANCH:-match_branch_name_pref::0.13.1-rc}" + PROJECT_BRANCH: "${PROJECT_BRANCH:-match_branch_name_pref::0.13.1}" USE_FASTBUILD: "True" IS_BUILDKITE_BUILD: "True" BUILD_ANDROID: "False" diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b269e9674..3b46f4d50f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,16 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [`x.y.z`] - Unreleased -## [`0.13.1`] - 2021-05-21 +## [`0.13.1`] - 2021-06-02 ### Breaking changes: -- Event tracing has been optimised to reduce overhead when tracing events in general and in particular when events are not sampled. The tracing API has been modified to accomidate these improvements. You will have to modify your project if you use the API. +- Event tracing has been optimised to reduce overhead when tracing events in general and in particular when events are not sampled. The tracing API has been modified to accommodate these improvements. You will have to modify your project if you use the API. ### Features: - Added `SpatialExecServerCmd` console command with one command `StartInsights` to dynamically enable insights capturing. - Format: SpatialExecServerCmd < server > < command > < args > - Example usage: "SpatialExecServerCmd local StartInsights -trace=CustomChannel -tracefile=MyNewTrace" - Visual Logger now supports multi-worker environments. -- The Unreal GDK has been updated to run against SpatialOS 15.1.0, older version of SpatialOS will no longer work with the Unreal GDK. +- The Unreal GDK has been updated to run against SpatialOS 15.1.0, older versions of SpatialOS will no longer work with the Unreal GDK. - Event tracing rotating log support (via `bEnableEventTracingRotatingLogs`, `EventTracingRotatingLogsMaxFileSizeBytes` and `EventTracingRotatingLogsMaxFileCount`). - Event tracing filter support (configured via `UEventTracingSamplingSettings`). @@ -102,7 +102,6 @@ These functions and structs can be referenced in both code and blueprints and it - Running without Ring Buffered RPCs is no longer supported, and the option has been removed from SpatialGDKSettings. - The schema database format has been updated and versioning introduced. Please regenerate your schema after updating. - The CookAndGenerateSchemaCommandlet no longer automatically deletes previously generated schema. Deletion of previously generated schema is now controlled by the `-DeleteExistingGeneratedSchema` flag. -- Event tracing has been optimised to reduce overhead when tracing events in general and in particular when events are not sampled. The tracing API has been modified to accommodate these improvements. You will have to modify your project if you use the API. ### Features: - The DeploymentLauncher tool can be used to start multiple simulated player deployments at once. diff --git a/UnrealGDKEngineNetTestVersion.txt b/UnrealGDKEngineNetTestVersion.txt index 6515fdf9f4..ed0d9e9902 100644 --- a/UnrealGDKEngineNetTestVersion.txt +++ b/UnrealGDKEngineNetTestVersion.txt @@ -1 +1 @@ -0.13.1-rc \ No newline at end of file +0.13.1 \ No newline at end of file diff --git a/UnrealGDKTestGymsVersion.txt b/UnrealGDKTestGymsVersion.txt index 6515fdf9f4..ed0d9e9902 100644 --- a/UnrealGDKTestGymsVersion.txt +++ b/UnrealGDKTestGymsVersion.txt @@ -1 +1 @@ -0.13.1-rc \ No newline at end of file +0.13.1 \ No newline at end of file