public BenchmarkExecResult Execute(BenchmarkBuildResult buildResult, BenchmarkParameters parameters, IBenchmarkDiagnoser diagnoser) { var exeName = Path.Combine(buildResult.DirectoryPath, "Program.exe"); var args = parameters == null ? string.Empty : parameters.ToArgs(); if (File.Exists(exeName)) { var lines = new List <string>(); var startInfo = CreateStartInfo(exeName, args); using (var process = Process.Start(startInfo)) { if (process != null) { process.PriorityClass = ProcessPriorityClass.High; process.ProcessorAffinity = new IntPtr(2); string line; while ((line = process.StandardOutput.ReadLine()) != null) { logger?.WriteLine(line); if (!line.StartsWith("//") && !string.IsNullOrEmpty(line)) { lines.Add(line); } // Wait until we know "Warmup" is happening, and then dissassemble the process if (codeAlreadyExtracted == false && line.StartsWith("// Warmup") && !line.StartsWith("// Warmup (idle)")) { try { diagnoser.Print(benchmark, process, logger); } finally { // Always set this, even if something went wrong, otherwise we will try on every run of a benchmark batch codeAlreadyExtracted = 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 BenchmarkExecResult(true, new string[0])); } } } return(new BenchmarkExecResult(true, lines)); } return(new BenchmarkExecResult(false, new string[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); }
public BenchmarkExecResult Execute(BenchmarkBuildResult buildResult, BenchmarkParameters parameters, IBenchmarkDiagnoser diagnoser) { Done = true; return(new BenchmarkExecResult(true, new string[0])); }
public BenchmarkExecResult Execute(BenchmarkBuildResult buildResult, BenchmarkParameters parameters, IBenchmarkDiagnoser diagnoser) { return(executor.Execute(buildResult, parameters, diagnoser)); }