Exemple #1
0
        internal void ProcessInput()
        {
            string line;

            while ((line = process.StandardOutput.ReadLine()) != null)
            {
                logger.WriteLine(LogKind.Default, line);

                if (!line.StartsWith("//") && !string.IsNullOrEmpty(line))
                {
                    Lines.Add(line);
                }

                // This is important so the Diagnoser can know the [Benchmark] methods will have run and (e.g.) it can do a Memory Dump
                if (diagnosticsAlreadyRun || !line.StartsWith(IterationMode.MainWarmup.ToString()))
                {
                    continue;
                }

                try
                {
                    diagnoser?.AfterBenchmarkHasRun(benchmark, process);
                }
                finally
                {
                    // Always set this, even if something went wrong, otherwise we will try on every run of a benchmark batch
                    diagnosticsAlreadyRun = true;
                }
            }
        }
        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();
            }
        }
Exemple #3
0
        private ExecuteResult ExecuteImpl(Process process, string exeName, Benchmark benchmark, ILogger logger, IDiagnoser compositeDiagnoser = null)
        {
            process.PriorityClass = ProcessPriorityClass.High;
            if (!benchmark.Job.Affinity.IsAuto)
            {
                process.ProcessorAffinity = new IntPtr(benchmark.Job.Affinity.Value);
            }

            var    lines = new List <string>();
            string line;

            while ((line = process.StandardOutput.ReadLine()) != null)
            {
                logger?.WriteLine(line);
                if (!line.StartsWith("//") && !string.IsNullOrEmpty(line))
                {
                    lines.Add(line);
                }

                if (compositeDiagnoser == null)
                {
                    continue;
                }

                // This is important so the Diagnoser can know the [Benchmark] methods will have run and (e.g.) it can do a Memory Dump
                if (diagnosticsAlreadyRun == false && line.StartsWith(IterationMode.MainWarmup.ToString()))
                {
                    try
                    {
                        compositeDiagnoser.AfterBenchmarkHasRun(benchmark, process);
                    }
                    finally
                    {
                        // Always set this, even if something went wrong, otherwise we will try on every run of a benchmark batch
                        diagnosticsAlreadyRun = true;
                    }
                }
            }

            if (process.HasExited && process.ExitCode != 0)
            {
                if (logger != null)
                {
                    logger.WriteError(
                        $"Something bad happened during the execution of {exeName}. Try to run the benchmark again using an AnyCPU application\n");
                }
                else
                {
                    if (exeName.ToLowerInvariant() == "msbuild")
                    {
                        Console.WriteLine("Build failed");
                    }
                }
                return(new ExecuteResult(true, new string[0]));
            }

            return(new ExecuteResult(true, lines));
        }
        private ExecuteResult ExecuteImpl(Process process, string exeName, Benchmark benchmark, ILogger logger, IDiagnoser compositeDiagnoser = null)
        {
            process.PriorityClass = ProcessPriorityClass.High;
            if (!benchmark.Job.Affinity.IsAuto)
                process.ProcessorAffinity = new IntPtr(benchmark.Job.Affinity.Value);

            var lines = new List<string>();
            string line;
            while ((line = process.StandardOutput.ReadLine()) != null)
            {
                logger?.WriteLine(line);
                if (!line.StartsWith("//") && !string.IsNullOrEmpty(line))
                    lines.Add(line);

                if (compositeDiagnoser == null)
                    continue;

                // This is important so the Diagnoser can know the [Benchmark] methods will have run and (e.g.) it can do a Memory Dump
                if (diagnosticsAlreadyRun == false && line.StartsWith(IterationMode.MainWarmup.ToString()))
                {
                    try
                    {
                        compositeDiagnoser.AfterBenchmarkHasRun(benchmark, process);
                    }
                    finally
                    {
                        // Always set this, even if something went wrong, otherwise we will try on every run of a benchmark batch
                        diagnosticsAlreadyRun = true;
                    }
                }
            }

            if (process.HasExited && process.ExitCode != 0)
            {
                if (logger != null)
                {
                    logger.WriteError(
                        $"Something bad happened during the execution of {exeName}. Try to run the benchmark again using an AnyCPU application\n");
                }
                else
                {
                    if (exeName.ToLowerInvariant() == "msbuild")
                        Console.WriteLine("Build failed");
                }
                return new ExecuteResult(true, new string[0]);
            }

            return new ExecuteResult(true, lines);
        }