1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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");
- }
- }
- }
- }
|