Skip to content

Commit

Permalink
Emit V1 of perfmap files in ShareFramework packages (dotnet#57195)
Browse files Browse the repository at this point in the history
* Add perfmap v1 flag on crossgen2 invocation for SPC
* Sync target and task for CrossGen2 from SDK repo
* Consume new SFX SDK version
  • Loading branch information
hoyosjs authored Aug 12, 2021
1 parent e06ef79 commit b2d5d63
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 26 deletions.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>382667fff0b58c362855a42c3529ba294fd0514c</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.SharedFramework.Sdk" Version="6.0.0-beta.21406.6">
<Dependency Name="Microsoft.DotNet.SharedFramework.Sdk" Version="6.0.0-beta.21411.6">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>382667fff0b58c362855a42c3529ba294fd0514c</Sha>
<Sha>70de8c7a1a5230d4dc8e273dcb0057805165ae19</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201201-01">
<Uri>https://github.com/microsoft/vstest</Uri>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<CoreLibNiPdbPath></CoreLibNiPdbPath>
<CoreLibPerfMapPath></CoreLibPerfMapPath>
<CoreLibNiPdbPath Condition="$(BuildPdb)">$([MSBuild]::NormalizePath('$(BinDir)', 'PDB', '$(CoreLibAssemblyName).ni.pdb'))</CoreLibNiPdbPath>
<CoreLibPerfMapPath Condition="$(BuildPerfMap)">$([MSBuild]::NormalizePath('$(BinDir)', '$(CoreLibAssemblyName).perf.map'))</CoreLibPerfMapPath>
<CoreLibPerfMapPath Condition="$(BuildPerfMap)">$([MSBuild]::NormalizePath('$(BinDir)', '$(CoreLibAssemblyName).ni.r2rmap'))</CoreLibPerfMapPath>
<MergedMibcPath>$([MSBuild]::NormalizePath('$(BinDir)', 'StandardOptimizationData.mibc'))</MergedMibcPath>
</PropertyGroup>
</Target>
Expand Down Expand Up @@ -97,6 +97,7 @@
<CrossGenDllCmd>$(CrossGenDllCmd) -o:$(CoreLibOutputPath)</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -r:$([MSBuild]::NormalizePath('$(BinDir)', 'IL', '*.dll'))</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) --targetarch:$(TargetArchitecture)</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) --perfmap-format-version:1</CrossGenDllCmd>
<MibcArgs>@(OptimizationMibcFiles->'-m:$(MergedMibcPath)', ' ')</MibcArgs>
<CrossGenDllCmd Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(EnableNgenOptimization)' == 'true'">$(CrossGenDllCmd) $(MibcArgs) --embed-pgo-data</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -O</CrossGenDllCmd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<PublishReadyToRunUseCrossgen2>true</PublishReadyToRunUseCrossgen2>
<PublishReadyToRunCrossgen2ExtraArgs>@(PublishReadyToRunCrossgen2ExtraArgsList)</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunPerfmapFormatVersion Condition="'$(PublishReadyToRunPerfmapFormatVersion)' == ''">1</PublishReadyToRunPerfmapFormatVersion>

<ScriptExt>.sh</ScriptExt>
<ScriptExt Condition="'$(OS)' == 'Windows_NT'">.cmd</ScriptExt>
Expand All @@ -42,7 +43,11 @@
DiaSymReader="$(_diaSymReaderPath)" />
</ItemGroup>
<ItemGroup>
<Crossgen2Tool Include="$(Crossgen2Dll)" TargetArch="$(TargetArchitecture)" TargetOS="$(TargetOS)" DotNetHostPath="$(RepoRoot)/dotnet$(ScriptExt)" />
<Crossgen2Tool Include="$(Crossgen2Dll)"
TargetArch="$(TargetArchitecture)"
TargetOS="$(TargetOS)"
DotNetHostPath="$(RepoRoot)/dotnet$(ScriptExt)"
PerfmapFormatVersion="$(PublishReadyToRunPerfmapFormatVersion)"/>
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,4 +143,4 @@ private static void DebugThrowMissingOrIncorrectCode(string code, string message
private static bool IsAsciiDigit(char c)
=> c >= '0' && c <= '9';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
}
}
}
26 changes: 20 additions & 6 deletions src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Condition="'$(PublishReadyToRun)' == 'true' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_TargetFrameworkVersionWithoutV)' >= '3.0'">
<!-- For .NET 6 and higher, default to using Crossgen2 in non-composite mode -->
<PublishReadyToRunUseCrossgen2 Condition="'$(PublishReadyToRunUseCrossgen2)' == '' and '$(_TargetFrameworkVersionWithoutV)' >= '6.0'">true</PublishReadyToRunUseCrossgen2>
<!--
For ReadyToRun compilation, default to Crossgen for .NET Core 3.x and .NET 5. If PublishReadyToRunUseCrossgen2
is set to true in the project or on the command line, use Crossgen2 and default to composite mode. For .NET 6
and higher, always use Crossgen2 and default to non-composite mode.
-->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_TargetFrameworkVersionWithoutV)' >= '3.0'">
<PublishReadyToRunUseCrossgen2 Condition="'$(_TargetFrameworkVersionWithoutV)' >= '6.0'">true</PublishReadyToRunUseCrossgen2>
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunComposite)' == '' and '$(_TargetFrameworkVersionWithoutV)' >= '6.0'">false</PublishReadyToRunComposite>
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunComposite)' == ''">true</PublishReadyToRunComposite>
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunUseCrossgen2)' != 'true' or '$(SelfContained)' != 'true'">false</PublishReadyToRunComposite>
<PublishReadyToRunUseRuntimePackOptimizationData Condition="'$(PublishReadyToRunUseRuntimePackOptimizationData)' == ''">true</PublishReadyToRunUseRuntimePackOptimizationData>
<PublishReadyToRunPerfmapFormatVersion Condition="'$(PublishReadyToRunPerfmapFormatVersion)' == ''">1</PublishReadyToRunPerfmapFormatVersion>
</PropertyGroup>

<!--
Expand Down Expand Up @@ -397,6 +403,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<_ReadyToRunImplementationAssemblies Include="@(_ReadyToRunImplementationAssembliesWithoutConflicts)" />
</ItemGroup>

<ItemGroup>
<_ReadyToRunPgoFiles Include="@(PublishReadyToRunPgoFiles)" />
<_ReadyToRunPgoFiles Include="@(RuntimePackAsset)"
Condition="'%(RuntimePackAsset.AssetType)' == 'pgodata' and '%(RuntimePackAsset.Extension)' == '.mibc' and '$(PublishReadyToRunUseRuntimePackOptimizationData)' == 'true'" />
</ItemGroup>

<PrepareForReadyToRunCompilation CrossgenTool="@(CrossgenTool)"
Crossgen2Tool="@(Crossgen2Tool)"
OutputPath="$(_ReadyToRunOutputPath)"
Expand Down Expand Up @@ -428,7 +440,8 @@ Copyright (c) .NET Foundation. All rights reserved.
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)"
EmitSymbols="$(PublishReadyToRunEmitSymbols)"
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)">
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
PerfmapFormatVersion="$(PublishReadyToRunPerfmapFormatVersion)">

<Output TaskParameter="CrossgenTool" ItemName="CrossgenTool" />
<Output TaskParameter="Crossgen2Tool" ItemName="Crossgen2Tool" />
Expand All @@ -444,12 +457,13 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<UsingTask Condition="'$(Crossgen2TasksOverriden)' != 'true'" TaskName="RunReadyToRunCompiler" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
<Target Name="_CreateR2RImages"
Inputs="@(_ReadyToRunCompileList);@(_ReadyToRunCompositeBuildInput)"
Inputs="@(_ReadyToRunCompileList);@(_ReadyToRunCompositeBuildInput);@(_ReadyToRunPgoFiles)"
Outputs="%(_ReadyToRunCompileList.OutputR2RImage);%(_ReadyToRunCompileList.OutputPDBImage)">

<RunReadyToRunCompiler CrossgenTool="@(CrossgenTool)"
Crossgen2Tool="@(Crossgen2Tool)"
UseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
Crossgen2PgoFiles="@(_ReadyToRunPgoFiles)"
Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs)"
ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)"
ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)"
Expand Down Expand Up @@ -505,4 +519,4 @@ Copyright (c) .NET Foundation. All rights reserved.
Include="@(_ReadyToRunSymbolsCompileList)" />
</ItemGroup>
</Target>
</Project>
</Project>
36 changes: 25 additions & 11 deletions src/tasks/Crossgen2Tasks/PrepareForReadyToRunCompilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class PrepareForReadyToRunCompilation : TaskBase
public ITaskItem[] ReadyToRunCompositeBuildInput => _r2rCompositeInput.ToArray();

private bool _crossgen2IsVersion5;
private int _perfmapFormatVersion;

private List<ITaskItem> _compileList = new List<ITaskItem>();
private List<ITaskItem> _symbolsCompileList = new List<ITaskItem>();
Expand All @@ -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);
Expand Down Expand Up @@ -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)}\"";
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -488,4 +502,4 @@ private static bool HasILCode(PEReader peReader, MetadataReader mdReader)
return false;
}
}
}
}
7 changes: 6 additions & 1 deletion src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -397,4 +402,4 @@ private static string ArchitectureToString(Architecture architecture)
};
}
}
}
}
17 changes: 16 additions & 1 deletion src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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}\"");
}
}

Expand Down Expand Up @@ -393,4 +408,4 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
}
}
}
}
}

0 comments on commit b2d5d63

Please sign in to comment.