diff --git a/ECS/EnginesRoot.cs b/ECS/EnginesRoot.cs index 6d43243..dfec6e4 100644 --- a/ECS/EnginesRoot.cs +++ b/ECS/EnginesRoot.cs @@ -46,8 +46,13 @@ namespace Svelto.ECS go.AddComponent().OnTick += SubmitNodes; #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR - GameObject debugEngineObject = new GameObject("Engine Debugger"); - debugEngineObject.gameObject.AddComponent(); + var debugEngineObject = GameObject.Find("Svelto.ECS.Profiler"); + if (debugEngineObject == null) + { + debugEngineObject = new GameObject("Svelto.ECS.Profiler"); + debugEngineObject.gameObject.AddComponent(); + UnityEngine.Object.DontDestroyOnLoad(debugEngineObject); + } #endif } diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs index 94683c2..f613f61 100644 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs +++ b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs @@ -47,7 +47,6 @@ namespace Svelto.ECS.Profiler EngineInfo[] engines = new EngineInfo[engineProfilerBehaviour.engines.Count]; engineProfilerBehaviour.engines.CopyTo(engines, 0); - DrawEnginesMonitor(engines); DrawEngineList(engineProfilerBehaviour, engines); EditorUtility.SetDirty(target); } @@ -84,20 +83,6 @@ namespace Svelto.ECS.Profiler } ProfilerEditorLayout.EndHorizontal(); - _showTickEngines = EditorGUILayout.Foldout(_showTickEngines, "Engines Ticks"); - if (_showTickEngines && ShouldShowSystems(engines)) - { - ProfilerEditorLayout.BeginVerticalBox(); - { - var systemsDrawn = DrawUpdateEngineInfos(engines); - if (systemsDrawn == 0) - { - EditorGUILayout.LabelField(string.Empty); - } - } - ProfilerEditorLayout.EndVertical(); - } - _showAddEngines = EditorGUILayout.Foldout(_showAddEngines, "Engines Add"); if (_showAddEngines && ShouldShowSystems(engines)) { @@ -129,94 +114,6 @@ namespace Svelto.ECS.Profiler ProfilerEditorLayout.EndVertical(); } - void DrawEnginesMonitor(EngineInfo[] engines) - { - if (_enginesMonitor == null) - { - _enginesMonitor = new EnginesMonitor(SYSTEM_MONITOR_DATA_LENGTH); - _engineMonitorData = new Queue(new float[SYSTEM_MONITOR_DATA_LENGTH]); - if (EditorApplication.update != Repaint) - { - EditorApplication.update += Repaint; - } - } - double totalDuration = 0; - for (int i = 0; i < engines.Length; i++) - { - totalDuration += engines[i].lastUpdateDuration; - } - - ProfilerEditorLayout.BeginVerticalBox(); - { - EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel); - - ProfilerEditorLayout.BeginHorizontal(); - { - EditorGUILayout.LabelField("Total", totalDuration.ToString()); - } - ProfilerEditorLayout.EndHorizontal(); - - ProfilerEditorLayout.BeginHorizontal(); - { - _axisUpperBounds = EditorGUILayout.FloatField("Axis Upper Bounds", _axisUpperBounds); - } - ProfilerEditorLayout.EndHorizontal(); - - if (!EditorApplication.isPaused) - { - if (_engineMonitorData.Count >= SYSTEM_MONITOR_DATA_LENGTH) - { - _engineMonitorData.Dequeue(); - } - - _engineMonitorData.Enqueue((float) totalDuration); - } - _enginesMonitor.Draw(_engineMonitorData.ToArray(), 80f, _axisUpperBounds); - } - ProfilerEditorLayout.EndVertical(); - } - - int DrawUpdateEngineInfos(EngineInfo[] engines) - { - if (_sortingOption != SORTING_OPTIONS.NONE) - { - SortUpdateEngines(engines); - } - - string title = - updateTitle.FastConcat(lateUpdateTitle) - .FastConcat(fixedupdateTitle) - .FastConcat(minTitle) - .FastConcat(maxTitle); - EditorGUILayout.LabelField("Engine Name", title, EditorStyles.boldLabel); - - int enginesDrawn = 0; - for (int i = 0; i < engines.Length; i++) - { - EngineInfo engineInfo = engines[i]; - - if (engineInfo.engineName.ToLower().Contains(_systemNameSearchTerm.ToLower())) - { - ProfilerEditorLayout.BeginHorizontal(); - { - var avg = string.Format("{0:0.000}", engineInfo.averageUpdateDuration).PadRight(15); - var avgLate = string.Format("{0:0.000}", engineInfo.averageLateUpdateDuration).PadRight(15); - var avgFixed = string.Format("{0:0.000}", engineInfo.averageFixedUpdateDuration).PadRight(15); - var min = string.Format("{0:0.000}", engineInfo.minUpdateDuration).PadRight(15); - var max = string.Format("{0:0.000}", engineInfo.maxUpdateDuration); - - string output = avg.FastConcat(avgLate).FastConcat(avgFixed).FastConcat(min).FastConcat(max); - - EditorGUILayout.LabelField(engineInfo.engineName, output, GetEngineStyle()); - } - ProfilerEditorLayout.EndHorizontal(); - - enginesDrawn += 1; - } - } - return enginesDrawn; - } - int DrawAddEngineInfos(EngineInfo[] engines) { if (_sortingOption != SORTING_OPTIONS.NONE) @@ -303,28 +200,6 @@ namespace Svelto.ECS.Profiler } #region Sorting Engines - void SortUpdateEngines(EngineInfo[] engines) - { - switch (_sortingOption) - { - case SORTING_OPTIONS.AVERAGE: - Array.Sort(engines, - (engine1, engine2) => engine2.averageUpdateDuration.CompareTo(engine1.averageUpdateDuration)); - break; - case SORTING_OPTIONS.MIN: - Array.Sort(engines, - (engine1, engine2) => engine2.minUpdateDuration.CompareTo(engine1.minUpdateDuration)); - break; - case SORTING_OPTIONS.MAX: - Array.Sort(engines, - (engine1, engine2) => engine2.maxUpdateDuration.CompareTo(engine1.maxUpdateDuration)); - break; - case SORTING_OPTIONS.NAME: - Array.Sort(engines, StringComparer.InvariantCulture); - break; - } - } - void SortAddEngines(EngineInfo[] engines) { switch (_sortingOption) @@ -342,7 +217,8 @@ namespace Svelto.ECS.Profiler (engine1, engine2) => engine2.maxAddDuration.CompareTo(engine1.maxAddDuration)); break; case SORTING_OPTIONS.NAME: - Array.Sort(engines, StringComparer.InvariantCulture); + Array.Sort(engines, + (engine1, engine2) => String.Compare(engine1.engineName, engine2.engineName, StringComparison.Ordinal)); break; } } @@ -364,7 +240,8 @@ namespace Svelto.ECS.Profiler (engine1, engine2) => engine2.maxRemoveDuration.CompareTo(engine1.maxRemoveDuration)); break; case SORTING_OPTIONS.NAME: - Array.Sort(engines, StringComparer.InvariantCulture); + Array.Sort(engines, + (engine1, engine2) => String.Compare(engine1.engineName, engine2.engineName, StringComparison.Ordinal)); break; } } diff --git a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta index 77f5e52..489305b 100644 --- a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta +++ b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1c9cf391ddfdd92429ce90eeb73a936a +guid: 3e961e5c8cc40064fa25092d835d1a80 timeCreated: 1462527509 licenseType: Pro MonoImporter: diff --git a/ECS/Profiler/EngineProfiler.cs b/ECS/Profiler/EngineProfiler.cs index 75e30e1..f055f3d 100644 --- a/ECS/Profiler/EngineProfiler.cs +++ b/ECS/Profiler/EngineProfiler.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using UnityEngine; -using Svelto.Ticker.Legacy; //This profiler is based on the Entitas Visual Debugging tool //https://github.com/sschmid/Entitas-CSharp @@ -42,69 +40,6 @@ namespace Svelto.ECS.Profiler } } - public static void MonitorUpdateDuration(ITickable tickable) - { - if (tickable is INodeEngine) - { - EngineInfo info; - if (engineInfos.TryGetValue((tickable as INodeEngine).GetType(), out info)) - { - _stopwatch.Reset(); - _stopwatch.Start(); - tickable.Tick(Time.deltaTime); - _stopwatch.Stop(); - - info.AddUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds); - } - } - else - { - tickable.Tick(Time.deltaTime); - } - } - - public static void MonitorUpdateDuration(IPhysicallyTickable tickable) - { - if (tickable is INodeEngine) - { - EngineInfo info; - if (engineInfos.TryGetValue((tickable as INodeEngine).GetType(), out info)) - { - _stopwatch.Reset(); - _stopwatch.Start(); - tickable.PhysicsTick(Time.fixedDeltaTime); - _stopwatch.Stop(); - - info.AddFixedUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds); - } - } - else - { - tickable.PhysicsTick(Time.fixedDeltaTime); - } - } - - public static void MonitorUpdateDuration(ILateTickable tickable) - { - if (tickable is INodeEngine) - { - EngineInfo info; - if (engineInfos.TryGetValue((tickable as INodeEngine).GetType(), out info)) - { - _stopwatch.Reset(); - _stopwatch.Start(); - tickable.LateTick(Time.deltaTime); - _stopwatch.Stop(); - - info.AddLateUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds); - } - } - else - { - tickable.LateTick(Time.deltaTime); - } - } - public static void AddEngine(IEngine engine) { if (engineInfos.ContainsKey(engine.GetType()) == false) diff --git a/ECS/note.txt b/ECS/note.txt index a55d53b..c041193 100644 --- a/ECS/note.txt +++ b/ECS/note.txt @@ -1,7 +1,7 @@ systems do not hold component data, but only system states systems cannot be injected systems are SRP and OCP -systems communicates between component, mediators, producer/consumer, Svelto.ECS.Example.Observers. producer/consumer and observers must be defined in the layer of the engine. +systems communicates between component, mediators, producer/consumer, observers. producer/consumer and observers must be defined in the layer of the engine. systems can have injected dependencies components don't have logic