diff options
author | Drachenkaetzchen <felicia@drachenkatze.org> | 2020-01-15 19:08:50 +0100 |
---|---|---|
committer | Drachenkaetzchen <felicia@drachenkatze.org> | 2020-01-15 19:08:50 +0100 |
commit | 84973ce5727ad20fe8b8ba4f89e59c8b754f799e (patch) | |
tree | 90c7f55d3a42ec73afdf86cebd8ae980ec3c1c4d /src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs | |
parent | 238b5db4f7f2f05e8967cc5eda761733d4bf35b4 (diff) | |
download | SMAPI-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.cs | 20 |
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() { |