diff --git a/Explorer/Assets/Scripts/ECS/Abstract/BaseUnityLoopSystem.cs b/Explorer/Assets/Scripts/ECS/Abstract/BaseUnityLoopSystem.cs index 2f78ef6323..01099f07e2 100644 --- a/Explorer/Assets/Scripts/ECS/Abstract/BaseUnityLoopSystem.cs +++ b/Explorer/Assets/Scripts/ECS/Abstract/BaseUnityLoopSystem.cs @@ -3,6 +3,7 @@ using Arch.SystemGroups.Metadata; using DCL.Diagnostics; using System; +using System.Linq; using UnityEngine.Profiling; namespace ECS.Abstract @@ -14,11 +15,23 @@ public abstract class BaseUnityLoopSystem : PlayerLoopSystem { private readonly CustomSampler updateSampler; - private string cachedCategory; + /// + /// Individual profiler marker for each combination of generic arguments + /// + private readonly CustomSampler? genericUpdateSampler; + + private string? cachedCategory; protected BaseUnityLoopSystem(World world) : base(world) { updateSampler = CustomSampler.Create($"{GetType().Name}.Update"); + genericUpdateSampler = CreateGenericSamplerIfRequired(); + } + + private CustomSampler? CreateGenericSamplerIfRequired() + { + Type type = GetType(); + return type.IsGenericType ? CustomSampler.Create($"{type.Name.Remove(type.Name.Length - 2)}<{string.Join(", ", type.GenericTypeArguments.Select(x => x.Name))}>.Update") : null; } public sealed override void Update(in float t) @@ -26,8 +39,15 @@ public sealed override void Update(in float t) try { updateSampler.Begin(); + + genericUpdateSampler?.Begin(); + Update(t); + + genericUpdateSampler?.End(); + updateSampler.End(); + } catch (Exception e) { @@ -47,7 +67,7 @@ protected internal string GetReportCategory() return cachedCategory; AttributesInfoBase metadata = GetMetadataInternal(); - LogCategoryAttribute logCategory = null; + LogCategoryAttribute? logCategory = null; while (metadata != null && (logCategory = metadata.GetAttribute()) == null) metadata = metadata.GroupMetadata;