From fce5814bcb150c4ff105a37dfcd57f397b117e48 Mon Sep 17 00:00:00 2001 From: Drachenkaetzchen Date: Wed, 15 Jan 2020 17:43:41 +0100 Subject: Added documentation for all commands. Renamed the "monitor" command to "trigger". Method name refactoring to be more consistent. --- src/SMAPI/Framework/Events/EventManager.cs | 1 + src/SMAPI/Framework/Events/ManagedEvent.cs | 1 + src/SMAPI/Framework/PerformanceCounter/PerformanceCounter.cs | 4 ++++ src/SMAPI/Framework/PerformanceCounter/PerformanceCounterManager.cs | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs index 9c65a6cc..19a4dff8 100644 --- a/src/SMAPI/Framework/Events/EventManager.cs +++ b/src/SMAPI/Framework/Events/EventManager.cs @@ -174,6 +174,7 @@ namespace StardewModdingAPI.Framework.Events /// Construct an instance. /// Writes messages to the log. /// The mod registry with which to identify mods. + /// The performance counter manager. public EventManager(IMonitor monitor, ModRegistry modRegistry, PerformanceCounterManager performanceCounterManager) { // create shortcut initializers diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs index bba94c35..dfdd7449 100644 --- a/src/SMAPI/Framework/Events/ManagedEvent.cs +++ b/src/SMAPI/Framework/Events/ManagedEvent.cs @@ -40,6 +40,7 @@ namespace StardewModdingAPI.Framework.Events /// A human-readable name for the event. /// Writes messages to the log. /// The mod registry with which to identify mods. + /// The performance counter manager public ManagedEvent(string eventName, IMonitor monitor, ModRegistry modRegistry, PerformanceCounterManager performanceCounterManager) { this.EventName = eventName; 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 /// The invocation stopwatch. private readonly Stopwatch InvocationStopwatch = new Stopwatch(); + /// Specifies if alerts should be paused. + public bool PauseAlerts { get; set; } + /// Constructs a performance counter manager. /// The monitor for output logging. public PerformanceCounterManager(IMonitor monitor) @@ -144,7 +147,8 @@ namespace StardewModdingAPI.Framework.PerformanceCounter /// The alert to add. public void AddAlert(AlertEntry entry) { - this.Alerts.Add(entry); + if (!this.PauseAlerts) + this.Alerts.Add(entry); } /// Initialized the default performance counter collections. -- cgit