Browse Source

Fix Engine Profiler

tags/Rel2b
sebas77 6 years ago
parent
commit
2428d7dd16
4 changed files with 32 additions and 55 deletions
  1. +11
    -4
      Svelto.ECS/ECS/EnginesRootEngines.cs
  2. +1
    -48
      Svelto.ECS/ECS/Profiler/EngineInfo.cs
  3. +4
    -3
      Svelto.ECS/ECS/Profiler/EngineProfiler.cs
  4. +16
    -0
      Svelto.ECS/ECS/Profiler/EngineProfilerBehaviour.cs

+ 11
- 4
Svelto.ECS/ECS/EnginesRootEngines.cs View File

@@ -14,6 +14,17 @@ namespace Svelto.ECS
{
public partial class EnginesRoot : IDisposable
{
#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
/// <summary>
/// I still need to find a good solution for this. Need to move somewhere else
/// </summary>
static EnginesRoot()
{
UnityEngine.GameObject debugEngineObject = new UnityEngine.GameObject("Svelto.ECS.Profiler");
debugEngineObject.gameObject.AddComponent<EngineProfilerBehaviour>();
UnityEngine.GameObject.DontDestroyOnLoad(debugEngineObject);
}
#endif
/// <summary>
/// Engines root contextualize your engines and entities. You don't need to limit yourself to one EngineRoot
/// as multiple engines root could promote separation of scopes. The EntitySubmissionScheduler checks
@@ -40,10 +51,6 @@ namespace Svelto.ECS

_scheduler = entityViewScheduler;
_scheduler.Schedule(new WeakAction(SubmitEntityViews));
#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
UnityEngine.GameObject debugEngineObject = new UnityEngine.GameObject("Engine Debugger");
debugEngineObject.gameObject.AddComponent<EngineProfilerBehaviour>();
#endif
}

public void AddEngine(IEngine engine)


+ 1
- 48
Svelto.ECS/ECS/Profiler/EngineInfo.cs View File

@@ -40,27 +40,16 @@ namespace Svelto.ECS.Profiler
double _maxRemoveDuration;
int _entityViewsRemovedCount;

public IEngine engine { get { return _engine; } }
public string engineName { get { return _engineName; } }
public Type engineType { get { return _engineType; } }

public double lastUpdateDuration { get { return _lastUpdateDuration[(int) UpdateType.Update]; } }
public double lastFixedUpdateDuration { get { return _lastUpdateDuration[(int)UpdateType.LateUpdate]; } }
public double lastLateUpdateDuration { get { return _lastUpdateDuration[(int)UpdateType.FixedUpdate]; } }

public double minAddDuration { get { return _minAddDuration; } }
public double minRemoveDuration { get { return _minRemoveDuration; } }
public double minUpdateDuration { get { return _minUpdateDuration[(int)UpdateType.Update]; } }

public double maxAddDuration { get { return _maxAddDuration; } }
public double maxRemoveDuration { get { return _maxRemoveDuration; } }
public double maxUpdateDuration { get { return _maxUpdateDuration[(int)UpdateType.Update]; } }

public double averageAddDuration { get { return _entityViewsAddedCount == 0 ? 0 : _accumulatedAddDuration / _entityViewsAddedCount; } }
public double averageRemoveDuration { get { return _entityViewsRemovedCount == 0 ? 0 : _accumulatedRemoveDuration / _entityViewsRemovedCount; } }
public double averageUpdateDuration { get { return _updateFrameTimes[(int)UpdateType.Update].Count == 0 ? 0 : _accumulatedUpdateDuration[(int)UpdateType.Update] / _updateFrameTimes[(int)UpdateType.Update].Count; } }
public double averageLateUpdateDuration { get { return _updateFrameTimes[(int)UpdateType.LateUpdate].Count == 0 ? 0 : _accumulatedUpdateDuration[(int)UpdateType.LateUpdate] / _updateFrameTimes[(int)UpdateType.LateUpdate].Count; } }
public double averageFixedUpdateDuration { get { return _updateFrameTimes[(int)UpdateType.FixedUpdate].Count == 0 ? 0 : _accumulatedUpdateDuration[(int)UpdateType.FixedUpdate] / _updateFrameTimes[(int)UpdateType.FixedUpdate].Count; } }

public EngineInfo(IEngine engine)
{
@@ -79,42 +68,6 @@ namespace Svelto.ECS.Profiler
ResetDurations();
}

public void AddUpdateDuration(double updateDuration)
{
AddUpdateDurationForType(updateDuration, (int)UpdateType.Update);
}

public void AddLateUpdateDuration(double updateDuration)
{
AddUpdateDurationForType(updateDuration, (int)UpdateType.LateUpdate);
}

public void AddFixedUpdateDuration(double updateDuration)
{
AddUpdateDurationForType(updateDuration, (int)UpdateType.FixedUpdate);
}

void AddUpdateDurationForType(double updateDuration, int updateType)
{
if (updateDuration < _minUpdateDuration[updateType] || _minUpdateDuration[updateType] == 0)
{
_minUpdateDuration[updateType] = updateDuration;
}
if (updateDuration > _maxUpdateDuration[updateType])
{
_maxUpdateDuration[updateType] = updateDuration;
}

if (_updateFrameTimes[updateType].Count == NUM_FRAMES_TO_AVERAGE)
{
_accumulatedUpdateDuration[updateType] -= _updateFrameTimes[updateType].Dequeue();
}

_accumulatedUpdateDuration[updateType] += updateDuration;
_updateFrameTimes[updateType].Enqueue(updateDuration);
_lastUpdateDuration[updateType] = updateDuration;
}

public void AddAddDuration(double duration)
{
if (duration < _minAddDuration || _minAddDuration == 0)


+ 4
- 3
Svelto.ECS/ECS/Profiler/EngineProfiler.cs View File

@@ -19,9 +19,9 @@ namespace Svelto.ECS.Profiler
{
_stopwatch.Start();
engine.Add(entityView);
_stopwatch.Reset();

_stopwatch.Stop();
info.AddAddDuration(_stopwatch.Elapsed.TotalMilliseconds);
_stopwatch.Reset();
}
}

@@ -32,9 +32,10 @@ namespace Svelto.ECS.Profiler
{
_stopwatch.Start();
engine.Remove(entityView);
_stopwatch.Reset();
_stopwatch.Stop();

info.AddRemoveDuration(_stopwatch.Elapsed.TotalMilliseconds);
_stopwatch.Reset();
}
}



+ 16
- 0
Svelto.ECS/ECS/Profiler/EngineProfilerBehaviour.cs View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

//This profiler is based on the Entitas Visual Debugging tool
//https://github.com/sschmid/Entitas-CSharp
@@ -16,6 +17,21 @@ namespace Svelto.ECS.Profiler
{
EngineProfiler.ResetDurations();
}

void OnEnable()
{
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}

void OnDisable()
{
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
}

void OnLevelFinishedLoading(Scene arg0, LoadSceneMode arg1)
{
ResetDurations();
}
}
}
#endif

Loading…
Cancel
Save