Exemplo n.º 1
0
        private ExecuteResult Execute(Process process, Benchmark benchmark, SynchronousProcessOutputLoggerWithDiagnoser loggerWithDiagnoser, IDiagnoser compositeDiagnoser, ILogger logger)
        {
            consoleHandler.SetProcess(process);

            process.Start();

            compositeDiagnoser?.ProcessStarted(process);

            process.EnsureHighPriority(logger);
            if (!benchmark.Job.Affinity.IsAuto)
            {
                process.EnsureProcessorAffinity(benchmark.Job.Affinity.Value);
            }

            loggerWithDiagnoser.ProcessInput();

            process.WaitForExit(); // should we add timeout here?

            compositeDiagnoser?.ProcessStopped(process);

            if (process.ExitCode == 0)
            {
                return(new ExecuteResult(true, loggerWithDiagnoser.Lines));
            }

            return(new ExecuteResult(true, new string[0]));
        }
Exemplo n.º 2
0
        private void RunCore(
            Benchmark benchmark, IRunnableBenchmark runnableBenchmark,
            ILogger logger, IDiagnoser diagnoser,
            BlockingStream outputStream)
        {
            var outputWriter = new StreamWriter(outputStream);
            var process      = Process.GetCurrentProcess();

            try
            {
                runnableBenchmark.Init(benchmark, outputWriter);

                diagnoser?.ProcessStarted(process);

                runnableBenchmark.Run();

                diagnoser?.AfterBenchmarkHasRun(benchmark, process);
            }
            catch (Exception ex)
            {
                logger.WriteLineError($"// ! {GetType().Name}, exception: {ex}");
            }
            finally
            {
                diagnoser?.ProcessStopped(process);

                outputWriter.Flush();
                outputStream.CompleteWriting();
            }
        }
Exemplo n.º 3
0
        public ExecuteResult Execute(BuildResult buildResult, Benchmark benchmark, ILogger logger, IDiagnoser compositeDiagnoser = null)
        {
            if (consoleHandler == null)
            {
                consoleHandler          = new ConsoleHandler(logger);
                Console.CancelKeyPress += consoleHandler.EventHandler;
            }

            var exeName = Path.Combine(buildResult.DirectoryPath, "Program.exe");
            var args    = string.Empty;

            if (File.Exists(exeName))
            {
                try
                {
                    var startInfo = CreateStartInfo(benchmark, exeName, args);
                    using (var process = Process.Start(startInfo))
                    {
                        if (process != null)
                        {
                            if (compositeDiagnoser != null)
                            {
                                compositeDiagnoser.ProcessStarted(process);
                            }

                            consoleHandler.SetProcess(process);
                            var result = ExecuteImpl(process, exeName, benchmark, logger, compositeDiagnoser);

                            if (compositeDiagnoser != null)
                            {
                                compositeDiagnoser.ProcessStopped(process);
                            }

                            return(result);
                        }
                    }
                }
                finally
                {
                    consoleHandler?.ClearProcess();
                }
            }
            return(new ExecuteResult(false, new string[0]));
        }
Exemplo n.º 4
0
        public ExecuteResult Execute(BuildResult buildResult, Benchmark benchmark, ILogger logger, IDiagnoser compositeDiagnoser = null)
        {
            if (consoleHandler == null)
            {
                consoleHandler = new ConsoleHandler(logger);
                Console.CancelKeyPress += consoleHandler.EventHandler;
            }

            var exeName = Path.Combine(buildResult.DirectoryPath, "Program.exe");
            var args = string.Empty;

            if (File.Exists(exeName))
            {
                try
                {
                    var startInfo = CreateStartInfo(benchmark, exeName, args);
                    using (var process = Process.Start(startInfo))
                    {
                        if (process != null)
                        {
                            if (compositeDiagnoser != null)
                                compositeDiagnoser.ProcessStarted(process);

                            consoleHandler.SetProcess(process);
                            var result = ExecuteImpl(process, exeName, benchmark, logger, compositeDiagnoser);

                            if (compositeDiagnoser != null)
                                compositeDiagnoser.ProcessStopped(process);

                            return result;
                        }
                    }
                }
                finally
                {
                    consoleHandler?.ClearProcess();
                }
            }
            return new ExecuteResult(false, new string[0]);
        }