public BenchmarkReport Run(Benchmark benchmark, IList <string> importantPropertyNames)
        {
            Logger.WriteLineHeader("// **************************");
            Logger.WriteLineHeader("// Benchmark: " + benchmark.Description);
            var directoryPath = benchmarkProjectGenerator.GenerateProject(benchmark);

            Logger.WriteLineInfo("// Generated project: " + directoryPath);
            Logger.NewLine();
            Logger.WriteLineInfo("// Build:");
            var buildResult = benchmarkProjectGenerator.BuildProject(directoryPath);

            if (buildResult.OverallResult == BuildResultCode.Success)
            {
                Logger.WriteLineInfo("// OverallResult = Success");
            }
            else
            {
                Logger.WriteLineError("// OverallResult = Failure");
                return(new BenchmarkReport(benchmark, new BenchmarkRunReport[0]));
            }
            Logger.NewLine();
            var processCount = Math.Max(1, benchmark.Task.ProcessCount);
            var runReports   = new List <BenchmarkRunReport>();
            var exeFileName  = Path.Combine(directoryPath, "Program.exe");

            for (int processNumber = 0; processNumber < processCount; processNumber++)
            {
                Logger.WriteLineInfo($"// Run, Process: {processNumber + 1} / {processCount}");
                if (importantPropertyNames.Any())
                {
                    Logger.WriteInfo("// ");
                    foreach (var name in importantPropertyNames)
                    {
                        Logger.WriteInfo($"{name}={benchmark.Properties.GetValue(name)} ");
                    }
                    Logger.NewLine();
                }

                var executor = new BenchmarkExecutor(Logger);
                if (File.Exists(exeFileName))
                {
                    var lines          = executor.Exec(exeFileName, benchmark.Task.Settings.ToArgs());
                    var iterRunReports = lines.Select(line => BenchmarkRunReport.Parse(Logger, line)).Where(r => r != null).ToList();
                    runReports.AddRange(iterRunReports);
                }
            }
            Logger.NewLine();
            return(new BenchmarkReport(benchmark, runReports));
        }
Beispiel #2
0
        private List <BenchmarkRunReport> Execute(IBenchmarkLogger logger, Benchmark benchmark, IList <string> importantPropertyNames, BenchmarkParameters parameters, IBenchmarkToolchainFacade toolchain, BenchmarkBuildResult buildResult)
        {
            logger.WriteLineInfo("// *** Execute ***");
            var processCount = Math.Max(1, benchmark.Task.ProcessCount);
            var runReports   = new List <BenchmarkRunReport>();

            for (int processNumber = 0; processNumber < processCount; processNumber++)
            {
                logger.WriteLineInfo($"// Run, Process: {processNumber + 1} / {processCount}");
                if (parameters != null)
                {
                    logger.WriteLineInfo($"// {parameters.ToInfo()}");
                }
                if (importantPropertyNames.Any())
                {
                    logger.WriteInfo("// ");
                    foreach (var name in importantPropertyNames)
                    {
                        logger.WriteInfo($"{name}={benchmark.Properties.GetValue(name)} ");
                    }
                    logger.NewLine();
                }

                var execResult = toolchain.Execute(buildResult, parameters, Plugins.CompositeDiagnoser);

                if (execResult.FoundExecutable)
                {
                    var iterRunReports = execResult.Data.Select(line => BenchmarkRunReport.Parse(logger, line)).Where(r => r != null).ToList();
                    runReports.AddRange(iterRunReports);
                }
                else
                {
                    logger.WriteLineError("Executable not found");
                }
            }
            logger.NewLine();
            return(runReports);
        }