return true;
}
- public void Cleanup()
+ public async void Cleanup()
{
if (_childProc != null && !_childProc.HasExited)
{
// if process exited while we were trying to kill it, it can throw IOE
catch (InvalidOperationException) { }
}
+
+ if (ReversedDiagnosticsClientBuilder.Server != null)
+ {
+ await ReversedDiagnosticsClientBuilder.Server.DisposeAsync();
+ }
}
}
{
private static string GetTransportName(string toolName) => $"{toolName}-{Process.GetCurrentProcess().Id}-{DateTime.Now:yyyyMMdd_HHmmss}.socket";
+ public static ReversedDiagnosticsServer Server = null;
+
// <summary>
// Starts the child process and returns the diagnostics client once the child proc connects to the reversed diagnostics pipe.
// The callee needs to resume the diagnostics client at appropriate time.
}
// Create and start the reversed server
string diagnosticTransportName = GetTransportName(toolName);
- ReversedDiagnosticsServer server = new ReversedDiagnosticsServer(diagnosticTransportName);
- server.Start();
+ Server = new ReversedDiagnosticsServer(diagnosticTransportName);
+ Server.Start();
// Start the child proc
if (!childProcLauncher.Start(diagnosticTransportName))
}
// Wait for attach
- IpcEndpointInfo endpointInfo = server.Accept(TimeSpan.FromSeconds(timeoutInSec));
+ IpcEndpointInfo endpointInfo = Server.Accept(TimeSpan.FromSeconds(timeoutInSec));
// If for some reason a different process attached to us, wait until the expected process attaches.
while (endpointInfo.ProcessId != childProcLauncher.ChildProc.Id)
{
- endpointInfo = server.Accept(TimeSpan.FromSeconds(timeoutInSec));
+ endpointInfo = Server.Accept(TimeSpan.FromSeconds(timeoutInSec));
}
return new DiagnosticsClient(endpointInfo.Endpoint);
}
}
-}
\ No newline at end of file
+}
return 0;
}
+ int ret = 0;
try
{
InitializeCounterList(counters, counter_list);
_renderer = new ConsoleWriter();
if (!BuildDiagnosticsClient())
{
- return 0;
+ ret = 0;
}
- int ret = await Start();
+ ret = await Start();
ProcessLauncher.Launcher.Cleanup();
- return ret;
}
catch (OperationCanceledException)
{
catch (Exception) {} // Swallow all exceptions for now.
console.Out.WriteLine($"Complete");
- return 1;
+ ret = 1;
+ }
+ finally
+ {
+ 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)
{
+ int ret = 1;
if (!ValidateAndSetProcessId(processId, name))
{
return 0;
if (!BuildDiagnosticsClient())
{
+ ProcessLauncher.Launcher.Cleanup();
return 0;
}
_console.Error.WriteLine($"The output format {format} is not a valid output format.");
return 0;
}
-
- int ret = await Start();
- ProcessLauncher.Launcher.Cleanup();
- return ret;
+ ret = await Start();
}
catch (OperationCanceledException)
{
}
- return 1;
+ finally
+ {
+ ProcessLauncher.Launcher.Cleanup();
+ }
+ return ret;
}
private void InitializeCounterList(string counters, List<string> counterList)
/// <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)
{
+ int ret = 0;
try
{
Debug.Assert(output != null);
{
ProcessLauncher.Launcher.ChildProc.Kill();
}
+ await ReversedDiagnosticsClientBuilder.Server.DisposeAsync();
return ErrorCodes.SessionCreationError;
}
process = ProcessLauncher.Launcher.ChildProc;
if (format != TraceFileFormat.NetTrace)
TraceFileFormatConverter.ConvertToFormat(format, output.FullName);
+ ret = 0;
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"[ERROR] {ex.ToString()}");
- return ErrorCodes.TracingError;
+ ret = ErrorCodes.TracingError;
}
finally
{
{
ProcessLauncher.Launcher.ChildProc.Kill();
}
- }
- return await Task.FromResult(0);
+ if (ReversedDiagnosticsClientBuilder.Server != null)
+ {
+ await ReversedDiagnosticsClientBuilder.Server.DisposeAsync();
+ }
+ }
+ return await Task.FromResult(ret);
}
private static void PrintProviders(IReadOnlyList<EventPipeProvider> providers, Dictionary<string, string> enabledBy)