private ExecuteResult Execute(Process process, BenchmarkCase benchmarkCase, SynchronousProcessOutputLoggerWithDiagnoser loggerWithDiagnoser, ILogger logger, ConsoleExitHandler consoleExitHandler, int launchIndex) { logger.WriteLineInfo($"// Execute: {process.StartInfo.FileName} {process.StartInfo.Arguments} in {process.StartInfo.WorkingDirectory}"); process.Start(); process.EnsureHighPriority(logger); if (benchmarkCase.Job.Environment.HasValue(EnvironmentMode.AffinityCharacteristic)) { process.TrySetAffinity(benchmarkCase.Job.Environment.Affinity, logger); } loggerWithDiagnoser.ProcessInput(); if (!process.WaitForExit(milliseconds: (int)ExecuteParameters.ProcessExitTimeout.TotalMilliseconds)) { logger.WriteLineInfo("// The benchmarking process did not quit on time, it's going to get force killed now."); consoleExitHandler.KillProcessTree(); } if (loggerWithDiagnoser.LinesWithResults.Any(line => line.Contains("BadImageFormatException"))) { logger.WriteLineError("You are probably missing <PlatformTarget>AnyCPU</PlatformTarget> in your .csproj file."); } return(new ExecuteResult(true, process.ExitCode, process.Id, loggerWithDiagnoser.LinesWithResults, loggerWithDiagnoser.LinesWithExtraOutput, launchIndex)); }
private ExecuteResult Execute(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, ArtifactsPaths artifactsPaths, string args, IDiagnoser diagnoser, IResolver resolver, int launchIndex) { try { using (var process = new Process { StartInfo = CreateStartInfo(benchmarkCase, artifactsPaths, args, resolver) }) using (var consoleExitHandler = new ConsoleExitHandler(process, logger)) { var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmarkCase, benchmarkId); diagnoser?.Handle(HostSignal.BeforeProcessStart, new DiagnoserActionParameters(process, benchmarkCase, benchmarkId)); return(Execute(process, benchmarkCase, loggerWithDiagnoser, logger, consoleExitHandler, launchIndex)); } } finally { diagnoser?.Handle(HostSignal.AfterProcessExit, new DiagnoserActionParameters(null, benchmarkCase, benchmarkId)); } }