Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDK support for perfmap format version #19132

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Tasks/Common/MetadataKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,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";
}
}
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
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
6 changes: 6 additions & 0 deletions src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ 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}");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<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 @@ -439,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 Down