Пример #1
0
        private int ExecuteCore(IHost host, Benchmark benchmark, ILogger logger)
        {
            int exitCode    = -1;
            var process     = Process.GetCurrentProcess();
            var oldPriority = process.PriorityClass;
            var oldAffinity = process.ProcessorAffinity;

#if CLASSIC
            var thread            = Thread.CurrentThread;
            var oldThreadPriority = thread.Priority;
#endif

            var affinity = benchmark.Job.ResolveValueAsNullable(EnvMode.AffinityCharacteristic);
            try
            {
                process.TrySetPriority(ProcessPriorityClass.High, logger);
#if CLASSIC
                thread.TrySetPriority(ThreadPriority.Highest, logger);
#endif
                if (affinity != null)
                {
                    process.TrySetAffinity(affinity.Value, logger);
                }

                exitCode = InProcessRunner.Run(host, benchmark, CodegenMode);
            }
            catch (Exception ex)
            {
                logger.WriteLineError($"// ! {GetType().Name}, exception: {ex}");
            }
            finally
            {
                process.TrySetPriority(oldPriority, logger);
#if CLASSIC
                thread.TrySetPriority(oldThreadPriority, logger);
#endif
                if (affinity != null)
                {
                    process.EnsureProcessorAffinity(oldAffinity);
                }
            }

            return(exitCode);
        }
Пример #2
0
        private int ExecuteCore(IHost host, ExecuteParameters parameters)
        {
            int exitCode    = -1;
            var process     = Process.GetCurrentProcess();
            var oldPriority = process.PriorityClass;
            var oldAffinity = process.TryGetAffinity();

#if !NETCOREAPP1_1
            var thread            = Thread.CurrentThread;
            var oldThreadPriority = thread.Priority;
#endif

            var affinity = parameters.Benchmark.Job.ResolveValueAsNullable(EnvMode.AffinityCharacteristic);
            try
            {
                process.TrySetPriority(ProcessPriorityClass.High, parameters.Logger);
#if !NETCOREAPP1_1
                thread.TrySetPriority(ThreadPriority.Highest, parameters.Logger);
#endif
                if (affinity != null)
                {
                    process.TrySetAffinity(affinity.Value, parameters.Logger);
                }

                exitCode = InProcessRunner.Run(host, parameters.Benchmark, CodegenMode, parameters.Config);
            }
            catch (Exception ex)
            {
                parameters.Logger.WriteLineError($"// ! {GetType().Name}, exception: {ex}");
            }
            finally
            {
                process.TrySetPriority(oldPriority, parameters.Logger);
#if !NETCOREAPP1_1
                thread.TrySetPriority(oldThreadPriority, parameters.Logger);
#endif
                if (affinity != null && oldAffinity != null)
                {
                    process.TrySetAffinity(oldAffinity.Value, parameters.Logger);
                }
            }

            return(exitCode);
        }
Пример #3
0
        private int ExecuteCore(IHostApi hostApi, Benchmark benchmark, ILogger logger)
        {
            int exitCode    = -1;
            var process     = Process.GetCurrentProcess();
            var oldPriority = process.PriorityClass;
            var oldAffinity = process.ProcessorAffinity;

            var affinity = benchmark.Job.ResolveValueAsNullable(EnvMode.AffinityCharacteristic);

            try
            {
                process.SetPriority(ProcessPriorityClass.High, logger);
                if (affinity != null)
                {
                    process.SetAffinity(affinity.Value, logger);
                }
                // TODO: set thread priority to highest

                exitCode = InProcessRunner.Run(hostApi, benchmark, CodegenMode);
            }
            catch (Exception ex)
            {
                logger.WriteLineError($"// ! {GetType().Name}, exception: {ex}");
            }
            finally
            {
                // TODO: restore thread priority

                process.SetPriority(oldPriority, logger);
                if (affinity != null)
                {
                    process.EnsureProcessorAffinity(oldAffinity);
                }
            }

            return(exitCode);
        }