summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs
diff options
context:
space:
mode:
authorDrachenkaetzchen <felicia@drachenkatze.org>2020-01-15 19:08:50 +0100
committerDrachenkaetzchen <felicia@drachenkatze.org>2020-01-15 19:08:50 +0100
commit84973ce5727ad20fe8b8ba4f89e59c8b754f799e (patch)
tree90c7f55d3a42ec73afdf86cebd8ae980ec3c1c4d /src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs
parent238b5db4f7f2f05e8967cc5eda761733d4bf35b4 (diff)
downloadSMAPI-84973ce5727ad20fe8b8ba4f89e59c8b754f799e.tar.gz
SMAPI-84973ce5727ad20fe8b8ba4f89e59c8b754f799e.tar.bz2
SMAPI-84973ce5727ad20fe8b8ba4f89e59c8b754f799e.zip
Added peak execution time over the last 60 seconds
Diffstat (limited to 'src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs')
-rw-r--r--src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs
index 33ddde2f..3d902e16 100644
--- a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs
+++ b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs
@@ -68,6 +68,26 @@ namespace StardewModdingAPI.Framework.PerformanceCounter
return this.PeakPerformanceCounterEntry;
}
+ /// <summary>Returns the peak entry.</summary>
+ /// <returns>The peak entry.</returns>
+ public PerformanceCounterEntry? GetPeak(TimeSpan range, DateTime? relativeTo = null)
+ {
+ if (this._counter.IsEmpty)
+ return null;
+
+ if (relativeTo == null)
+ relativeTo = DateTime.UtcNow;
+
+ DateTime start = relativeTo.Value.Subtract(range);
+
+ var entries = this._counter.Where(x => (x.EventTime >= start) && (x.EventTime <= relativeTo)).ToList();
+
+ if (!entries.Any())
+ return null;
+
+ return entries.OrderByDescending(x => x.ElapsedMilliseconds).First();
+ }
+
/// <summary>Resets the peak entry.</summary>
public void ResetPeak()
{