/// <summary>Executes the specified benchmark.</summary>
        public ExecuteResult Execute(ExecuteParameters executeParameters)
        {
            // TODO: preallocate buffer for output (no direct logging)?
            var hostLogger = LogOutput ? executeParameters.Logger : NullLogger.Instance;
            var host       = new InProcessHost(executeParameters.BenchmarkCase, hostLogger, executeParameters.Diagnoser);

            int exitCode  = -1;
            var runThread = new Thread(() => exitCode = ExecuteCore(host, executeParameters));

            if (executeParameters.BenchmarkCase.Descriptor.WorkloadMethod.GetCustomAttributes <STAThreadAttribute>(false).Any())
            {
                runThread.SetApartmentState(ApartmentState.STA);
            }

            runThread.IsBackground = true;

            var timeout = HostEnvironmentInfo.GetCurrent().HasAttachedDebugger ? UnderDebuggerTimeout : ExecutionTimeout;

            runThread.Start();

            if (!runThread.Join((int)timeout.TotalMilliseconds))
            {
                throw new InvalidOperationException(
                          $"Benchmark {executeParameters.BenchmarkCase.DisplayInfo} takes too long to run. " +
                          "Prefer to use out-of-process toolchains for long-running benchmarks.");
            }

            return(GetExecutionResult(host.RunResults, exitCode));
        }
예제 #2
0
        /// <summary>Executes the specified benchmark.</summary>
        /// <param name="buildResult">The build result.</param>
        /// <param name="benchmark">The benchmark.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="resolver">The resolver.</param>
        /// <param name="diagnoser">The diagnoser.</param>
        /// <returns>Execution result.</returns>
        public ExecuteResult Execute(
            BuildResult buildResult, Benchmark benchmark, ILogger logger, IResolver resolver, IDiagnoser diagnoser = null)
        {
            // TODO: preallocate buffer for output (no direct logging)?
            var hostLogger = LogOutput ? logger : new CompositeLogger();
            var host       = new InProcessHost(benchmark, hostLogger, diagnoser);

            int exitCode  = -1;
            var runThread = new Thread(() => exitCode = ExecuteCore(host, benchmark, logger));

#if CLASSIC
            if (benchmark.Target.Method.GetCustomAttributes <STAThreadAttribute>(false).Any())
            {
                runThread.SetApartmentState(ApartmentState.STA);
            }
#endif
            runThread.IsBackground = true;

            var timeout = HostEnvironmentInfo.GetCurrent().HasAttachedDebugger ? UnderDebuggerTimeout : ExecutionTimeout;

            runThread.Start();

            if (!runThread.Join((int)timeout.TotalMilliseconds))
            {
                throw new InvalidOperationException(
                          $"Benchmark {benchmark.DisplayInfo} takes to long to run. " +
                          "Prefer to use out-of-process toolchains for long-running benchmarks.");
            }

            return(GetExecutionResult(host.RunResults, exitCode, logger));
        }