1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.PerformanceCounter;
namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
{
// ReSharper disable once UnusedType.Global
internal class PerformanceCounterCommand : TrainerCommand
{
/// <summary>The command names and aliases</summary>
private readonly Dictionary<SubCommand, string[]> SubCommandNames = new Dictionary<SubCommand, string[]>()
{
{SubCommand.Summary, new[] {"summary", "sum", "s"}},
{SubCommand.Detail, new[] {"detail", "d"}},
{SubCommand.Reset, new[] {"reset", "r"}},
{SubCommand.Trigger, new[] {"trigger"}},
{SubCommand.Enable, new[] {"enable"}},
{SubCommand.Disable, new[] {"disable"}},
{SubCommand.Examples, new[] {"examples"}},
{SubCommand.Concepts, new[] {"concepts"}},
{SubCommand.Help, new[] {"help"}},
};
/// <summary>The available commands enum</summary>
private enum SubCommand
{
Summary,
Detail,
Reset,
Trigger,
Enable,
Disable,
Examples,
Help,
Concepts,
None
}
/// <summary>Construct an instance.</summary>
public PerformanceCounterCommand() : base("pc", PerformanceCounterCommand.GetDescription())
{
}
/// <summary>Handle the command.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="command">The command name.</param>
/// <param name="args">The command arguments.</param>
public override void Handle(IMonitor monitor, string command, ArgumentParser args)
{
if (args.TryGet(0, "command", out string subCommandString, false))
{
SubCommand subSubCommand = this.ParseCommandString(subCommandString);
switch (subSubCommand)
{
case SubCommand.Summary:
this.HandleSummarySubCommand(monitor, args);
break;
case SubCommand.Detail:
this.HandleDetailSubCommand(monitor, args);
break;
case SubCommand.Reset:
this.HandleResetSubCommand(monitor, args);
break;
case SubCommand.Trigger:
this.HandleTriggerSubCommand(monitor, args);
break;
case SubCommand.Examples:
break;
case SubCommand.Concepts:
this.OutputHelp(monitor, SubCommand.Concepts);
break;
case SubCommand.Enable:
SCore.PerformanceCounterManager.EnableTracking = true;
monitor.Log("Performance counter tracking is now enabled", LogLevel.Info);
break;
case SubCommand.Disable:
SCore.PerformanceCounterManager.EnableTracking = false;
monitor.Log("Performance counter tracking is now disabled", LogLevel.Info);
break;
case SubCommand.Help:
if (args.TryGet(1, "command", out string commandString))
this.OutputHelp(monitor, this.ParseCommandString(commandString));
break;
default:
this.LogUsageError(monitor, $"Unknown command {subCommandString}");
break;
}
}
else
this.HandleSummarySubCommand(monitor, args);
}
/// <summary>Handles the summary sub command.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="args">The command arguments.</param>
private void HandleSummarySubCommand(IMonitor monitor, ArgumentParser args)
{
IEnumerable<PerformanceCounterCollection> data;
if (!args.TryGet(1, "mode", out string mode, false))
{
mode = "important";
}
switch (mode)
{
case null:
case "important":
data = SCore.PerformanceCounterManager.PerformanceCounterCollections.Where(p => p.IsImportant);
break;
case "all":
data = SCore.PerformanceCounterManager.PerformanceCounterCollections;
break;
default:
data = SCore.PerformanceCounterManager.PerformanceCounterCollections.Where(p =>
p.Name.ToLowerInvariant().Contains(mode.ToLowerInvariant()));
break;
}
double? threshold = null;
if (args.TryGetDecimal(2, "threshold", out decimal t, false))
{
threshold = (double?) t;
}
StringBuilder sb = new StringBuilder();
TimeSpan interval = TimeSpan.FromSeconds(60);
sb.AppendLine($"Summary over the last {interval.TotalSeconds} seconds:");
sb.AppendLine(this.GetTableString(
data: data,
header: new[] {"Collection", "Avg Calls/s", "Avg Exec Time (Game)", "Avg Exec Time (Mods)", "Avg Exec Time (Game+Mods)", "Peak Exec Time"},
getRow: item => new[]
{
item.Name,
item.GetAverageCallsPerSecond().ToString(),
this.FormatMilliseconds(item.GetGameAverageExecutionTime(interval), threshold),
this.FormatMilliseconds(item.GetModsAverageExecutionTime(interval), threshold),
this.FormatMilliseconds(item.GetAverageExecutionTime(interval), threshold),
this.FormatMilliseconds(item.GetPeakExecutionTime(interval), threshold)
},
true
));
monitor.Log(sb.ToString(), LogLevel.Info);
}
/// <summary>Handles the detail sub command.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="args">The command arguments.</param>
private void HandleDetailSubCommand(IMonitor monitor, ArgumentParser args)
{
var collections = new List<PerformanceCounterCollection>();
TimeSpan averageInterval = TimeSpan.FromSeconds(60);
double? thresholdMilliseconds = null;
string sourceFilter = null;
if (args.TryGet(1, "collection", out string collectionName))
{
collections.AddRange(SCore.PerformanceCounterManager.PerformanceCounterCollections.Where(
collection => collection.Name.ToLowerInvariant().Contains(collectionName.ToLowerInvariant())));
if (args.IsDecimal(2) && args.TryGetDecimal(2, "threshold", out decimal value, false))
{
thresholdMilliseconds = (double?) value;
}
else
{
if (args.TryGet(2, "source", out string sourceName, false))
{
sourceFilter = sourceName;
}
}
}
foreach (PerformanceCounterCollection c in collections)
{
this.OutputPerformanceCollectionDetail(monitor, c, averageInterval, thresholdMilliseconds, sourceFilter);
}
}
/// <summary>Handles the trigger sub command.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="args">The command arguments.</param>
private void HandleTriggerSubCommand(IMonitor monitor, ArgumentParser args)
{
if (args.TryGet(1, "mode", out string mode, false))
{
switch (mode)
{
case "list":
this.OutputAlertTriggers(monitor);
break;
case "collection":
if (args.TryGet(2, "name", out string collectionName))
{
if (args.TryGetDecimal(3, "threshold", out decimal threshold))
{
if (args.TryGet(4, "source", out string source, false))
{
this.ConfigureAlertTrigger(monitor, collectionName, source, threshold);
}
else
{
this.ConfigureAlertTrigger(monitor, collectionName, null, threshold);
}
}
}
break;
case "pause":
SCore.PerformanceCounterManager.PauseAlerts = true;
monitor.Log($"Alerts are now paused.", LogLevel.Info);
break;
case "resume":
SCore.PerformanceCounterManager.PauseAlerts = false;
monitor.Log($"Alerts are now resumed.", LogLevel.Info);
break;
case "dump":
this.OutputAlertTriggers(monitor, true);
break;
case "clear":
this.ClearAlertTriggers(monitor);
break;
default:
this.LogUsageError(monitor, $"Unknown mode {mode}. See 'pc help trigger' for usage.");
break;
}
}
else
{
this.OutputAlertTriggers(monitor);
}
}
/// <summary>Sets up an an alert trigger.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="collectionName">The name of the collection.</param>
/// <param name="sourceName">The name of the source, or null for all sources.</param>
/// <param name="threshold">The trigger threshold, or 0 to remove.</param>
private void ConfigureAlertTrigger(IMonitor monitor, string collectionName, string sourceName, decimal threshold)
{
foreach (PerformanceCounterCollection collection in SCore.PerformanceCounterManager.PerformanceCounterCollections)
{
if (collection.Name.ToLowerInvariant().Equals(collectionName.ToLowerInvariant()))
{
if (sourceName == null)
{
if (threshold != 0)
{
collection.EnableAlerts = true;
collection.AlertThresholdMilliseconds = (double) threshold;
monitor.Log($"Set up alert triggering for '{collectionName}' with '{this.FormatMilliseconds((double?) threshold)}'", LogLevel.Info);
}
else
{
collection.EnableAlerts = false;
monitor.Log($"Cleared alert triggering for '{collection}'.");
}
return;
}
else
{
foreach (var performanceCounter in collection.PerformanceCounters)
{
if (performanceCounter.Value.Source.ToLowerInvariant().Equals(sourceName.ToLowerInvariant()))
{
if (threshold != 0)
{
performanceCounter.Value.EnableAlerts = true;
performanceCounter.Value.AlertThresholdMilliseconds = (double) threshold;
monitor.Log($"Set up alert triggering for '{sourceName}' in collection '{collectionName}' with '{this.FormatMilliseconds((double?) threshold)}", LogLevel.Info);
}
else
{
performanceCounter.Value.EnableAlerts = false;
}
return;
}
}
monitor.Log($"Could not find the source '{sourceName}' in collection '{collectionName}'", LogLevel.Warn);
return;
}
}
}
monitor.Log($"Could not find the collection '{collectionName}'", LogLevel.Warn);
}
/// <summary>Clears alert triggering for all collections.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
private void ClearAlertTriggers(IMonitor monitor)
{
int clearedTriggers = 0;
foreach (PerformanceCounterCollection collection in SCore.PerformanceCounterManager.PerformanceCounterCollections)
{
if (collection.EnableAlerts)
{
collection.EnableAlerts = false;
clearedTriggers++;
}
foreach (var performanceCounter in collection.PerformanceCounters)
{
if (performanceCounter.Value.EnableAlerts)
{
performanceCounter.Value.EnableAlerts = false;
clearedTriggers++;
}
}
}
monitor.Log($"Cleared {clearedTriggers} alert triggers.", LogLevel.Info);
}
/// <summary>Lists all configured alert triggers.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="asDump">True to dump the triggers as commands.</param>
private void OutputAlertTriggers(IMonitor monitor, bool asDump = false)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Configured triggers:");
sb.AppendLine();
var collectionTriggers = new List<(string collectionName, double threshold)>();
var sourceTriggers = new List<(string collectionName, string sourceName, double threshold)>();
foreach (PerformanceCounterCollection collection in SCore.PerformanceCounterManager.PerformanceCounterCollections)
{
if (collection.EnableAlerts)
{
collectionTriggers.Add((collection.Name, collection.AlertThresholdMilliseconds));
}
sourceTriggers.AddRange(from performanceCounter in
collection.PerformanceCounters where performanceCounter.Value.EnableAlerts
select (collection.Name, performanceCounter.Value.Source, performanceCounter.Value.AlertThresholdMilliseconds));
}
if (collectionTriggers.Count > 0)
{
sb.AppendLine("Collection Triggers:");
sb.AppendLine();
if (asDump)
{
foreach (var item in collectionTriggers)
{
sb.AppendLine($"pc trigger {item.collectionName} {item.threshold}");
}
}
else
{
sb.AppendLine(this.GetTableString(
data: collectionTriggers,
header: new[] {"Collection", "Threshold"},
getRow: item => new[]
{
item.collectionName,
this.FormatMilliseconds(item.threshold)
},
true
));
}
sb.AppendLine();
}
else
{
sb.AppendLine("No collection triggers.");
}
if (sourceTriggers.Count > 0)
{
sb.AppendLine("Source Triggers:");
sb.AppendLine();
if (asDump)
{
foreach (var item in sourceTriggers)
{
sb.AppendLine($"pc trigger {item.collectionName} {item.threshold} {item.sourceName}");
}
}
else
{
sb.AppendLine(this.GetTableString(
data: sourceTriggers,
header: new[] {"Collection", "Source", "Threshold"},
getRow: item => new[]
{
item.collectionName,
item.sourceName,
this.FormatMilliseconds(item.threshold)
},
true
));
}
sb.AppendLine();
}
else
{
sb.AppendLine("No source triggers.");
}
monitor.Log(sb.ToString(), LogLevel.Info);
}
/// <summary>Handles the reset sub command.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="args">The command arguments.</param>
private void HandleResetSubCommand(IMonitor monitor, ArgumentParser args)
{
if (args.TryGet(1, "type", out string type, false, new []{"category", "source"}))
{
args.TryGet(2, "name", out string name);
switch (type)
{
case "category":
SCore.PerformanceCounterManager.ResetCollection(name);
monitor.Log($"All performance counters for category {name} are now cleared.", LogLevel.Info);
break;
case "source":
SCore.PerformanceCounterManager.ResetSource(name);
monitor.Log($"All performance counters for source {name} are now cleared.", LogLevel.Info);
break;
}
}
else
{
SCore.PerformanceCounterManager.Reset();
monitor.Log("All performance counters are now cleared.", LogLevel.Info);
}
}
/// <summary>Outputs the details for a collection.</summary>
/// <param name="monitor">Writes messages to the console and log file.</param>
/// <param name="collection">The collection.</param>
/// <param name="averageInterval">The interval over which to calculate the averages.</param>
/// <param name="thresholdMilliseconds">The threshold.</param>
/// <param name="sourceFilter">The source filter.</param>
private void OutputPerformanceCollectionDetail(IMonitor monitor, PerformanceCounterCollection collection,
TimeSpan averageInterval, double? thresholdMilliseconds, string sourceFilter = null)
{
StringBuilder sb = new StringBuilder($"Performance Counter for {collection.Name}:\n\n");
List<KeyValuePair<string, PerformanceCounter>> 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();
}
if (data.Any())
{
sb.AppendLine(this.GetTableString(
data: data,
header: new[] {"Mod", $"Avg Exec Time (last {(int) averageInterval.TotalSeconds}s)", "Last Exec Time", "Peak Exec Time", $"Peak Exec Time (last {(int) averageInterval.TotalSeconds}s)"},
getRow: item => new[]
{
item.Key,
this.FormatMilliseconds(item.Value.GetAverage(averageInterval), thresholdMilliseconds),
this.FormatMilliseconds(item.Value.GetLastEntry()?.ElapsedMilliseconds),
this.FormatMilliseconds(item.Value.GetPeak()?.ElapsedMilliseconds),
this.FormatMilliseconds(item.Value.GetPeak(averageInterval)?.ElapsedMilliseconds)
},
true
));
}
else
{
sb.Clear();
sb.AppendLine($"Performance Counter for {collection.Name}: none.");
}
monitor.Log(sb.ToString(), LogLevel.Info);
}
/// <summary>Parses a command string and returns the associated command.</summary>
/// <param name="commandString">The command string</param>
/// <returns>The parsed command.</returns>
private SubCommand ParseCommandString(string commandString)
{
foreach (var i in this.SubCommandNames.Where(i =>
i.Value.Any(str => str.Equals(commandString, StringComparison.InvariantCultureIgnoreCase))))
{
return i.Key;
}
return SubCommand.None;
}
/// <summary>Formats the given milliseconds value into a string format. Optionally
/// allows a threshold to return "-" if the value is less than the threshold.</summary>
/// <param name="milliseconds">The milliseconds to format. Returns "-" if null</param>
/// <param name="thresholdMilliseconds">The threshold. Any value below this is returned as "-".</param>
/// <returns>The formatted milliseconds.</returns>
private string FormatMilliseconds(double? milliseconds, double? thresholdMilliseconds = null)
{
if (milliseconds == null || (thresholdMilliseconds != null && milliseconds < thresholdMilliseconds))
{
return "-";
}
return ((double) milliseconds).ToString("F2");
}
/// <summary>Shows detailed help for a specific sub command.</summary>
/// <param name="monitor">The output monitor</param>
/// <param name="subCommand">The sub command</param>
private void OutputHelp(IMonitor monitor, SubCommand subCommand)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine();
switch (subCommand)
{
case SubCommand.Concepts:
sb.AppendLine("A performance counter is a metric which measures execution time. Each performance");
sb.AppendLine("counter consists of:");
sb.AppendLine();
sb.AppendLine(" - A source, which typically is a mod or the game itself.");
sb.AppendLine(" - A ring buffer which stores the data points (execution time and time when it was executed)");
sb.AppendLine();
sb.AppendLine("A set of performance counters is organized in a collection to group various areas.");
sb.AppendLine("Per default, collections for all game events [1] are created.");
sb.AppendLine();
sb.AppendLine("Example:");
sb.AppendLine();
sb.AppendLine("The performance counter collection named 'Display.Rendered' contains one performance");
sb.AppendLine("counters when the game executes the 'Display.Rendered' event, and one additional");
sb.AppendLine("performance counter for each mod which handles the 'Display.Rendered' event.");
sb.AppendLine();
sb.AppendLine("[1] https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events");
break;
case SubCommand.Detail:
sb.AppendLine("Usage: pc detail <collection> <source>");
sb.AppendLine(" pc detail <collection> <threshold>");
sb.AppendLine();
sb.AppendLine("Displays details for a specific collection.");
sb.AppendLine();
sb.AppendLine("Arguments:");
sb.AppendLine(" <collection> Required. The full or partial name of the collection to display.");
sb.AppendLine(" <source> Optional. The full or partial name of the source.");
sb.AppendLine(" <threshold> Optional. The threshold in milliseconds. Any average execution time below that");
sb.AppendLine(" threshold is not reported.");
sb.AppendLine();
sb.AppendLine("Examples:");
sb.AppendLine("pc detail Display.Rendering Displays all performance counters for the 'Display.Rendering' collection");
sb.AppendLine("pc detail Display.Rendering Pathoschild.ChestsAnywhere Displays the 'Display.Rendering' performance counter for 'Pathoschild.ChestsAnywhere'");
sb.AppendLine("pc detail Display.Rendering 5 Displays the 'Display.Rendering' performance counters exceeding an average of 5ms");
break;
case SubCommand.Summary:
sb.AppendLine("Usage: pc summary <mode|name> <threshold>");
sb.AppendLine();
sb.AppendLine("Displays the performance counter summary.");
sb.AppendLine();
sb.AppendLine("Arguments:");
sb.AppendLine(" <mode> Optional. Defaults to 'important' if omitted. Specifies one of these modes:");
sb.AppendLine(" - all Displays performance counters from all collections");
sb.AppendLine(" - important Displays only important performance counter collections");
sb.AppendLine();
sb.AppendLine(" <name> Optional. Only shows performance counter collections matching the given name");
sb.AppendLine(" <threshold> Optional. Hides the actual execution time if it is below this threshold");
sb.AppendLine();
sb.AppendLine("Examples:");
sb.AppendLine("pc summary all Shows all events");
sb.AppendLine("pc summary all 5 Shows all events");
sb.AppendLine("pc summary Display.Rendering Shows only the 'Display.Rendering' collection");
break;
case SubCommand.Trigger:
sb.AppendLine("Usage: pc trigger <mode>");
sb.AppendLine("Usage: pc trigger collection <collectionName> <threshold>");
sb.AppendLine("Usage: pc trigger collection <collectionName> <threshold> <sourceName>");
sb.AppendLine();
sb.AppendLine("Manages alert triggers.");
sb.AppendLine();
sb.AppendLine("Arguments:");
sb.AppendLine(" <mode> Optional. Specifies if a specific source or a specific collection should be triggered.");
sb.AppendLine(" - list Lists current triggers");
sb.AppendLine(" - collection Sets up a trigger for a collection");
sb.AppendLine(" - clear Clears all trigger entries");
sb.AppendLine(" - pause Pauses triggering of alerts");
sb.AppendLine(" - resume Resumes triggering of alerts");
sb.AppendLine(" - dump Dumps all triggers as commands for copy and paste");
sb.AppendLine(" Defaults to 'list' if not specified.");
sb.AppendLine();
sb.AppendLine(" <collectionName> Required if the mode 'collection' is specified.");
sb.AppendLine(" Specifies the name of the collection to be triggered. Must be an exact match.");
sb.AppendLine();
sb.AppendLine(" <sourceName> Optional. Specifies the name of a specific source. Must be an exact match.");
sb.AppendLine();
sb.AppendLine(" <threshold> Required if the mode 'collection' is specified.");
sb.AppendLine(" Specifies the threshold in milliseconds (fractions allowed).");
sb.AppendLine(" Specify '0' to remove the threshold.");
sb.AppendLine();
sb.AppendLine("Examples:");
sb.AppendLine();
sb.AppendLine("pc trigger collection Display.Rendering 10");
sb.AppendLine(" Sets up an alert trigger which writes on the console if the execution time of all performance counters in");
sb.AppendLine(" the 'Display.Rendering' collection exceed 10 milliseconds.");
sb.AppendLine();
sb.AppendLine("pc trigger collection Display.Rendering 5 Pathoschild.ChestsAnywhere");
sb.AppendLine(" Sets up an alert trigger to write on the console if the execution time of Pathoschild.ChestsAnywhere in");
sb.AppendLine(" the 'Display.Rendering' collection exceed 5 milliseconds.");
sb.AppendLine();
sb.AppendLine("pc trigger collection Display.Rendering 0");
sb.AppendLine(" Removes the threshold previously defined from the collection. Note that source-specific thresholds are left intact.");
sb.AppendLine();
sb.AppendLine("pc trigger clear");
sb.AppendLine(" Clears all previously setup alert triggers.");
break;
case SubCommand.Reset:
sb.AppendLine("Usage: pc reset <type> <name>");
sb.AppendLine();
sb.AppendLine("Resets performance counters.");
sb.AppendLine();
sb.AppendLine("Arguments:");
sb.AppendLine(" <type> Optional. Specifies if a collection or source should be reset.");
sb.AppendLine(" If omitted, all performance counters are reset.");
sb.AppendLine();
sb.AppendLine(" - source Clears performance counters for a specific source");
sb.AppendLine(" - collection Clears performance counters for a specific collection");
sb.AppendLine();
sb.AppendLine(" <name> Required if a <type> is given. Specifies the name of either the collection");
sb.AppendLine(" or the source. The name must be an exact match.");
sb.AppendLine();
sb.AppendLine("Examples:");
sb.AppendLine("pc reset Resets all performance counters");
sb.AppendLine("pc reset source Pathoschild.ChestsAnywhere Resets all performance for the source named Pathoschild.ChestsAnywhere");
sb.AppendLine("pc reset collection Display.Rendering Resets all performance for the collection named Display.Rendering");
break;
}
sb.AppendLine();
monitor.Log(sb.ToString(), LogLevel.Info);
}
/// <summary>Get the command description.</summary>
private static string GetDescription()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Displays and configures performance counters.");
sb.AppendLine();
sb.AppendLine("A performance counter records the invocation time of in-game events being");
sb.AppendLine("processed by mods or the game itself. See 'concepts' for a detailed explanation.");
sb.AppendLine();
sb.AppendLine("Usage: pc <command> <action>");
sb.AppendLine();
sb.AppendLine("Commands:");
sb.AppendLine();
sb.AppendLine(" summary|sum|s Displays a summary of important or all collections");
sb.AppendLine(" detail|d Shows performance counter information for a given collection");
sb.AppendLine(" reset|r Resets the performance counters");
sb.AppendLine(" trigger Configures alert triggers");
sb.AppendLine(" enable Enables performance counter recording");
sb.AppendLine(" disable Disables performance counter recording");
sb.AppendLine(" examples Displays various examples");
sb.AppendLine(" concepts Displays an explanation of the performance counter concepts");
sb.AppendLine(" help Displays verbose help for the available commands");
sb.AppendLine();
sb.AppendLine("To get help for a specific command, use 'pc help <command>', for example:");
sb.AppendLine("pc help summary");
sb.AppendLine();
sb.AppendLine("Defaults to summary if no command is given.");
sb.AppendLine();
return sb.ToString();
}
}
}
|