private static SizeReportingNode GetAcquisitionSize() { var result = new SizeReportingNode("Acquisition Size"); // Arbitrary command to trigger first time setup ProcessStartInfo dotnet = new ProcessStartInfo() { WorkingDirectory = s_sandboxDir.FullName, FileName = s_dotnetExe.FullName, Arguments = "new" }; // Used to set where the packages will be unpacked to. // There is a no gaurentee that this is a stable method, but is the only way currently to set the fallback folder location dotnet.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; LaunchProcess(dotnet, 180000); Console.WriteLine("\n** Measuring total size of acquired files"); result.AddChild(new SizeReportingNode(s_fallbackDir, 1)); var dotnetNode = new SizeReportingNode(s_dotnetExe.Directory); var reportingDepths = new Dictionary <string, int> { { "additionalDeps", 1 }, { "host", 0 }, { "sdk", 2 }, { "shared", 2 }, { "store", 3 } }; foreach (var childNode in dotnetNode.Children) { int depth = 0; if (reportingDepths.TryGetValue(childNode.Name, out depth)) { childNode.LimitReportingDepth(depth); } } result.AddChild(dotnetNode); return(result); }
private static SizeReportingNode GetDeploymentSize() { // Write the NuGet.Config file var nugetConfFile = new FileInfo(Path.Combine(s_sandboxDir.FullName, "NuGet.Config")); File.WriteAllText(nugetConfFile.FullName, NugetConfig); var result = new SizeReportingNode("Deployment Size"); foreach (string template in NewTemplates) { var templateNode = new SizeReportingNode(template); result.AddChild(templateNode); foreach (var os in OperatingSystems) { Console.WriteLine($"\n\n** Deploying {template}/{os}"); var deploymentSandbox = new DirectoryInfo(Path.Combine(s_sandboxDir.FullName, template, os)); var publishDir = new DirectoryInfo(Path.Combine(deploymentSandbox.FullName, "publish")); deploymentSandbox.Create(); ProcessStartInfo dotnetNew = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, Arguments = $"new {template}", UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; dotnetNew.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; ProcessStartInfo dotnetRestore = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, Arguments = $"restore --runtime {os}", UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; dotnetRestore.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; ProcessStartInfo dotnetPublish = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, // The UserSharedCompiler flag is set to false to prevent handles from being held that will later cause deletion of the installed SDK to fail. Arguments = $"publish -c Release --runtime {os} --output {publishDir.FullName} /p:UseSharedCompilation=false /p:UseRazorBuildServer=false", UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; dotnetPublish.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; try { LaunchProcess(dotnetNew, 180000); if (deploymentSandbox.EnumerateFiles().Any(f => f.Name.EndsWith("proj"))) { LaunchProcess(dotnetRestore, 180000); LaunchProcess(dotnetPublish, 180000); } else { Console.WriteLine($"** {template} does not have a project file to restore or publish"); } } catch (Exception e) { Console.Error.WriteLine(e.Message); continue; } // If we published this project, only report it's published size if (publishDir.Exists) { var publishNode = new SizeReportingNode(publishDir, 0); publishNode.Name = deploymentSandbox.Name; templateNode.AddChild(publishNode); if (publishNode.Size <= 0) { throw new InvalidOperationException($"{publishNode.Name} reports as invalid size {publishNode.Size}"); } } else { templateNode.AddChild(new SizeReportingNode(deploymentSandbox, 0)); } } } return(result); }
// Add the adoptee node as a child and set the adoptee's parent public void AddChild(SizeReportingNode adoptee) { Children.Add(adoptee); adoptee.Parent = this; _size = null; }
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; } } }
private static SizeReportingNode GetDeploymentSize() { // Write the NuGet.Config file var nugetConfFile = new FileInfo(Path.Combine(s_sandboxDir.FullName, "NuGet.Config")); File.WriteAllText(nugetConfFile.FullName, NugetConfig); var result = new SizeReportingNode("Deployment Size"); foreach (string template in NewTemplates) { var templateNode = new SizeReportingNode(template); result.AddChild(templateNode); foreach (var os in OperatingSystems) { Console.WriteLine($"\n\n** Deploying {template}/{os}"); var deploymentSandbox = new DirectoryInfo(Path.Combine(s_sandboxDir.FullName, template, os)); var publishDir = new DirectoryInfo(Path.Combine(deploymentSandbox.FullName, "publish")); deploymentSandbox.Create(); ProcessStartInfo dotnetNew = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, Arguments = $"new {template}", UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; dotnetNew.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; ProcessStartInfo dotnetRestore = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, Arguments = $"restore --runtime {os}", UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; dotnetRestore.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; ProcessStartInfo dotnetPublish = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, Arguments = $"publish -c Release --runtime {os} --output {publishDir.FullName}", // "out" is an arbitrary project name UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; dotnetPublish.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = s_fallbackDir.FullName; try { LaunchProcess(dotnetNew, 180000); if (deploymentSandbox.EnumerateFiles().Any(f => f.Name.EndsWith("proj"))) { LaunchProcess(dotnetRestore, 180000); LaunchProcess(dotnetPublish, 180000); } else { Console.WriteLine($"** {template} does not have a project file to restore or publish"); } } catch (Exception e) { Console.Error.WriteLine(e.Message); continue; } // If we published this project, only report published it's size if (publishDir.Exists) { var publishNode = new SizeReportingNode(publishDir, 0); publishNode.Name = deploymentSandbox.Name; templateNode.AddChild(publishNode); } else { templateNode.AddChild(new SizeReportingNode(deploymentSandbox, 0)); } } } return(result); }