Jeremy 2 anos atrás
pai
commit
62454ca01b
1 arquivos alterados com 44 adições e 0 exclusões
  1. 44 0
      Utilities/Performance.cs

+ 44 - 0
Utilities/Performance.cs

@@ -0,0 +1,44 @@
+using WingServerCommon.Log;
+
+namespace WingServerCommon.Utilities
+{
+    public class Performance : IDisposable
+    {
+        private readonly int _performanceThreshold;
+        private readonly string _message;
+        private readonly int _startTime;
+
+        public Performance(string message)
+        {
+            _performanceThreshold = 100;
+            _startTime = Environment.TickCount;
+            _message = message;
+        }
+
+        public Performance(string format, params object[] args)
+        {
+            _performanceThreshold = 100;
+            _startTime = Environment.TickCount;
+            _message = string.Format(format, args);
+        }
+
+        public Performance(int performanceThreshold, string format, params object[] args)
+        {
+            _performanceThreshold = performanceThreshold;
+            _startTime = Environment.TickCount;
+            _message = string.Format(format, args);
+        }
+
+        public void Dispose()
+        {
+            var endTime = Environment.TickCount;
+            var intervals = endTime - _startTime;
+            if (intervals > _performanceThreshold)
+            {
+                Logger.WriteLineWarn($"Perf: {_message} end, spend {intervals}ms");
+            }
+        }
+    }
+
+
+}