From: Johan Lorensson Date: Fri, 18 Jun 2021 21:04:56 +0000 (+0200) Subject: Add runtime resume option to dotnet-trace and dotnet-counters. (#2343) X-Git-Tag: submit/tizen/20220302.040122~25^2^2~58 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b253a5dbde5f2574ada392ceb4e9d6d19083ad9;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Add runtime resume option to dotnet-trace and dotnet-counters. (#2343) --- diff --git a/src/Tools/dotnet-counters/CounterMonitor.cs b/src/Tools/dotnet-counters/CounterMonitor.cs index 185259014..c8eee8df7 100644 --- a/src/Tools/dotnet-counters/CounterMonitor.cs +++ b/src/Tools/dotnet-counters/CounterMonitor.cs @@ -91,7 +91,7 @@ namespace Microsoft.Diagnostics.Tools.Counters _renderer.Stop(); } - public async Task Monitor(CancellationToken ct, List counter_list, string counters, IConsole console, int processId, int refreshInterval, string name, string diagnosticPort) + public async Task Monitor(CancellationToken ct, List 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)) { @@ -115,7 +115,7 @@ namespace Microsoft.Diagnostics.Tools.Counters _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; @@ -135,7 +135,7 @@ namespace Microsoft.Diagnostics.Tools.Counters } - public async Task Collect(CancellationToken ct, List counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string name, string diagnosticPort) + public async Task Collect(CancellationToken ct, List 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)) { @@ -190,7 +190,7 @@ namespace Microsoft.Diagnostics.Tools.Counters _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; } diff --git a/src/Tools/dotnet-counters/Program.cs b/src/Tools/dotnet-counters/Program.cs index 5da067fcd..ff040f357 100644 --- a/src/Tools/dotnet-counters/Program.cs +++ b/src/Tools/dotnet-counters/Program.cs @@ -22,8 +22,8 @@ namespace Microsoft.Diagnostics.Tools.Counters internal class Program { - delegate Task CollectDelegate(CancellationToken ct, List counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string processName, string port); - delegate Task MonitorDelegate(CancellationToken ct, List counter_list, string counters, IConsole console, int processId, int refreshInterval, string processName, string port); + delegate Task CollectDelegate(CancellationToken ct, List counter_list, string counters, IConsole console, int processId, int refreshInterval, CountersExportFormat format, string output, string processName, string port, bool resumeRuntime); + delegate Task MonitorDelegate(CancellationToken ct, List counter_list, string counters, IConsole console, int processId, int refreshInterval, string processName, string port, bool resumeRuntime); private static Command MonitorCommand() => new Command( @@ -33,7 +33,7 @@ namespace Microsoft.Diagnostics.Tools.Counters // 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() => @@ -44,7 +44,7 @@ namespace Microsoft.Diagnostics.Tools.Counters // 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() => @@ -127,6 +127,14 @@ namespace Microsoft.Diagnostics.Tools.Counters Argument = new Argument(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(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) diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs index 3764b1da9..65856947a 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs @@ -21,7 +21,7 @@ namespace Microsoft.Diagnostics.Tools.Trace { internal static class CollectCommandHandler { - delegate Task 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 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); /// /// Collects a diagnostic trace from a currently running process or launch a child process and trace it. @@ -41,8 +41,9 @@ namespace Microsoft.Diagnostics.Tools.Trace /// The verbosity level of CLR events /// Path to the diagnostic port to be created. /// Should IO from a child process be hidden. + /// Resume runtime once session has been initialized. /// - private static async Task 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 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; @@ -150,7 +151,7 @@ namespace Microsoft.Diagnostics.Tools.Trace 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()); @@ -162,7 +163,7 @@ namespace Microsoft.Diagnostics.Tools.Trace return await Task.FromResult(ret); } diagnosticsClient = holder.Client; - if (shouldResumeRuntime) + if (ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort)) { process = Process.GetProcessById(holder.EndpointInfo.ProcessId); } @@ -399,7 +400,8 @@ namespace Microsoft.Diagnostics.Tools.Trace CLREventLevelOption(), CommonOptions.NameOption(), DiagnosticPortOption(), - ShowChildIOOption() + ShowChildIOOption(), + ResumeRuntimeOption() }; private static uint DefaultCircularBufferSizeInMB() => 256; @@ -482,5 +484,13 @@ namespace Microsoft.Diagnostics.Tools.Trace { Argument = new Argument(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(name: "resumeRuntime", getDefaultValue: () => true) + }; } }