예제 #1
0
        private ProcessStartInfo CreateStartInfo(BenchmarkCase benchmarkCase, ArtifactsPaths artifactsPaths,
                                                 string args, IResolver resolver, bool noAcknowledgments)
        {
            var start = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardInput  = !noAcknowledgments,
                RedirectStandardError  = false,         // #1629
                CreateNoWindow         = true,
                StandardOutputEncoding = Encoding.UTF8, // #1713
                WorkingDirectory       = null           // by default it's null
            };

            start.SetEnvironmentVariables(benchmarkCase, resolver);

            string exePath = artifactsPaths.ExecutablePath;

            var runtime = benchmarkCase.GetRuntime();

            // TODO: use resolver

            switch (runtime)
            {
            case ClrRuntime _:
            case CoreRuntime _:
            case NativeAotRuntime _:
                start.FileName  = exePath;
                start.Arguments = args;
                break;

            case MonoRuntime mono:
                start.FileName  = mono.CustomPath ?? "mono";
                start.Arguments = GetMonoArguments(benchmarkCase.Job, exePath, args, resolver);
                break;

            case WasmRuntime wasm:
                start.FileName = wasm.JavaScriptEngine;
                start.RedirectStandardInput = false;

                string main_js = runtime.RuntimeMoniker < RuntimeMoniker.WasmNet70 ? "main.js" : "test-main.js";

                start.Arguments        = $"{wasm.JavaScriptEngineArguments} {main_js} -- --run {artifactsPaths.ProgramName}.dll {args} ";
                start.WorkingDirectory = artifactsPaths.BinariesDirectoryPath;
                break;

            case MonoAotLLVMRuntime _:
                start.FileName         = exePath;
                start.Arguments        = args;
                start.WorkingDirectory = artifactsPaths.BinariesDirectoryPath;
                break;

            default:
                throw new NotSupportedException("Runtime = " + runtime);
            }
            return(start);
        }
예제 #2
0
        public long GetBytesAllocatedPerOperation(BenchmarkCase benchmarkCase)
        {
            bool excludeAllocationQuantumSideEffects = benchmarkCase.GetRuntime().RuntimeMoniker <= RuntimeMoniker.NetCoreApp20; // the issue got fixed for .NET Core 2.0+ https://github.com/dotnet/coreclr/issues/10207

            return(GetTotalAllocatedBytes(excludeAllocationQuantumSideEffects) == 0
                ? 0
                : (long)Math.Round(  // let's round it to reduce the side effects of Allocation quantum
                       (double)GetTotalAllocatedBytes(excludeAllocationQuantumSideEffects) / TotalOperations,
                       MidpointRounding.ToEven));
        }
        public SynchronousProcessOutputLoggerWithDiagnoser(ILogger logger, Process process, IDiagnoser diagnoser, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId)
        {
            if (!process.StartInfo.RedirectStandardOutput)
            {
                throw new NotSupportedException("set RedirectStandardOutput to true first");
            }
            if (!(process.StartInfo.RedirectStandardInput || benchmarkCase.GetRuntime() is WasmRuntime))
            {
                throw new NotSupportedException("set RedirectStandardInput to true first");
            }

            this.logger               = logger;
            this.process              = process;
            this.diagnoser            = diagnoser;
            diagnoserActionParameters = new DiagnoserActionParameters(process, benchmarkCase, benchmarkId);

            LinesWithResults     = new List <string>();
            LinesWithExtraOutput = new List <string>();
        }
예제 #4
0
        internal static void SetEnvironmentVariables(this ProcessStartInfo start, BenchmarkCase benchmarkCase, IResolver resolver)
        {
            if (benchmarkCase.Job.Environment.Runtime is ClrRuntime clrRuntime && !string.IsNullOrEmpty(clrRuntime.Version))
            {
                start.EnvironmentVariables["COMPLUS_Version"] = clrRuntime.Version;
            }

            if (benchmarkCase.Job.Environment.Runtime is MonoRuntime monoRuntime && !string.IsNullOrEmpty(monoRuntime.MonoBclPath))
            {
                start.EnvironmentVariables["MONO_PATH"] = monoRuntime.MonoBclPath;
            }

            // corerun does not understand runtimeconfig.json files;
            // we have to set "COMPlus_GC*" environment variables as documented in
            // https://docs.microsoft.com/en-us/dotnet/core/run-time-config/garbage-collector
            if (benchmarkCase.Job.Infrastructure.Toolchain is CoreRunToolchain _)
            {
                start.SetCoreRunEnvironmentVariables(benchmarkCase, resolver);
            }

            // disable ReSharper's Dynamic Program Analysis (see https://github.com/dotnet/BenchmarkDotNet/issues/1871 for details)
            start.EnvironmentVariables["JETBRAINS_DPA_AGENT_ENABLE"] = "0";

            if (benchmarkCase.Job.Infrastructure.Toolchain is MonoAotLLVMToolChain)
            {
                MonoAotLLVMRuntime aotruntime = (MonoAotLLVMRuntime)benchmarkCase.GetRuntime();

                if (aotruntime.AOTCompilerMode == MonoAotCompilerMode.llvm)
                {
                    start.EnvironmentVariables["MONO_ENV_OPTIONS"] = "--llvm";
                }
            }

            if (!benchmarkCase.Job.HasValue(EnvironmentMode.EnvironmentVariablesCharacteristic))
            {
                return;
            }

            foreach (var environmentVariable in benchmarkCase.Job.Environment.EnvironmentVariables)
            {
                start.EnvironmentVariables[environmentVariable.Key] = environmentVariable.Value;
            }
        }