diff options
Diffstat (limited to 'src/SMAPI/Framework/PerformanceCounter')
-rw-r--r-- | src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/PerformanceCounter/PerformanceCounterManager.cs | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs index b2ec4c90..33ddde2f 100644 --- a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs +++ b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs @@ -114,6 +114,10 @@ namespace StardewModdingAPI.Framework.PerformanceCounter DateTime start = relativeTo.Value.Subtract(range); var entries = this._counter.Where(x => (x.EventTime >= start) && (x.EventTime <= relativeTo)); + + if (!entries.Any()) + return 0; + return entries.Average(x => x.ElapsedMilliseconds); } } diff --git a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterManager.cs b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterManager.cs index d8f1f172..49720431 100644 --- a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterManager.cs +++ b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterManager.cs @@ -20,6 +20,9 @@ namespace StardewModdingAPI.Framework.PerformanceCounter /// <summary>The invocation stopwatch.</summary> private readonly Stopwatch InvocationStopwatch = new Stopwatch(); + /// <summary>Specifies if alerts should be paused.</summary> + public bool PauseAlerts { get; set; } + /// <summary>Constructs a performance counter manager.</summary> /// <param name="monitor">The monitor for output logging.</param> public PerformanceCounterManager(IMonitor monitor) @@ -144,7 +147,8 @@ namespace StardewModdingAPI.Framework.PerformanceCounter /// <param name="entry">The alert to add.</param> public void AddAlert(AlertEntry entry) { - this.Alerts.Add(entry); + if (!this.PauseAlerts) + this.Alerts.Add(entry); } /// <summary>Initialized the default performance counter collections.</summary> |