Skip to content

Commit

Permalink
Introduce Profiler Marker for each type of generic system (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-dcl authored Sep 2, 2024
1 parent dbe1f6f commit 1ad4ab5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Explorer/Assets/Scripts/ECS/Abstract/BaseUnityLoopSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Arch.SystemGroups.Metadata;
using DCL.Diagnostics;
using System;
using System.Linq;
using UnityEngine.Profiling;

namespace ECS.Abstract
Expand All @@ -14,20 +15,39 @@ public abstract class BaseUnityLoopSystem : PlayerLoopSystem<World>
{
private readonly CustomSampler updateSampler;

private string cachedCategory;
/// <summary>
/// Individual profiler marker for each combination of generic arguments
/// </summary>
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)
{
try
{
updateSampler.Begin();

genericUpdateSampler?.Begin();

Update(t);

genericUpdateSampler?.End();

updateSampler.End();

}
catch (Exception e)
{
Expand All @@ -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<LogCategoryAttribute>()) == null)
metadata = metadata.GroupMetadata;
Expand Down

0 comments on commit 1ad4ab5

Please sign in to comment.