From 9c1e6af657298f53efa5ccb7c1b52514f9d2d409 Mon Sep 17 00:00:00 2001 From: egi Date: Sat, 30 May 2020 13:51:52 +0200 Subject: [PATCH 1/2] Remove CodeProfiler, SkyTools.Benchmark will serve the future. --- TLM/TLM/CodeProfiler.cs | 96 ----------------------------------------- TLM/TLM/TLM.csproj | 3 +- 2 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 TLM/TLM/CodeProfiler.cs diff --git a/TLM/TLM/CodeProfiler.cs b/TLM/TLM/CodeProfiler.cs deleted file mode 100644 index 2637aacf3..000000000 --- a/TLM/TLM/CodeProfiler.cs +++ /dev/null @@ -1,96 +0,0 @@ -namespace TrafficManager { -#if TRACE - using System.Collections.Generic; - using System.Diagnostics; - using System.Threading; - using ColossalFramework; - using CSUtil.Commons; - - public class CodeProfiler - : Singleton - { - private readonly Dictionary watches_ = new Dictionary(); - private readonly Dictionary intervals_ = new Dictionary(); - - internal void Start(string name1) { - Validate(name); - try { - Monitor.Enter(watches_); - watches_[name].Start(); - } finally { - Monitor.Exit(watches_); - } - } - - internal void Stop(string name) { - Validate(name); - try { - Monitor.Enter(watches_); - watches_[name].Stop(); - ++intervals_[name]; - } finally { - Monitor.Exit(watches_); - } - } - - internal void Reset(string name) { - Validate(name); - try { - Monitor.Enter(watches_); - watches_[name].Reset(); - } finally { - Monitor.Exit(watches_); - } - } - - internal ulong ElapsedNano(string name) { - Validate(name); - try { - Monitor.Enter(watches_); - return (ulong)(watches_[name].Elapsed.TotalMilliseconds * 1000d * 1000d); - } finally { - Monitor.Exit(watches_); - } - } - - private void Validate(string name) { - try { - Monitor.Enter(watches_); - if (!watches_.ContainsKey(name)) { - watches_[name] = new Stopwatch(); - intervals_[name] = 0; - } - } finally { - Monitor.Exit(watches_); - } - } - - internal void OnLevelUnloading() { - try { - Monitor.Enter(watches_); - - foreach (KeyValuePair we in watches_) { - Log._DebugFormat( - "Stopwatch {0}: Total elapsed ns: {1} ms: {2} s: {3} min: {4} h: {5} " + - "intervals: {6} avg. ns: {7}", - we.Key, - ElapsedNano(we.Key), - ElapsedNano(we.Key) / 1000u / 1000u, - ElapsedNano(we.Key) / 1000u / 1000u / 1000u, - ElapsedNano(we.Key) / 1000u / 1000u / 1000u / 60u, - ElapsedNano(we.Key) / 1000u / 1000u / 1000u / 60u / 60u, - intervals_[we.Key], - intervals_[we.Key] > 0 - ? (string.Empty + (ElapsedNano(we.Key) / intervals_[we.Key])) - : "n/a"); - } - - watches_.Clear(); - intervals_.Clear(); - } finally { - Monitor.Exit(watches_); - } - } - } -#endif -} \ No newline at end of file diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index 98264eff5..1b5e487cb 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -1,4 +1,4 @@ - + @@ -138,7 +138,6 @@ Properties\SharedAssemblyInfo.cs - From 3663cf8329ba09419973abaef6890f79652d90ba Mon Sep 17 00:00:00 2001 From: egi Date: Sat, 30 May 2020 17:55:29 +0200 Subject: [PATCH 2/2] Remove CodeProfiler cleanup --- TLM/TLM/LoadingExtension.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/TLM/TLM/LoadingExtension.cs b/TLM/TLM/LoadingExtension.cs index 84530a505..d370a07b7 100644 --- a/TLM/TLM/LoadingExtension.cs +++ b/TLM/TLM/LoadingExtension.cs @@ -150,10 +150,6 @@ void Destroy() where T : MonoBehaviour { ModUI.SetSingletonInstance(null); Log._Debug("removed UIBase instance."); } - -#if TRACE - Singleton.instance.OnLevelUnloading(); -#endif } catch (Exception e) { Log.Error("Exception unloading mod. " + e.Message);