_renderer.Stop();
}
- public async Task<int> Monitor(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, string name, string diagnosticPort)
+ public async Task<int> Monitor(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, string name, string diagnosticPort, bool resumeRuntime)
{
if (!ProcessLauncher.Launcher.HasChildProc && !CommandUtils.ValidateArgumentsForAttach(processId, name, diagnosticPort, out _processId))
{
_interval = refreshInterval;
_renderer = new ConsoleWriter();
_diagnosticsClient = holder.Client;
- shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort);
+ shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort) || resumeRuntime;
int ret = await Start();
ProcessLauncher.Launcher.Cleanup();
return ret;
}
- public async Task<int> Collect(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string name, string diagnosticPort)
+ public async Task<int> Collect(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string name, string diagnosticPort, bool resumeRuntime)
{
if (!ProcessLauncher.Launcher.HasChildProc && !CommandUtils.ValidateArgumentsForAttach(processId, name, diagnosticPort, out _processId))
{
_console.Error.WriteLine($"The output format {format} is not a valid output format.");
return 0;
}
- shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort);
+ shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort) || resumeRuntime;
int ret = await Start();
return ret;
}
internal class Program
{
- delegate Task<int> CollectDelegate(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string processName, string port);
- delegate Task<int> MonitorDelegate(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, string processName, string port);
+ delegate Task<int> CollectDelegate(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string processName, string port, bool resumeRuntime);
+ delegate Task<int> MonitorDelegate(CancellationToken ct, List<string> counter_list, string counters, IConsole console, int processId, int refreshInterval, string processName, string port, bool resumeRuntime);
private static Command MonitorCommand() =>
new Command(
// Handler
HandlerDescriptor.FromDelegate((MonitorDelegate)new CounterMonitor().Monitor).GetCommandHandler(),
// Arguments and Options
- CounterList(), CounterOption(), ProcessIdOption(), RefreshIntervalOption(), NameOption(), DiagnosticPortOption(),
+ CounterList(), CounterOption(), ProcessIdOption(), RefreshIntervalOption(), NameOption(), DiagnosticPortOption(), ResumeRuntimeOption()
};
private static Command CollectCommand() =>
// Handler
HandlerDescriptor.FromDelegate((CollectDelegate)new CounterMonitor().Collect).GetCommandHandler(),
// Arguments and Options
- CounterList(), CounterOption(), ProcessIdOption(), RefreshIntervalOption(), ExportFormatOption(), ExportFileNameOption(), NameOption(), DiagnosticPortOption()
+ CounterList(), CounterOption(), ProcessIdOption(), RefreshIntervalOption(), ExportFormatOption(), ExportFileNameOption(), NameOption(), DiagnosticPortOption(), ResumeRuntimeOption()
};
private static Option NameOption() =>
Argument = new Argument<string>(name: "diagnosticPort", getDefaultValue: () => "")
};
+ private static Option ResumeRuntimeOption() =>
+ new Option(
+ alias: "--resume-runtime",
+ description: @"Resume runtime once session has been initialized, defaults to true. Disable resume of runtime using --resume-runtime:false")
+ {
+ Argument = new Argument<bool>(name: "resumeRuntime", getDefaultValue: () => true)
+ };
+
private static readonly string[] s_SupportedRuntimeVersions = new[] { "3.0", "3.1", "5.0" };
public static int List(IConsole console, string runtimeVersion)
{
internal static class CollectCommandHandler
{
- delegate Task<int> CollectDelegate(CancellationToken ct, IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format, TimeSpan duration, string clrevents, string clreventlevel, string name, string port, bool showchildio);
+ delegate Task<int> CollectDelegate(CancellationToken ct, IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format, TimeSpan duration, string clrevents, string clreventlevel, string name, string port, bool showchildio, bool resumeRuntime);
/// <summary>
/// Collects a diagnostic trace from a currently running process or launch a child process and trace it.
/// <param name="clreventlevel">The verbosity level of CLR events</param>
/// <param name="port">Path to the diagnostic port to be created.</param>
/// <param name="showchildio">Should IO from a child process be hidden.</param>
+ /// <param name="resumeRuntime">Resume runtime once session has been initialized.</param>
/// <returns></returns>
- private static async Task<int> Collect(CancellationToken ct, IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format, TimeSpan duration, string clrevents, string clreventlevel, string name, string diagnosticPort, bool showchildio)
+ private static async Task<int> Collect(CancellationToken ct, IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format, TimeSpan duration, string clrevents, string clreventlevel, string name, string diagnosticPort, bool showchildio, bool resumeRuntime)
{
int ret = 0;
bool collectionStopped = false;
DiagnosticsClient diagnosticsClient;
Process process;
DiagnosticsClientBuilder builder = new DiagnosticsClientBuilder("dotnet-trace", 10);
- bool shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort);
+ bool shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort) || resumeRuntime;
var shouldExit = new ManualResetEvent(false);
ct.Register(() => shouldExit.Set());
return await Task.FromResult(ret);
}
diagnosticsClient = holder.Client;
- if (shouldResumeRuntime)
+ if (ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort))
{
process = Process.GetProcessById(holder.EndpointInfo.ProcessId);
}
CLREventLevelOption(),
CommonOptions.NameOption(),
DiagnosticPortOption(),
- ShowChildIOOption()
+ ShowChildIOOption(),
+ ResumeRuntimeOption()
};
private static uint DefaultCircularBufferSizeInMB() => 256;
{
Argument = new Argument<bool>(name: "show-child-io", getDefaultValue: () => false)
};
+
+ private static Option ResumeRuntimeOption() =>
+ new Option(
+ alias: "--resume-runtime",
+ description: @"Resume runtime once session has been initialized, defaults to true. Disable resume of runtime using --resume-runtime:false")
+ {
+ Argument = new Argument<bool>(name: "resumeRuntime", getDefaultValue: () => true)
+ };
}
}