From 1b905205a3073c56e29c46b5e57c4a9cb2ca5832 Mon Sep 17 00:00:00 2001 From: Drachenkaetzchen Date: Tue, 21 Jan 2020 12:20:06 +0100 Subject: Added commands to enable and disable performance counters. Peak is now using the default interval --- .../PerformanceCounterCollection.cs | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/SMAPI/Framework/PerformanceCounter/PerformanceCounterCollection.cs') 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()); } + /// Returns the average execution time for all non-game internal sources. + /// The interval for which to get the average, relative to now + /// The average execution time in milliseconds + public double GetModsAverageExecutionTime(TimeSpan interval) + { + return this.PerformanceCounters.Where(p => + p.Key != Constants.GamePerformanceCounterName).Sum(p => p.Value.GetAverage(interval)); + } + /// Returns the overall average execution time. /// The average execution time in milliseconds public double GetAverageExecutionTime() @@ -89,6 +98,14 @@ namespace StardewModdingAPI.Framework.PerformanceCounter return this.PerformanceCounters.Sum(p => p.Value.GetAverage()); } + /// Returns the overall average execution time. + /// The interval for which to get the average, relative to now + /// The average execution time in milliseconds + public double GetAverageExecutionTime(TimeSpan interval) + { + return this.PerformanceCounters.Sum(p => p.Value.GetAverage(interval)); + } + /// Returns the average execution time for game-internal sources. /// The average execution time in milliseconds public double GetGameAverageExecutionTime() @@ -99,6 +116,20 @@ namespace StardewModdingAPI.Framework.PerformanceCounter return 0; } + /// Returns the average execution time for game-internal sources. + /// The average execution time in milliseconds + public double GetGameAverageExecutionTime(TimeSpan interval) + { + if (this.PerformanceCounters.TryGetValue(Constants.GamePerformanceCounterName, out PerformanceCounter gameExecTime)) + return gameExecTime.GetAverage(interval); + + return 0; + } + + /// Returns the peak execution time + /// The interval for which to get the peak, relative to + /// The DateTime which the is relative to, or DateTime.Now if not given + /// The peak execution time public double GetPeakExecutionTime(TimeSpan range, DateTime? relativeTo = null) { if (this.PeakInvocations.IsEmpty) -- cgit