private string _metricsEventSourceSessionId;
private int _maxTimeSeries;
private int _maxHistograms;
+ private TimeSpan _duration;
class ProviderEventState
{
string diagnosticPort,
bool resumeRuntime,
int maxHistograms,
- int maxTimeSeries)
+ int maxTimeSeries,
+ TimeSpan duration)
{
try
{
_renderer = new ConsoleWriter(useAnsi);
_diagnosticsClient = holder.Client;
_resumeRuntime = resumeRuntime;
+ _duration = duration;
int ret = await Start();
ProcessLauncher.Launcher.Cleanup();
return ret;
string diagnosticPort,
bool resumeRuntime,
int maxHistograms,
- int maxTimeSeries)
+ int maxTimeSeries,
+ TimeSpan duration)
{
try
{
_maxTimeSeries = maxTimeSeries;
_output = output;
_diagnosticsClient = holder.Client;
+ _duration = duration;
if (_output.Length == 0)
{
_console.Error.WriteLine("Output cannot be an empty string");
});
monitorTask.Start();
+ var shouldStopAfterDuration = _duration != default(TimeSpan);
+ Stopwatch durationStopwatch = null;
+
+ if (shouldStopAfterDuration)
+ {
+ durationStopwatch = Stopwatch.StartNew();
+ }
while(!_shouldExit.Task.Wait(250))
{
_pauseCmdSet = false;
}
}
+
+ if (shouldStopAfterDuration && durationStopwatch.Elapsed >= _duration)
+ {
+ durationStopwatch.Stop();
+ break;
+ }
}
+
StopMonitor();
return _shouldExit.Task;
}
string port,
bool resumeRuntime,
int maxHistograms,
- int maxTimeSeries);
+ int maxTimeSeries,
+ TimeSpan duration);
delegate Task<int> MonitorDelegate(
CancellationToken ct,
List<string> counter_list,
string port,
bool resumeRuntime,
int maxHistograms,
- int maxTimeSeries);
+ int maxTimeSeries,
+ TimeSpan duration);
private static Command MonitorCommand() =>
new Command(
DiagnosticPortOption(),
ResumeRuntimeOption(),
MaxHistogramOption(),
- MaxTimeSeriesOption()
+ MaxTimeSeriesOption(),
+ DurationOption()
};
private static Command CollectCommand() =>
DiagnosticPortOption(),
ResumeRuntimeOption(),
MaxHistogramOption(),
- MaxTimeSeriesOption()
+ MaxTimeSeriesOption(),
+ DurationOption()
};
private static Option NameOption() =>
Argument = new Argument<int>(name: "maxTimeSeries", getDefaultValue: () => 1000)
};
+ private static Option DurationOption() =>
+ new Option(
+ alias: "--duration",
+ description: @"When specified, will run for the given timespan and then automatically stop. Provided in the form of dd:hh:mm:ss.")
+ {
+ Argument = new Argument<TimeSpan>(name: "duration-timespan", getDefaultValue: () => default)
+ };
+
private static readonly string[] s_SupportedRuntimeVersions = new[] { "3.0", "3.1", "5.0" };
public static int List(IConsole console, string runtimeVersion)