From a86b71899ec52c44ddc6c3018e8cc5e9d7ff4d62 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Thu, 27 Dec 2018 18:27:57 -0500 Subject: Add GPL modules --- MediaBrowser.Controller/Library/Profiler.cs | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 MediaBrowser.Controller/Library/Profiler.cs (limited to 'MediaBrowser.Controller/Library/Profiler.cs') diff --git a/MediaBrowser.Controller/Library/Profiler.cs b/MediaBrowser.Controller/Library/Profiler.cs new file mode 100644 index 000000000..3957c3020 --- /dev/null +++ b/MediaBrowser.Controller/Library/Profiler.cs @@ -0,0 +1,76 @@ +using MediaBrowser.Model.Logging; +using System; +using System.Diagnostics; + +namespace MediaBrowser.Controller.Library +{ + /// + /// Class Profiler + /// + public class Profiler : IDisposable + { + /// + /// The name + /// + readonly string _name; + /// + /// The stopwatch + /// + readonly Stopwatch _stopwatch; + + /// + /// The _logger + /// + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// The logger. + public Profiler(string name, ILogger logger) + { + this._name = name; + + _logger = logger; + + _stopwatch = new Stopwatch(); + _stopwatch.Start(); + } + #region IDisposable Members + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool dispose) + { + if (dispose) + { + _stopwatch.Stop(); + string message; + if (_stopwatch.ElapsedMilliseconds > 300000) + { + message = string.Format("{0} took {1} minutes.", + _name, ((float)_stopwatch.ElapsedMilliseconds / 60000).ToString("F")); + } + else + { + message = string.Format("{0} took {1} seconds.", + _name, ((float)_stopwatch.ElapsedMilliseconds / 1000).ToString("#0.000")); + } + _logger.Info(message); + } + } + + #endregion + } +} -- cgit v1.2.3