using System;
using System.Collections.Generic;
using System.CommandLine;
+using System.CommandLine.Binding;
using System.CommandLine.Rendering;
using System.Diagnostics;
using System.IO;
{
internal static class CollectCommandHandler
{
+ delegate Task<int> CollectDelegate(CancellationToken ct, IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format);
+
/// <summary>
/// Collects a diagnostic trace from a currently running process.
/// </summary>
+ /// <param name="ct">The cancellation token</param>
/// <param name="console"></param>
/// <param name="processId">The process to collect the trace from.</param>
/// <param name="output">The output path for the collected trace data.</param>
/// <param name="profile">A named pre-defined set of provider configurations that allows common tracing scenarios to be specified succinctly.</param>
/// <param name="format">The desired format of the created trace file.</param>
/// <returns></returns>
- private static async Task<int> Collect(IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format)
+ private static async Task<int> Collect(CancellationToken ct, IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format)
{
try
{
var failed = false;
var terminated = false;
+ ct.Register(() => shouldExit.Set());
+
ulong sessionId = 0;
using (Stream stream = EventPipeClient.CollectTracing(processId, configuration, out sessionId))
using (VirtualTerminalMode vTermMode = VirtualTerminalMode.TryEnable())
collectingTask.Start();
Console.Out.WriteLine("Press <Enter> or <Ctrl+C> to exit...");
- Console.CancelKeyPress += (sender, args) => {
- args.Cancel = true;
- shouldExit.Set();
- };
do {
while (!Console.KeyAvailable && !shouldExit.WaitOne(250)) { }
ProfileOption(),
CommonOptions.FormatOption(),
},
- handler: System.CommandLine.Invocation.CommandHandler.Create<IConsole, int, FileInfo, uint, string, string, TraceFileFormat>(Collect));
+ handler: HandlerDescriptor.FromDelegate((CollectDelegate)Collect).GetCommandHandler());
private static uint DefaultCircularBufferSizeInMB => 256;