Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<SystemReflectionMetadataVersion>8.0.0</SystemReflectionMetadataVersion>
<SystemCollectionsImmutableVersion>9.0.11</SystemCollectionsImmutableVersion>
<!-- Other libs -->
<SystemCommandLineVersion>2.0.2</SystemCommandLineVersion>
<MicrosoftBclAsyncInterfacesVersion>9.0.8</MicrosoftBclAsyncInterfacesVersion>
<MicrosoftDiaSymReaderNativeVersion>17.10.0-beta1.24272.1</MicrosoftDiaSymReaderNativeVersion>
<MicrosoftDiagnosticsTracingTraceEventVersion>3.1.23</MicrosoftDiagnosticsTracingTraceEventVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,9 @@ public CommandGroup(string commandPrompt = null)
internal bool Execute(IReadOnlyList<string> commandLine, IServiceProvider services)
{
IConsoleService consoleService = services.GetService<IConsoleService>();
CommandLineConfiguration configuration = new(_rootCommand)
{
Output = new ConsoleServiceWrapper(consoleService.Write),
Error = new ConsoleServiceWrapper(consoleService.WriteError)
};

// Parse the command line and invoke the command
ParseResult parseResult = configuration.Parse(commandLine);

// Parse the command line
ParseResult parseResult = _rootCommand.Parse(commandLine);

if (parseResult.Errors.Count > 0)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Tools/Common/Commands/ProcessStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
Expand All @@ -23,7 +24,7 @@ public class ProcessStatusCommandHandler
public static Command ProcessStatusCommand(string description)
{
Command statusCommand = new(name: "ps", description);
statusCommand.SetAction((parseResult, ct) => Task.FromResult(ProcessStatus(parseResult.Configuration.Output, parseResult.Configuration.Error)));
statusCommand.SetAction((context, ct) => Task.FromResult(ProcessStatus(context.Console.Out, context.Console.Error)));
return statusCommand;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Common/ProcessTerminationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static async Task<int> InvokeAsync(ParseResult parseResult, string bloc
private static ProcessTerminationHandler ConfigureTerminationHandler(ParseResult parseResult, string blockedSignals)
{
// Use custom process terminate handler for the command line tool parse result.
parseResult.Configuration.ProcessTerminationTimeout = null;
// Note: ProcessTerminationTimeout property was removed in System.CommandLine 2.0+
return new ProcessTerminationHandler(blockedSignals);
}

Expand Down
21 changes: 11 additions & 10 deletions src/Tools/dotnet-dump/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Internal.Common;
Expand Down Expand Up @@ -31,16 +32,16 @@ private static Command CollectCommand()
ProcessIdOption, OutputOption, DiagnosticLoggingOption, CrashReportOption, TypeOption, ProcessNameOption, DiagnosticPortOption
};

command.SetAction((parseResult) => new Dumper().Collect(
stdOutput: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
processId: parseResult.GetValue(ProcessIdOption),
output: parseResult.GetValue(OutputOption),
diag: parseResult.GetValue(DiagnosticLoggingOption),
crashreport: parseResult.GetValue(CrashReportOption),
type: parseResult.GetValue(TypeOption),
name: parseResult.GetValue(ProcessNameOption),
diagnosticPort: parseResult.GetValue(DiagnosticPortOption)));
command.SetAction((context) => new Dumper().Collect(
stdOutput: context.Console.Out,
stdError: context.Console.Error,
processId: context.ParseResult.GetValue(ProcessIdOption),
output: context.ParseResult.GetValue(OutputOption),
diag: context.ParseResult.GetValue(DiagnosticLoggingOption),
crashreport: context.ParseResult.GetValue(CrashReportOption),
type: context.ParseResult.GetValue(TypeOption),
name: context.ParseResult.GetValue(ProcessNameOption),
diagnosticPort: context.ParseResult.GetValue(DiagnosticPortOption)));

return command;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Tools/dotnet-sos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.IO;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -31,10 +32,10 @@ private static Command InstallCommand()
ArchitectureOption
};

installCommand.SetAction(parseResult => Invoke(
parseResult.Configuration.Output,
parseResult.Configuration.Error,
architecture: parseResult.GetValue(ArchitectureOption),
installCommand.SetAction(context => Invoke(
context.Console.Out,
context.Console.Error,
architecture: context.ParseResult.GetValue(ArchitectureOption),
install: true));

return installCommand;
Expand All @@ -52,9 +53,9 @@ private static Command UninstallCommand()
name: "uninstall",
description: "Uninstalls SOS and reverts any configuration changes to LLDB.");

uninstallCommand.SetAction(parseResult => Invoke(
parseResult.Configuration.Output,
parseResult.Configuration.Error,
uninstallCommand.SetAction(context => Invoke(
context.Console.Out,
context.Console.Error,
architecture: null,
install: false));

Expand Down
13 changes: 7 additions & 6 deletions src/Tools/dotnet-stack/ReportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics.Tracing;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -173,12 +174,12 @@ public static Command ReportCommand()
DurationOption
};

reportCommand.SetAction((parseResult, ct) => Report(ct,
stdOutput: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
processId: parseResult.GetValue(ProcessIdOption),
name: parseResult.GetValue(NameOption),
duration: parseResult.GetValue(DurationOption)));
reportCommand.SetAction((context, ct) => Report(ct,
stdOutput: context.Console.Out,
stdError: context.Console.Error,
processId: context.ParseResult.GetValue(ProcessIdOption),
name: context.ParseResult.GetValue(NameOption),
duration: context.ParseResult.GetValue(DurationOption)));

return reportCommand;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Tools/dotnet-stack/Symbolicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
Expand Down Expand Up @@ -305,13 +306,13 @@ public static Command SymbolicateCommand()
StandardOutOption
};

symbolicateCommand.SetAction((parseResult, ct) => Task.FromResult(Symbolicate(
stdOutput: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
inputPath: parseResult.GetValue(InputFileArgument),
searchDir: parseResult.GetValue(SearchDirectoryOption),
output: parseResult.GetValue(OutputFileOption),
stdout: parseResult.GetValue(StandardOutOption))));
symbolicateCommand.SetAction((context, ct) => Task.FromResult(Symbolicate(
stdOutput: context.Console.Out,
stdError: context.Console.Error,
inputPath: context.ParseResult.GetValue(InputFileArgument),
searchDir: context.ParseResult.GetValue(SearchDirectoryOption),
output: context.ParseResult.GetValue(OutputFileOption),
stdout: context.ParseResult.GetValue(StandardOutOption))));

return symbolicateCommand;
}
Expand Down
45 changes: 23 additions & 22 deletions src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void ConsoleWriteLine(string str = "")
/// <param name="stoppingEventPayloadFilter">A string, parsed as [payload_field_name]:[payload_field_value] pairs separated by commas, that will stop the trace upon hitting an event with a matching payload. Requires `--stopping-event-provider-name` and `--stopping-event-event-name` to be set.</param>
/// <param name="rundown">Collect rundown events.</param>
/// <returns></returns>
internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration cliConfig, 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, string stoppingEventProviderName, string stoppingEventEventName, string stoppingEventPayloadFilter, bool? rundown, string dsrouter)
internal async Task<int> Collect(CancellationToken ct, TextWriter stdOut, TextWriter stdError, 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, string stoppingEventProviderName, string stoppingEventEventName, string stoppingEventPayloadFilter, bool? rundown, string dsrouter)
{
bool collectionStopped = false;
bool cancelOnEnter = true;
Expand Down Expand Up @@ -453,7 +453,7 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
if (format != TraceFileFormat.NetTrace)
{
string outputFilename = TraceFileFormatConverter.GetConvertedFilename(output.FullName, outputfile: null, format);
TraceFileFormatConverter.ConvertToFormat(cliConfig.Output, cliConfig.Error, format, fileToConvert: output.FullName, outputFilename);
TraceFileFormatConverter.ConvertToFormat(stdOut, stdError, format, fileToConvert: output.FullName, outputFilename);
}
}

Expand Down Expand Up @@ -560,32 +560,33 @@ public static Command CollectCommand()
collectCommand.TreatUnmatchedTokensAsErrors = false; // see the logic in Program.Main that handles UnmatchedTokens
collectCommand.Description = "Collects a diagnostic trace from a currently running process or launch a child process and trace it. Append -- to the collect command to instruct the tool to run a command and trace it immediately. When tracing a child process, the exit code of dotnet-trace shall be that of the traced process unless the trace process encounters an error.";

collectCommand.SetAction((parseResult, ct) =>
collectCommand.SetAction((context, ct) =>
{
CollectCommandHandler handler = new();
string providersValue = parseResult.GetValue(CommonOptions.ProvidersOption) ?? string.Empty;
string profileValue = parseResult.GetValue(CommonOptions.ProfileOption) ?? string.Empty;
string providersValue = context.ParseResult.GetValue(CommonOptions.ProvidersOption) ?? string.Empty;
string profileValue = context.ParseResult.GetValue(CommonOptions.ProfileOption) ?? string.Empty;

return handler.Collect(ct,
cliConfig: parseResult.Configuration,
processId: parseResult.GetValue(CommonOptions.ProcessIdOption),
output: parseResult.GetValue(CommonOptions.OutputPathOption),
buffersize: parseResult.GetValue(CircularBufferOption),
stdOut: context.Console.Out,
stdError: context.Console.Error,
processId: context.ParseResult.GetValue(CommonOptions.ProcessIdOption),
output: context.ParseResult.GetValue(CommonOptions.OutputPathOption),
buffersize: context.ParseResult.GetValue(CircularBufferOption),
providers: providersValue.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries),
profile: profileValue.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries),
format: parseResult.GetValue(CommonOptions.FormatOption),
duration: parseResult.GetValue(CommonOptions.DurationOption),
clrevents: parseResult.GetValue(CommonOptions.CLREventsOption) ?? string.Empty,
clreventlevel: parseResult.GetValue(CommonOptions.CLREventLevelOption) ?? string.Empty,
name: parseResult.GetValue(CommonOptions.NameOption),
diagnosticPort: parseResult.GetValue(DiagnosticPortOption) ?? string.Empty,
showchildio: parseResult.GetValue(ShowChildIOOption),
resumeRuntime: parseResult.GetValue(ResumeRuntimeOption),
stoppingEventProviderName: parseResult.GetValue(StoppingEventProviderNameOption),
stoppingEventEventName: parseResult.GetValue(StoppingEventEventNameOption),
stoppingEventPayloadFilter: parseResult.GetValue(StoppingEventPayloadFilterOption),
rundown: parseResult.GetValue(RundownOption),
dsrouter: parseResult.GetValue(DSRouterOption));
format: context.ParseResult.GetValue(CommonOptions.FormatOption),
duration: context.ParseResult.GetValue(CommonOptions.DurationOption),
clrevents: context.ParseResult.GetValue(CommonOptions.CLREventsOption) ?? string.Empty,
clreventlevel: context.ParseResult.GetValue(CommonOptions.CLREventLevelOption) ?? string.Empty,
name: context.ParseResult.GetValue(CommonOptions.NameOption),
diagnosticPort: context.ParseResult.GetValue(DiagnosticPortOption) ?? string.Empty,
showchildio: context.ParseResult.GetValue(ShowChildIOOption),
resumeRuntime: context.ParseResult.GetValue(ResumeRuntimeOption),
stoppingEventProviderName: context.ParseResult.GetValue(StoppingEventProviderNameOption),
stoppingEventEventName: context.ParseResult.GetValue(StoppingEventEventNameOption),
stoppingEventPayloadFilter: context.ParseResult.GetValue(StoppingEventPayloadFilterOption),
rundown: context.ParseResult.GetValue(RundownOption),
dsrouter: context.ParseResult.GetValue(DSRouterOption));
});

return collectCommand;
Expand Down
13 changes: 7 additions & 6 deletions src/Tools/dotnet-trace/CommandLine/Commands/ConvertCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -103,12 +104,12 @@ public static Command ConvertCommand()
OutputOption,
};

convertCommand.SetAction((parseResult, ct) => Task.FromResult(ConvertFile(
stdOut: parseResult.Configuration.Output,
stdError: parseResult.Configuration.Error,
inputFilename: parseResult.GetValue(InputFileArgument),
format: parseResult.GetValue(CommonOptions.ConvertFormatOption),
output: parseResult.GetValue(OutputOption
convertCommand.SetAction((context, ct) => Task.FromResult(ConvertFile(
stdOut: context.Console.Out,
stdError: context.Console.Error,
inputFilename: context.ParseResult.GetValue(InputFileArgument),
format: context.ParseResult.GetValue(CommonOptions.ConvertFormatOption),
output: context.ParseResult.GetValue(OutputOption
))));

return convertCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/EventPipeStress/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.137102" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="$(MicrosoftDiagnosticsTracingTraceEventVersion)" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.7.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/tests/EventPipeStress/Stress/Stress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<ProjectReference Include="../Common/Common.csproj" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions src/tests/dotnet-trace/CollectCommandFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class CollectCommandFunctionalTests

public sealed record CollectArgs(
CancellationToken ct = default,
CommandLineConfiguration cliConfig = null,
TextWriter stdOut = null,
TextWriter stdError = null,
int processId = -1,
uint buffersize = 1,
string[] providers = null,
Expand Down Expand Up @@ -91,7 +92,8 @@ private static async Task<int> RunAsync(CollectArgs config, MockConsole console,

return await handler.Collect(
config.ct,
config.cliConfig,
config.stdOut ?? Console.Out,
config.stdError ?? Console.Error,
config.ProcessId,
config.Output,
config.buffersize,
Expand Down
Loading