From b2d5d63e5194265e18c448d7f014585bf0bad2d4 Mon Sep 17 00:00:00 2001 From: Juan Hoyos Date: Thu, 12 Aug 2021 11:09:59 -0700 Subject: [PATCH] Emit V1 of perfmap files in ShareFramework packages (#57195) * Add perfmap v1 flag on crossgen2 invocation for SPC * Sync target and task for CrossGen2 from SDK repo * Consume new SFX SDK version --- eng/Version.Details.xml | 4 +-- global.json | 2 +- src/coreclr/crossgen-corelib.proj | 3 +- .../Microsoft.NETCore.App/ReadyToRun.targets | 7 +++- .../CommonFilePulledFromSdkRepo/Logger.cs | 5 ++- .../MetadataKeys.cs | 4 ++- .../Microsoft.NET.CrossGen.targets | 26 ++++++++++---- .../PrepareForReadyToRunCompilation.cs | 36 +++++++++++++------ .../ResolveReadyToRunCompilers.cs | 7 +++- .../Crossgen2Tasks/RunReadyToRunCompiler.cs | 17 ++++++++- 10 files changed, 85 insertions(+), 26 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 176dba9fe17040..ffd7f3a024d4c9 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -78,9 +78,9 @@ https://github.com/dotnet/arcade 382667fff0b58c362855a42c3529ba294fd0514c - + https://github.com/dotnet/arcade - 382667fff0b58c362855a42c3529ba294fd0514c + 70de8c7a1a5230d4dc8e273dcb0057805165ae19 https://github.com/microsoft/vstest diff --git a/global.json b/global.json index ce35288f8268cb..d234281fc93b76 100644 --- a/global.json +++ b/global.json @@ -15,7 +15,7 @@ "Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.21406.6", "Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.21406.6", "Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.21406.6", - "Microsoft.DotNet.SharedFramework.Sdk": "6.0.0-beta.21406.6", + "Microsoft.DotNet.SharedFramework.Sdk": "6.0.0-beta.21411.6", "Microsoft.Build.NoTargets": "3.1.0", "Microsoft.Build.Traversal": "3.0.23", "Microsoft.NET.Sdk.IL": "6.0.0-rc.1.21411.3" diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 655fc3281eb2ef..847066a891c07c 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -52,7 +52,7 @@ $([MSBuild]::NormalizePath('$(BinDir)', 'PDB', '$(CoreLibAssemblyName).ni.pdb')) - $([MSBuild]::NormalizePath('$(BinDir)', '$(CoreLibAssemblyName).perf.map')) + $([MSBuild]::NormalizePath('$(BinDir)', '$(CoreLibAssemblyName).ni.r2rmap')) $([MSBuild]::NormalizePath('$(BinDir)', 'StandardOptimizationData.mibc')) @@ -97,6 +97,7 @@ $(CrossGenDllCmd) -o:$(CoreLibOutputPath) $(CrossGenDllCmd) -r:$([MSBuild]::NormalizePath('$(BinDir)', 'IL', '*.dll')) $(CrossGenDllCmd) --targetarch:$(TargetArchitecture) + $(CrossGenDllCmd) --perfmap-format-version:1 @(OptimizationMibcFiles->'-m:$(MergedMibcPath)', ' ') $(CrossGenDllCmd) $(MibcArgs) --embed-pgo-data $(CrossGenDllCmd) -O diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/ReadyToRun.targets b/src/installer/pkg/sfx/Microsoft.NETCore.App/ReadyToRun.targets index 227c7f4a7d896b..4e3f684dedc20a 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/ReadyToRun.targets +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/ReadyToRun.targets @@ -20,6 +20,7 @@ true @(PublishReadyToRunCrossgen2ExtraArgsList) + 1 .sh .cmd @@ -42,7 +43,11 @@ DiaSymReader="$(_diaSymReaderPath)" /> - + diff --git a/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/Logger.cs b/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/Logger.cs index d77fed2fc65271..4c5ac74ba1c191 100644 --- a/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/Logger.cs +++ b/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/Logger.cs @@ -65,6 +65,9 @@ public void LogWarning(string format, params string[] args) public void LogError(string format, params string[] args) => Log(CreateMessage(MessageLevel.Error, format, args)); + public void LogNonSdkError(string code, string format, params string[] args) + => Log(new Message(MessageLevel.Error, string.Format(format, args), code)); + public void Log(in Message message) { HasLoggedErrors |= message.Level == MessageLevel.Error; @@ -140,4 +143,4 @@ private static void DebugThrowMissingOrIncorrectCode(string code, string message private static bool IsAsciiDigit(char c) => c >= '0' && c <= '9'; } -} +} \ No newline at end of file diff --git a/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/MetadataKeys.cs b/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/MetadataKeys.cs index e3df2f4dc81757..d6955cf85bb4e8 100644 --- a/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/MetadataKeys.cs +++ b/src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/MetadataKeys.cs @@ -17,6 +17,7 @@ internal static class MetadataKeys public const string AllowExplicitVersion = "AllowExplicitVersion"; public const string RelativePath = "RelativePath"; public const string DiagnosticLevel = "DiagnosticLevel"; + public const string Implementation = "Implementation"; // Metadata on WinMD references // Target Metadata public const string RuntimeIdentifier = "RuntimeIdentifier"; @@ -123,5 +124,6 @@ internal static class MetadataKeys public const string EmitSymbols = "EmitSymbols"; public const string IsVersion5 = "IsVersion5"; public const string CreateCompositeImage = "CreateCompositeImage"; + public const string PerfmapFormatVersion = "PerfmapFormatVersion"; } -} +} \ No newline at end of file diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index 1a133ed839bbd9..251336540b5bb3 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -11,12 +11,18 @@ Copyright (c) .NET Foundation. All rights reserved. --> - - - true + + + true false true false + true + 1 - + \ No newline at end of file diff --git a/src/tasks/Crossgen2Tasks/PrepareForReadyToRunCompilation.cs b/src/tasks/Crossgen2Tasks/PrepareForReadyToRunCompilation.cs index a664a967d88931..40235b9092bc47 100644 --- a/src/tasks/Crossgen2Tasks/PrepareForReadyToRunCompilation.cs +++ b/src/tasks/Crossgen2Tasks/PrepareForReadyToRunCompilation.cs @@ -57,6 +57,7 @@ public class PrepareForReadyToRunCompilation : TaskBase public ITaskItem[] ReadyToRunCompositeBuildInput => _r2rCompositeInput.ToArray(); private bool _crossgen2IsVersion5; + private int _perfmapFormatVersion; private List _compileList = new List(); private List _symbolsCompileList = new List(); @@ -72,6 +73,9 @@ protected override void ExecuteCore() string isVersion5 = Crossgen2Tool.GetMetadata(MetadataKeys.IsVersion5); _crossgen2IsVersion5 = !string.IsNullOrEmpty(isVersion5) && bool.Parse(isVersion5); + string perfmapVersion = Crossgen2Tool.GetMetadata(MetadataKeys.PerfmapFormatVersion); + _perfmapFormatVersion = !string.IsNullOrEmpty(perfmapVersion) ? int.Parse(perfmapVersion) : 0; + if (Crossgen2Composite && EmitSymbols && _crossgen2IsVersion5) { Log.LogError(Strings.Crossgen5CannotEmitSymbolsInCompositeMode); @@ -144,16 +148,25 @@ private void ProcessInputFileList( } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - using (FileStream fs = new FileStream(file.ItemSpec, FileMode.Open, FileAccess.Read)) + string perfmapExtension; + if (ReadyToRunUseCrossgen2 && !_crossgen2IsVersion5 && _perfmapFormatVersion >= 1) { - PEReader pereader = new PEReader(fs); - MetadataReader mdReader = pereader.GetMetadataReader(); - Guid mvid = mdReader.GetGuid(mdReader.GetModuleDefinition().Mvid); - - outputPDBImage = Path.ChangeExtension(outputR2RImage, "ni.{" + mvid + "}.map"); - outputPDBImageRelativePath = Path.ChangeExtension(outputR2RImageRelativePath, "ni.{" + mvid + "}.map"); - crossgen1CreatePDBCommand = $"/CreatePerfMap \"{Path.GetDirectoryName(outputPDBImage)}\""; + perfmapExtension = ".ni.r2rmap"; } + else + { + using (FileStream fs = new FileStream(file.ItemSpec, FileMode.Open, FileAccess.Read)) + { + PEReader pereader = new PEReader(fs); + MetadataReader mdReader = pereader.GetMetadataReader(); + Guid mvid = mdReader.GetGuid(mdReader.GetModuleDefinition().Mvid); + perfmapExtension = ".ni.{" + mvid + "}.map"; + } + } + + outputPDBImage = Path.ChangeExtension(outputR2RImage, perfmapExtension); + outputPDBImageRelativePath = Path.ChangeExtension(outputR2RImageRelativePath, perfmapExtension); + crossgen1CreatePDBCommand = $"/CreatePerfMap \"{Path.GetDirectoryName(outputPDBImage)}\""; } } @@ -240,8 +253,9 @@ private void ProcessInputFileList( } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - compositePDBImage = Path.ChangeExtension(compositeR2RImage, ".ni.{composite}.map"); - compositePDBRelativePath = Path.ChangeExtension(compositeR2RImageRelativePath, ".ni.{composite}.map"); + string perfmapExtension = (_perfmapFormatVersion >= 1 ? ".ni.r2rmap" : ".ni.{composite}.map"); + compositePDBImage = Path.ChangeExtension(compositeR2RImage, perfmapExtension); + compositePDBRelativePath = Path.ChangeExtension(compositeR2RImageRelativePath, perfmapExtension); } if (compositePDBImage != null && ReadyToRunUseCrossgen2 && !_crossgen2IsVersion5) @@ -488,4 +502,4 @@ private static bool HasILCode(PEReader peReader, MetadataReader mdReader) return false; } } -} +} \ No newline at end of file diff --git a/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs b/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs index d44b98519233e6..8c3e602ae77259 100644 --- a/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs +++ b/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs @@ -17,6 +17,7 @@ public class ResolveReadyToRunCompilers : TaskBase { public bool EmitSymbols { get; set; } public bool ReadyToRunUseCrossgen2 { get; set; } + public string PerfmapFormatVersion { get; set; } [Required] public ITaskItem[] RuntimePacks { get; set; } @@ -177,6 +178,10 @@ private bool ValidateCrossgen2Support() { Crossgen2Tool.SetMetadata(MetadataKeys.TargetOS, targetOS); Crossgen2Tool.SetMetadata(MetadataKeys.TargetArch, ArchitectureToString(_targetArchitecture)); + if (!string.IsNullOrEmpty(PerfmapFormatVersion)) + { + Crossgen2Tool.SetMetadata(MetadataKeys.PerfmapFormatVersion, PerfmapFormatVersion); + } } _crossgen2IsVersion5 = version5; @@ -397,4 +402,4 @@ private static string ArchitectureToString(Architecture architecture) }; } } -} +} \ No newline at end of file diff --git a/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs b/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs index 2f6ed265fb6674..a71cee659acb62 100644 --- a/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs +++ b/src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs @@ -25,6 +25,7 @@ public class RunReadyToRunCompiler : ToolTask public bool ShowCompilerWarnings { get; set; } public bool UseCrossgen2 { get; set; } public string Crossgen2ExtraCommandLineArgs { get; set; } + public ITaskItem[] Crossgen2PgoFiles { get; set; } [Output] public bool WarningsDetected { get; set; } @@ -326,6 +327,20 @@ private string GenerateCrossgen2ResponseFile() { result.AppendLine("--perfmap"); result.AppendLine($"--perfmap-path:{Path.GetDirectoryName(_outputPDBImage)}"); + + string perfmapFormatVersion = Crossgen2Tool.GetMetadata(MetadataKeys.PerfmapFormatVersion); + if (!string.IsNullOrEmpty(perfmapFormatVersion)) + { + result.AppendLine($"--perfmap-format-version:{perfmapFormatVersion}"); + } + } + } + + if (Crossgen2PgoFiles != null) + { + foreach (var mibc in Crossgen2PgoFiles) + { + result.AppendLine($"-m:\"{mibc.ItemSpec}\""); } } @@ -393,4 +408,4 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport } } } -} +} \ No newline at end of file