diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/PerformanceCounterCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/PerformanceCounterCommand.cs
index da171a44..d6e36123 100644
--- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/PerformanceCounterCommand.cs
+++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/PerformanceCounterCommand.cs
@@ -13,6 +13,9 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
/*********
** Fields
*********/
+ /// The name of the command.
+ private const string CommandName = "performance";
+
/// The available commands.
private enum SubCommand
{
@@ -31,7 +34,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
*********/
/// Construct an instance.
public PerformanceCounterCommand()
- : base("performance", PerformanceCounterCommand.GetDescription()) { }
+ : base(CommandName, PerformanceCounterCommand.GetDescription()) { }
/// Handle the command.
/// Writes messages to the console and log file.
@@ -97,27 +100,13 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
/// The command arguments.
private void HandleSummarySubCommand(IMonitor monitor, ArgumentParser args)
{
- if (!args.TryGet(1, "mode", out string mode, false))
- mode = "important";
+ if (!this.AssertEnabled(monitor))
+ return;
IEnumerable data = SCore.PerformanceMonitor.GetCollections();
- switch (mode)
- {
- case null:
- case "important":
- data = data.Where(p => p.IsPerformanceCritical);
- break;
-
- case "all":
- break;
-
- default:
- data = data.Where(p => p.Name.ToLowerInvariant().Contains(mode.ToLowerInvariant()));
- break;
- }
double? threshold = null;
- if (args.TryGetDecimal(2, "threshold", out decimal t, false))
+ if (args.TryGetDecimal(1, "threshold", out decimal t, required: false))
threshold = (double?)t;
TimeSpan interval = TimeSpan.FromSeconds(60);
@@ -147,23 +136,21 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
/// The command arguments.
private void HandleDetailSubCommand(IMonitor monitor, ArgumentParser args)
{
- var collections = new List();
- TimeSpan averageInterval = TimeSpan.FromSeconds(60);
+ if (!this.AssertEnabled(monitor))
+ return;
+
+ // parse args
double? thresholdMilliseconds = null;
- string sourceFilter = null;
+ if (args.TryGetDecimal(1, "threshold", out decimal t, required: false))
+ thresholdMilliseconds = (double)t;
- if (args.TryGet(1, "collection", out string collectionName))
- {
- collections.AddRange(SCore.PerformanceMonitor.GetCollections().Where(collection => collection.Name.ToLowerInvariant().Contains(collectionName.ToLowerInvariant())));
-
- if (args.Count >= 2 && decimal.TryParse(args[2], out _) && args.TryGetDecimal(2, "threshold", out decimal value, false))
- thresholdMilliseconds = (double?)value;
- else if (args.TryGet(2, "source", out string sourceName, false))
- sourceFilter = sourceName;
- }
+ // get collections
+ var collections = SCore.PerformanceMonitor.GetCollections();
+ // format
+ TimeSpan averageInterval = TimeSpan.FromSeconds(60);
foreach (PerformanceCounterCollection c in collections)
- this.OutputPerformanceCollectionDetail(monitor, c, averageInterval, thresholdMilliseconds, sourceFilter);
+ this.OutputPerformanceCollectionDetail(monitor, c, averageInterval, thresholdMilliseconds);
}
/// Handles the trigger sub command.
@@ -171,6 +158,9 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
/// The command arguments.
private void HandleTriggerSubCommand(IMonitor monitor, ArgumentParser args)
{
+ if (!this.AssertEnabled(monitor))
+ return;
+
if (args.TryGet(1, "mode", out string mode, false))
{
switch (mode)
@@ -210,7 +200,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
break;
default:
- this.LogUsageError(monitor, $"Unknown mode {mode}. See 'pc help trigger' for usage.");
+ this.LogUsageError(monitor, $"Unknown mode {mode}. See '{CommandName} help trigger' for usage.");
break;
}
}
@@ -331,7 +321,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
if (asDump)
{
foreach (var item in collectionTriggers)
- report.AppendLine($"pc trigger {item.CollectionName} {item.Threshold}");
+ report.AppendLine($"{CommandName} trigger {item.CollectionName} {item.Threshold}");
}
else
{
@@ -356,7 +346,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
if (asDump)
{
foreach (SourceTrigger item in sourceTriggers)
- report.AppendLine($"pc trigger {item.CollectionName} {item.Threshold} {item.SourceName}");
+ report.AppendLine($"{CommandName} trigger {item.CollectionName} {item.Threshold} {item.SourceName}");
}
else
{
@@ -381,6 +371,9 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
/// The command arguments.
private void HandleResetSubCommand(IMonitor monitor, ArgumentParser args)
{
+ if (!this.AssertEnabled(monitor))
+ return;
+
if (args.TryGet(1, "type", out string type, false, new[] { "category", "source" }))
{
args.TryGet(2, "name", out string name);
@@ -404,26 +397,17 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
}
}
-
/// Outputs the details for a collection.
/// Writes messages to the console and log file.
/// The collection.
/// The interval over which to calculate the averages.
/// The threshold.
- /// The source filter.
- private void OutputPerformanceCollectionDetail(IMonitor monitor, PerformanceCounterCollection collection,
- TimeSpan averageInterval, double? thresholdMilliseconds, string sourceFilter = null)
+ private void OutputPerformanceCollectionDetail(IMonitor monitor, PerformanceCounterCollection collection, TimeSpan averageInterval, double? thresholdMilliseconds)
{
StringBuilder report = new StringBuilder($"Performance Counter for {collection.Name}:\n\n");
List> data = collection.PerformanceCounters.ToList();
- if (sourceFilter != null)
- {
- data = collection.PerformanceCounters.Where(p =>
- p.Value.Source.ToLowerInvariant().Contains(sourceFilter.ToLowerInvariant())).ToList();
- }
-
if (thresholdMilliseconds != null)
data = data.Where(p => p.Value.GetAverage(averageInterval) >= thresholdMilliseconds).ToList();
@@ -476,46 +460,35 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
switch (subcommand)
{
case SubCommand.Detail:
- report.AppendLine("Usage: pc detail