From 708c137c68e7c6b9edc59d711ed50b42bd1688fd Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 12 Sep 2024 03:24:06 +0800 Subject: [PATCH 1/3] update debug service --- src/DebugUtils/EcsDebug.cs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/DebugUtils/EcsDebug.cs b/src/DebugUtils/EcsDebug.cs index 6742a91..0356dcc 100644 --- a/src/DebugUtils/EcsDebug.cs +++ b/src/DebugUtils/EcsDebug.cs @@ -143,6 +143,7 @@ namespace DCFApixels.DragonECS Name = name; ID = iD; } + public override string ToString() { return this.AutoToString(); } } public IEnumerable MarkerInfos { @@ -167,14 +168,15 @@ namespace DCFApixels.DragonECS { var oldService = _instance; _instance = service; - - foreach (var info in oldService.MarkerInfos) - { - service._idDispenser.Use(info.ID); - service._nameIdTable.TryAdd(info.Name, info.ID); - service.OnNewProfilerMark(info.ID, info.Name); + if(_instance != null) + { //TODO Так, всеже треды влияют друг на друга, скоерее всего проблема в использовании _nameIdTable + foreach (var info in oldService.MarkerInfos) + { + service._idDispenser.Use(info.ID); + service._nameIdTable.TryAdd(info.Name, info.ID); + service.OnNewProfilerMark(info.ID, info.Name); + } } - service.OnServiceSetup(oldService); OnServiceChanged(service); } @@ -263,6 +265,10 @@ namespace DCFApixels.DragonECS Name = name; ID = id; } + public override string ToString() + { + return this.AutoToString(); + } } private MarkerData[] _stopwatchs; [ThreadStatic] @@ -318,10 +324,10 @@ namespace DCFApixels.DragonECS var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkGray; - _stopwatchs[id].stopwatch.Start(); + _stopwatchs[id].Stopwatch.Start(); Console.Write(PROFILER_MARKER_CACHE); - Console.Write(_stopwatchs[id].name); + Console.Write(_stopwatchs[id].Name); Console.WriteLine("> "); Console.ForegroundColor = color; @@ -332,13 +338,13 @@ namespace DCFApixels.DragonECS #if ((DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_DEBUGGER) && !UNITY_5_3_OR_NEWER var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkGray; - _stopwatchs[id].stopwatch.Stop(); - var time = _stopwatchs[id].stopwatch.Elapsed; - _stopwatchs[id].stopwatch.Reset(); + _stopwatchs[id].Stopwatch.Stop(); + var time = _stopwatchs[id].Stopwatch.Elapsed; + _stopwatchs[id].Stopwatch.Reset(); Console.Write(PROFILER_MARKER_CACHE); Console.Write("> "); - Console.Write(_stopwatchs[id].name); + Console.Write(_stopwatchs[id].Name); Console.Write(" s:"); int written = 0; From 8613dc3321b9978a4f2f119c37f779d1212d5ec8 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 12 Sep 2024 04:05:15 +0800 Subject: [PATCH 2/3] fix debug service --- src/DebugUtils/EcsDebug.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/DebugUtils/EcsDebug.cs b/src/DebugUtils/EcsDebug.cs index 0356dcc..d87ac8f 100644 --- a/src/DebugUtils/EcsDebug.cs +++ b/src/DebugUtils/EcsDebug.cs @@ -12,7 +12,10 @@ namespace DCFApixels.DragonECS { public readonly int id; internal EcsProfilerMarker(int id) { this.id = id; } - public EcsProfilerMarker(string name) { id = DebugService.Instance.RegisterMark(name); } + public EcsProfilerMarker(string name) + { + id = DebugService.Instance.RegisterMark(name); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Begin() { DebugService.Instance.ProfilerMarkBegin(id); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -169,7 +172,7 @@ namespace DCFApixels.DragonECS var oldService = _instance; _instance = service; if(_instance != null) - { //TODO Так, всеже треды влияют друг на друга, скоерее всего проблема в использовании _nameIdTable + { //TODO Так, всеже треды влияют друг на друга, скоерее всего проблема в использовании _nameIdTable/ Так вроде пофиксил, но не понял как конкретно foreach (var info in oldService.MarkerInfos) { service._idDispenser.Use(info.ID); @@ -187,7 +190,7 @@ namespace DCFApixels.DragonECS public static Action OnServiceChanged = delegate { }; private IdDispenser _idDispenser = new IdDispenser(16, 0); - private ConcurrentDictionary _nameIdTable = new ConcurrentDictionary(); + private Dictionary _nameIdTable = new Dictionary(); public abstract void Print(string tag, object v); public abstract void Break(); public int RegisterMark(string name) @@ -197,11 +200,14 @@ namespace DCFApixels.DragonECS { lock (_lock) { - id = _idDispenser.UseFree(); - _nameIdTable.TryAdd(name, id); + if (!_nameIdTable.TryGetValue(name, out id)) + { + id = _idDispenser.UseFree(); + _nameIdTable.Add(name, id); + OnNewProfilerMark(id, name); + } } } - OnNewProfilerMark(id, name); return id; } public void DeleteMark(string name) @@ -210,7 +216,7 @@ namespace DCFApixels.DragonECS { int id = _nameIdTable[name]; //TODO проверить TryRemove - _nameIdTable.TryRemove(name, out id); + _nameIdTable.Remove(name); _idDispenser.Release(id); OnDelProfilerMark(id); } From 856082d1aaae7e8f85ae4b8eac0eb45c2f2dd0b3 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 12 Sep 2024 04:05:43 +0800 Subject: [PATCH 3/3] Update EcsDebug.cs --- src/DebugUtils/EcsDebug.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/DebugUtils/EcsDebug.cs b/src/DebugUtils/EcsDebug.cs index d87ac8f..e129f84 100644 --- a/src/DebugUtils/EcsDebug.cs +++ b/src/DebugUtils/EcsDebug.cs @@ -1,6 +1,5 @@ using DCFApixels.DragonECS.Internal; using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -215,7 +214,6 @@ namespace DCFApixels.DragonECS lock (_lock) { int id = _nameIdTable[name]; - //TODO проверить TryRemove _nameIdTable.Remove(name); _idDispenser.Release(id); OnDelProfilerMark(id);