{
if (!ProcessLauncher.Launcher.HasChildProc && !CommandUtils.ValidateArgumentsForAttach(processId, name, diagnosticPort, out _processId))
{
- return 0;
+ return ReturnCode.ArgumentError;
}
shouldExit = new ManualResetEvent(false);
_ct.Register(() => shouldExit.Set());
{
if (holder == null)
{
- return 1;
+ return ReturnCode.Ok;
}
try
{
catch (Exception) { } // Swallow all exceptions for now.
console.Out.WriteLine($"Complete");
- return 1;
+ return ReturnCode.Ok;
}
}
}
{
if (!ProcessLauncher.Launcher.HasChildProc && !CommandUtils.ValidateArgumentsForAttach(processId, name, diagnosticPort, out _processId))
{
- return 0;
+ return ReturnCode.ArgumentError;
}
shouldExit = new ManualResetEvent(false);
{
if (holder == null)
{
- return 1;
+ return ReturnCode.Ok;
}
try
if (_output.Length == 0)
{
_console.Error.WriteLine("Output cannot be an empty string");
- return 0;
+ return ReturnCode.ArgumentError;
}
if (format == CountersExportFormat.csv)
{
else
{
_console.Error.WriteLine($"The output format {format} is not a valid output format.");
- return 0;
+ return ReturnCode.ArgumentError;
}
shouldResumeRuntime = ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort) || resumeRuntime;
int ret = await Start();
_session.Stop();
}
catch (Exception) { } // session.Stop() can throw if target application already stopped before we send the stop command.
- return 1;
+ return ReturnCode.Ok;
}
}
}
string providerString = BuildProviderString();
if (providerString.Length == 0)
{
- return 1;
+ return ReturnCode.ArgumentError;
}
_renderer.Initialize();
if (shouldExit.WaitOne(250))
{
StopMonitor();
- return 0;
+ return ReturnCode.Ok;
}
if (Console.KeyAvailable)
{
pauseCmdSet = false;
}
}
- return await Task.FromResult(0);
+ return await Task.FromResult(ReturnCode.Ok);
}
}
}
/// <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, bool resumeRuntime)
{
- int ret = 0;
bool collectionStopped = false;
bool cancelOnEnter = true;
bool cancelOnCtrlC = true;
bool printStatusOverTime = true;
+ int ret = ReturnCode.Ok;
try
{
if (showchildio)
{
Console.WriteLine("--show-child-io must not be specified when attaching to a process");
- return ErrorCodes.ArgumentError;
+ return ReturnCode.ArgumentError;
}
if (CommandUtils.ValidateArgumentsForAttach(processId, name, diagnosticPort, out int resolvedProcessId))
{
}
else
{
- return ErrorCodes.ArgumentError;
+ return ReturnCode.ArgumentError;
}
}
else if (!CommandUtils.ValidateArgumentsForChildProcess(processId, name, diagnosticPort))
{
- return ErrorCodes.ArgumentError;
+ return ReturnCode.ArgumentError;
}
if (profile.Length == 0 && providers.Length == 0 && clrevents.Length == 0)
if (selectedProfile == null)
{
Console.Error.WriteLine($"Invalid profile name: {profile}");
- return ErrorCodes.ArgumentError;
+ return ReturnCode.ArgumentError;
}
Profile.MergeProfileAndProviders(selectedProfile, providerCollection, enabledBy);
if (providerCollection.Count <= 0)
{
Console.Error.WriteLine("No providers were specified to start a trace.");
- return ErrorCodes.ArgumentError;
+ return ReturnCode.ArgumentError;
}
PrintProviders(providerCollection, enabledBy);
// if builder returned null, it means we received ctrl+C while waiting for clients to connect. Exit gracefully.
if (holder == null)
{
- return await Task.FromResult(ret);
+ return await Task.FromResult(ReturnCode.Ok);
}
diagnosticsClient = holder.Client;
if (ProcessLauncher.Launcher.HasChildProc || !string.IsNullOrEmpty(diagnosticPort))
if (attempts > 10)
{
Console.Error.WriteLine("Unable to examine process.");
- return ErrorCodes.SessionCreationError;
+ return ReturnCode.SessionCreationError;
}
Thread.Sleep(200);
}
if (session == null)
{
Console.Error.WriteLine("Unable to create session.");
- return ErrorCodes.SessionCreationError;
+ return ReturnCode.SessionCreationError;
}
if (shouldStopAfterDuration)
catch (Exception ex)
{
Console.Error.WriteLine($"[ERROR] {ex.ToString()}");
- ret = ErrorCodes.TracingError;
collectionStopped = true;
+ ret = ReturnCode.TracingError;
}
finally
{
{
if (!collectionStopped || ct.IsCancellationRequested)
{
- ret = ErrorCodes.TracingError;
+ ret = ReturnCode.TracingError;
}
// If we launched a child proc that hasn't exited yet, terminate it before we exit.