private ExecuteResult Execute(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, string exePath, string workingDirectory, string args, IDiagnoser diagnoser, IResolver resolver) { ConsoleExitHandler.Instance.Logger = logger; try { using (var process = new Process { StartInfo = CreateStartInfo(benchmarkCase, exePath, args, workingDirectory, resolver) }) { var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmarkCase, benchmarkId); diagnoser?.Handle(HostSignal.BeforeProcessStart, new DiagnoserActionParameters(process, benchmarkCase, benchmarkId)); return(Execute(process, benchmarkCase, loggerWithDiagnoser, logger)); } } finally { ConsoleExitHandler.Instance.Process = null; ConsoleExitHandler.Instance.Logger = null; diagnoser?.Handle(HostSignal.AfterProcessExit, new DiagnoserActionParameters(null, benchmarkCase, benchmarkId)); } }
internal void ProcessInput() { // Peek -1 or 0 can indicate internal error. while (!process.StandardOutput.EndOfStream && process.StandardOutput.Peek() > 0) { // ReadLine() can actually return string.Empty and null as valid values. string line = process.StandardOutput.ReadLine(); if (!string.IsNullOrEmpty(line)) // Skip bad data. { logger.WriteLine(LogKind.Default, line); if (!line.StartsWith("//")) { LinesWithResults.Add(line); } else if (Engine.Signals.TryGetSignal(line, out var signal)) { diagnoser?.Handle(signal, diagnoserActionParameters); process.StandardInput.WriteLine(Engine.Signals.Acknowledgment); } else { LinesWithExtraOutput.Add(line); } } } }
internal void ProcessInput() { string line; while ((line = process.StandardOutput.ReadLine()) != null) { logger.WriteLine(LogKind.Default, line); if (string.IsNullOrEmpty(line)) { continue; } if (!line.StartsWith("//")) { LinesWithResults.Add(line); } else if (Engine.Signals.TryGetSignal(line, out var signal)) { diagnoser?.Handle(signal, diagnoserActionParameters); process.StandardInput.WriteLine(Engine.Signals.Acknowledgment); } else { LinesWithExtraOutput.Add(line); } } }
/// <summary>Sends notification signal to the host.</summary> /// <param name="hostSignal">The signal to send.</param> public void SendSignal(HostSignal hostSignal) { if (!IsDiagnoserAttached) // no need to send the signal, nobody is listening for it { return; } diagnoser.Handle(hostSignal, diagnoserActionParameters); }
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)); } }
/// <summary>Sends notification signal to the host.</summary> /// <param name="hostSignal">The signal to send.</param> public void SendSignal(HostSignal hostSignal) { if (!IsDiagnoserAttached) // no need to send the signal, nobody is listening for it { return; } if (diagnoser == null) { throw new NullReferenceException(nameof(diagnoser)); } diagnoser.Handle(hostSignal, diagnoserActionParameters); }
internal void ProcessInput() { // Peek -1 or 0 can indicate internal error. while (!process.StandardOutput.EndOfStream && process.StandardOutput.Peek() > 0) { // ReadLine() can actually return string.Empty and null as valid values. string line = process.StandardOutput.ReadLine(); if (line == null) { continue; } logger.WriteLine(LogKind.Default, line); if (!line.StartsWith("//")) { LinesWithResults.Add(line); } else if (Engine.Signals.TryGetSignal(line, out var signal)) { diagnoser?.Handle(signal, diagnoserActionParameters); if (process.StartInfo.RedirectStandardInput) { process.StandardInput.WriteLine(Engine.Signals.Acknowledgment); } if (signal == HostSignal.AfterAll) { // we have received the last signal so we can stop reading the output // if the process won't exit after this, its hung and needs to be killed return; } } else if (!string.IsNullOrEmpty(line)) { LinesWithExtraOutput.Add(line); } } }