Added reset functionality

This commit is contained in:
Drachenkaetzchen 2020-01-10 14:16:00 +01:00
parent 47f626cc99
commit 8a77373b18
3 changed files with 28 additions and 2 deletions

View File

@ -25,6 +25,12 @@ namespace StardewModdingAPI.Framework.PerformanceCounter
this._counter = new CircularBuffer<PerformanceCounterEntry>(PerformanceCounter.MAX_ENTRIES); this._counter = new CircularBuffer<PerformanceCounterEntry>(PerformanceCounter.MAX_ENTRIES);
} }
public void Reset()
{
this._counter.Clear();
this.PeakPerformanceCounterEntry = null;
}
public int GetAverageCallsPerSecond() public int GetAverageCallsPerSecond()
{ {
var x = this._counter.GroupBy( var x = this._counter.GroupBy(

View File

@ -16,6 +16,22 @@ namespace StardewModdingAPI.Framework.PerformanceCounter
this.InitializePerformanceCounterEvents(); this.InitializePerformanceCounterEvents();
} }
public void Reset()
{
foreach (var performanceCounter in this.PerformanceCounterEvents)
{
this.ResetCategory(performanceCounter);
}
}
public void ResetCategory(EventPerformanceCounterCategory category)
{
foreach (var eventPerformanceCounter in category.Event.PerformanceCounters)
{
eventPerformanceCounter.Value.Reset();
}
}
private void InitializePerformanceCounterEvents() private void InitializePerformanceCounterEvents()
{ {
this.PerformanceCounterEvents = new HashSet<EventPerformanceCounterCategory>() this.PerformanceCounterEvents = new HashSet<EventPerformanceCounterCategory>()

View File

@ -498,8 +498,9 @@ namespace StardewModdingAPI.Framework
"Usage: performance_counters [name] [threshold]\n"+ "Usage: performance_counters [name] [threshold]\n"+
"Shows detailed performance counters for a specific event\n"+ "Shows detailed performance counters for a specific event\n"+
"- name: The (partial) name of the event\n"+ "- name: The (partial) name of the event\n"+
"- threshold: The minimum avg execution time (ms) of the event\n"+ "- threshold: The minimum avg execution time (ms) of the event\n\n"+
"", this.HandleCommand); "Usage: performance_counters reset\n"+
"Resets all performance counters\n", this.HandleCommand);
this.GameInstance.CommandManager.Add(null, "pc", "Alias for performance_counters", this.HandleCommand); this.GameInstance.CommandManager.Add(null, "pc", "Alias for performance_counters", this.HandleCommand);
// start handling command line input // start handling command line input
@ -1393,6 +1394,9 @@ namespace StardewModdingAPI.Framework
} }
} }
break; break;
case "reset":
this.PerformanceCounterManager.Reset();
return;
default: default:
showSummary = false; showSummary = false;
filterByName = arguments[0]; filterByName = arguments[0];