diff options
author | Drachenkaetzchen <felicia@drachenkatze.org> | 2020-01-21 12:20:06 +0100 |
---|---|---|
committer | Drachenkaetzchen <felicia@drachenkatze.org> | 2020-01-21 12:20:06 +0100 |
commit | 1b905205a3073c56e29c46b5e57c4a9cb2ca5832 (patch) | |
tree | 677358e51b8b3a8ba37ffd480f4a12778a2cafd9 /src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs | |
parent | 84973ce5727ad20fe8b8ba4f89e59c8b754f799e (diff) | |
download | SMAPI-1b905205a3073c56e29c46b5e57c4a9cb2ca5832.tar.gz SMAPI-1b905205a3073c56e29c46b5e57c4a9cb2ca5832.tar.bz2 SMAPI-1b905205a3073c56e29c46b5e57c4a9cb2ca5832.zip |
Added commands to enable and disable performance counters. Peak is now using the default interval
Diffstat (limited to 'src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs')
-rw-r--r-- | src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs index fe14ebf8..f469eceb 100644 --- a/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs +++ b/src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs @@ -82,6 +82,15 @@ namespace StardewModdingAPI.Framework.PerformanceCounter p.Key != Constants.GamePerformanceCounterName).Sum(p => p.Value.GetAverage()); } + /// <summary>Returns the average execution time for all non-game internal sources.</summary> + /// <param name="interval">The interval for which to get the average, relative to now</param> + /// <returns>The average execution time in milliseconds</returns> + public double GetModsAverageExecutionTime(TimeSpan interval) + { + return this.PerformanceCounters.Where(p => + p.Key != Constants.GamePerformanceCounterName).Sum(p => p.Value.GetAverage(interval)); + } + /// <summary>Returns the overall average execution time.</summary> /// <returns>The average execution time in milliseconds</returns> public double GetAverageExecutionTime() @@ -89,6 +98,14 @@ namespace StardewModdingAPI.Framework.PerformanceCounter return this.PerformanceCounters.Sum(p => p.Value.GetAverage()); } + /// <summary>Returns the overall average execution time.</summary> + /// <param name="interval">The interval for which to get the average, relative to now</param> + /// <returns>The average execution time in milliseconds</returns> + public double GetAverageExecutionTime(TimeSpan interval) + { + return this.PerformanceCounters.Sum(p => p.Value.GetAverage(interval)); + } + /// <summary>Returns the average execution time for game-internal sources.</summary> /// <returns>The average execution time in milliseconds</returns> public double GetGameAverageExecutionTime() @@ -99,6 +116,20 @@ namespace StardewModdingAPI.Framework.PerformanceCounter return 0; } + /// <summary>Returns the average execution time for game-internal sources.</summary> + /// <returns>The average execution time in milliseconds</returns> + public double GetGameAverageExecutionTime(TimeSpan interval) + { + if (this.PerformanceCounters.TryGetValue(Constants.GamePerformanceCounterName, out PerformanceCounter gameExecTime)) + return gameExecTime.GetAverage(interval); + + return 0; + } + + /// <summary>Returns the peak execution time</summary> + /// <param name="interval">The interval for which to get the peak, relative to <paramref name="relativeTo"/></param> + /// <param name="relativeTo">The DateTime which the <paramref name="interval"/> is relative to, or DateTime.Now if not given</param> + /// <returns>The peak execution time</returns> public double GetPeakExecutionTime(TimeSpan range, DateTime? relativeTo = null) { if (this.PeakInvocations.IsEmpty) |