コード例 #1
0
ファイル: SoDBench.cs プロジェクト: zdrsh/coreclr
            public static SoDBenchOptions Parse(string[] args)
            {
                using (var parser = new Parser((settings) => {
                    settings.CaseInsensitiveEnumValues = true;
                    settings.CaseSensitive = false;
                    settings.HelpWriter = new StringWriter();
                    settings.IgnoreUnknownArguments = true;
                }))
                {
                    SoDBenchOptions options = null;
                    parser.ParseArguments <SoDBenchOptions>(args)
                    .WithParsed(parsed => options = parsed)
                    .WithNotParsed(errors => {
                        foreach (Error error in errors)
                        {
                            switch (error.Tag)
                            {
                            case ErrorType.MissingValueOptionError:
                                throw new ArgumentException(
                                    $"Missing value option for command line argument '{(error as MissingValueOptionError).NameInfo.NameText}'");

                            case ErrorType.HelpRequestedError:
                                Console.WriteLine(Usage());
                                Environment.Exit(0);
                                break;

                            case ErrorType.VersionRequestedError:
                                Console.WriteLine(new AssemblyName(typeof(SoDBenchOptions).GetTypeInfo().Assembly.FullName).Version);
                                Environment.Exit(0);
                                break;

                            case ErrorType.BadFormatTokenError:
                            case ErrorType.UnknownOptionError:
                            case ErrorType.MissingRequiredOptionError:
                            case ErrorType.MutuallyExclusiveSetError:
                            case ErrorType.BadFormatConversionError:
                            case ErrorType.SequenceOutOfRangeError:
                            case ErrorType.RepeatedOptionError:
                            case ErrorType.NoVerbSelectedError:
                            case ErrorType.BadVerbSelectedError:
                            case ErrorType.HelpVerbRequestedError:
                                break;
                            }
                        }
                    });

                    if (options != null && !String.IsNullOrEmpty(options.DotnetExecutable) && !String.IsNullOrEmpty(options.CoreLibariesDirectory))
                    {
                        throw new ArgumentException("--dotnet and --corlibs cannot be used together");
                    }

                    return(options);
                }
            }
コード例 #2
0
ファイル: SoDBench.cs プロジェクト: zdrsh/coreclr
        static void Main(string[] args)
        {
            try
            {
                var options = SoDBenchOptions.Parse(args);

                s_targetArchitecture = options.TargetArchitecture;
                s_dotnetChannel      = options.DotnetChannel;
                s_keepArtifacts      = options.KeepArtifacts;

                if (!String.IsNullOrWhiteSpace(options.DotnetExecutable))
                {
                    s_dotnetExe = new FileInfo(options.DotnetExecutable);
                }

                if (s_sandboxDir == null)
                {
                    // Truncate the Guid used for anti-collision because a full Guid results in expanded paths over 260 chars (the Windows max)
                    s_sandboxDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), $"sod{Guid.NewGuid().ToString().Substring(0,13)}"));
                    s_sandboxDir.Create();
                    Console.WriteLine($"** Running inside sandbox directory: {s_sandboxDir}");
                }

                if (s_dotnetExe == null)
                {
                    if (!String.IsNullOrEmpty(options.CoreLibariesDirectory))
                    {
                        Console.WriteLine($"** Using core libraries found at {options.CoreLibariesDirectory}");
                        s_corelibsDir = new DirectoryInfo(options.CoreLibariesDirectory);
                    }
                    else
                    {
                        var coreroot = Environment.GetEnvironmentVariable("CORE_ROOT");
                        if (!String.IsNullOrEmpty(coreroot) && Directory.Exists(coreroot))
                        {
                            Console.WriteLine($"** Using core libraries from CORE_ROOT at {coreroot}");
                            s_corelibsDir = new DirectoryInfo(coreroot);
                        }
                        else
                        {
                            Console.WriteLine("** Using default dotnet-cli core libraries");
                        }
                    }

                    PrintHeader("** Installing Dotnet CLI");
                    s_dotnetExe = SetupDotnet();
                }

                if (s_fallbackDir == null)
                {
                    s_fallbackDir = new DirectoryInfo(Path.Combine(s_sandboxDir.FullName, "fallback"));
                    s_fallbackDir.Create();
                }

                Console.WriteLine($"** Path to dotnet executable: {s_dotnetExe.FullName}");

                PrintHeader("** Starting acquisition size test");
                var acquisition = GetAcquisitionSize();

                PrintHeader("** Running deployment size test");
                var deployment = GetDeploymentSize();

                var root = new SizeReportingNode("Dotnet Total");
                root.AddChild(acquisition);
                root.AddChild(deployment);

                var formattedStr = root.FormatAsCsv();

                File.WriteAllText(options.OutputFilename, formattedStr);

                if (options.Verbose)
                {
                    Console.WriteLine($"** CSV Output:\n{formattedStr}");
                }
            }
            finally
            {
                if (!s_keepArtifacts && s_sandboxDir != null)
                {
                    PrintHeader("** Cleaning up sandbox directory");
                    DeleteDirectory(s_sandboxDir);
                    s_sandboxDir = null;
                }
            }
        }