コード例 #1
0
        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))
            {
                try
                {
                    var startInfo = CreateStartInfo(exeName, args);
                    using (var process = Process.Start(startInfo))
                    {
                        if (process != null)
                        {
                            consoleHandler.SetProcess(process);
                            return ExecuteImpl(process, diagnoser, exeName);
                        }
                    }
                }
                finally
                {
                    if (consoleHandler != null)
                    {
                        consoleHandler.ClearProcess();
                    }
                }
            }
            return new BenchmarkExecResult(false, new string[0]);
        }
コード例 #2
0
 public BenchmarkReport(Benchmark benchmark, IList<BenchmarkRunReport> runs, EnvironmentInfo hostInfo, BenchmarkParameters parameters = null)
 {
     Benchmark = benchmark;
     Runs = runs;
     Parameters = parameters;
     HostInfo = hostInfo;
 }
コード例 #3
0
        public BenchmarkExecResult Exec(BenchmarkBuildResult buildResult, BenchmarkParameters parameters)
        {
            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
                            var shouldExtractCode = (CommandLineArgs.PrintAssembly || CommandLineArgs.PrintIL || CommandLineArgs.PrintDiagnostics);
                            if (codeAlreadyExtracted == false && shouldExtractCode &&
                                line.StartsWith("// Warmup") && !line.StartsWith("// Warmup (idle)"))
                            {
                                var codeExtractor = new BenchmarkCodeExtractor(benchmark, process, codeExeName: Assembly.GetEntryAssembly().Location, logger: logger);
                                codeExtractor.PrintCodeForMethod(printAssembly: CommandLineArgs.PrintAssembly,
                                                                 printIL: CommandLineArgs.PrintIL,
                                                                 printDiagnostics: CommandLineArgs.PrintDiagnostics);
                                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]);
        }
コード例 #4
0
        public BenchmarkExecResult Exec(BenchmarkBuildResult buildResult, BenchmarkParameters parameters)
        {
            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);
                        }
                        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]);
        }
コード例 #5
0
 public BenchmarkExecResult Exec(BenchmarkBuildResult buildResult, BenchmarkParameters parameters)
 {
     return executor.Exec(buildResult, parameters);
 }
コード例 #6
0
 public static BenchmarkReport CreateEmpty(Benchmark benchmark, BenchmarkParameters parameters) =>
     new BenchmarkReport(benchmark, new BenchmarkRunReport[0], EnvironmentInfo.GetCurrentInfo(), parameters);
コード例 #7
0
 public BenchmarkExecResult Execute(BenchmarkBuildResult buildResult, BenchmarkParameters parameters, IBenchmarkDiagnoser diagnoser)
 {
     Done = true;
     return new BenchmarkExecResult(true, new string[0]);
 }
コード例 #8
0
        private BenchmarkReport Run(Benchmark benchmark, IList<string> importantPropertyNames, BenchmarkParameters parameters = null)
        {
            var flow = BenchmarkFlowFactory.CreateFlow(benchmark, Logger);

            Logger.WriteLineHeader("// **************************");
            Logger.WriteLineHeader("// Benchmark: " + benchmark.Description);

            var generateResult = Generate(flow);
            if (!generateResult.IsGenerateSuccess)
                return BenchmarkReport.CreateEmpty(benchmark, parameters);

            var buildResult = Build(flow, generateResult);
            if (!buildResult.IsBuildSuccess)
                return BenchmarkReport.CreateEmpty(benchmark, parameters);

            var runReports = Exec(benchmark, importantPropertyNames, parameters, flow, buildResult);
            return new BenchmarkReport(benchmark, runReports, parameters);
        }
コード例 #9
0
        private List<BenchmarkRunReport> Exec(Benchmark benchmark, IList<string> importantPropertyNames, BenchmarkParameters parameters, IBenchmarkFlow flow, BenchmarkBuildResult buildResult)
        {
            Logger.WriteLineInfo("// *** Exec ***");
            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 = flow.Exec(buildResult, parameters);

                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;
        }
コード例 #10
0
 public BenchmarkExecResult Execute(BenchmarkBuildResult buildResult, BenchmarkParameters parameters, IBenchmarkDiagnoser diagnoser)
 {
     return executor.Execute(buildResult, parameters, diagnoser);
 }
コード例 #11
0
        private BenchmarkReport Run(IBenchmarkLogger logger, Benchmark benchmark, IList<string> importantPropertyNames, BenchmarkParameters parameters = null)
        {
            var toolchain = Plugins.CreateToolchain(benchmark, logger);

            logger.WriteLineHeader("// **************************");
            logger.WriteLineHeader("// Benchmark: " + benchmark.Description);

            var generateResult = Generate(logger, toolchain);
            if (!generateResult.IsGenerateSuccess)
                return BenchmarkReport.CreateEmpty(benchmark, parameters);

            var buildResult = Build(logger, toolchain, generateResult);
            if (!buildResult.IsBuildSuccess)
                return BenchmarkReport.CreateEmpty(benchmark, parameters);

            var runReports = Execute(logger, benchmark, importantPropertyNames, parameters, toolchain, buildResult);
            return new BenchmarkReport(benchmark, runReports, EnvironmentInfo.GetCurrentInfo(), parameters);
        }
コード例 #12
0
 public static BenchmarkReport CreateEmpty(Benchmark benchmark, BenchmarkParameters parameters) => new BenchmarkReport(benchmark, new BenchmarkRunReport[0], parameters);
コード例 #13
0
 public BenchmarkReport(Benchmark benchmark, IList<BenchmarkRunReport> runs, BenchmarkParameters parameters = null)
 {
     Benchmark = benchmark;
     Runs = runs;
     Parameters = parameters;
 }