Generate symbols for profiling when running crossgen

This commit is contained in:
Nick Guerrera 2017-11-01 17:17:22 -07:00
parent a64e671a8b
commit 116da0277c
2 changed files with 40 additions and 0 deletions

View file

@ -3,7 +3,9 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@ -22,12 +24,18 @@ namespace Microsoft.DotNet.Build.Tasks
public string CrossgenPath { get; set; }
public bool CreateSymbols { get; set; }
public string DiasymReaderPath { get; set; }
public bool ReadyToRun { get; set; }
public ITaskItem[] PlatformAssemblyPaths { get; set; }
private string TempOutputPath { get; set; }
private bool _secondInvocationToCreateSymbols;
protected override bool ValidateParameters()
{
base.ValidateParameters();
@ -58,6 +66,12 @@ namespace Microsoft.DotNet.Build.Tasks
File.Delete(TempOutputPath);
}
if (toolResult && CreateSymbols)
{
_secondInvocationToCreateSymbols = true;
toolResult = base.Execute();
}
return toolResult;
}
@ -83,9 +97,30 @@ namespace Microsoft.DotNet.Build.Tasks
protected override string GenerateCommandLineCommands()
{
if (_secondInvocationToCreateSymbols)
{
return $"{GetReadyToRun()} {GetPlatformAssemblyPaths()} {GetDiasymReaderPath()} {GetCreateSymbols()}";
}
return $"{GetReadyToRun()} {GetInPath()} {GetOutPath()} {GetPlatformAssemblyPaths()} {GetJitPath()}";
}
private string GetCreateSymbols()
{
var option = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "-createpdb" : "-createperfmap";
return $"{option} \"{Path.GetDirectoryName(DestinationPath)}\" \"{DestinationPath}\"";
}
private string GetDiasymReaderPath()
{
if (string.IsNullOrEmpty(DiasymReaderPath))
{
return null;
}
return $"-diasymreaderpath \"{DiasymReaderPath}\"";
}
private string GetReadyToRun()
{
if (ReadyToRun)

View file

@ -211,6 +211,8 @@
<!-- Don't crossgen satellite assemblies -->
<SdkFiles Remove="$(PublishDir)/**/*.resources.dll" />
<DiasymReaderPath Include="$(SharedFrameworkNameVersionPath)/Microsoft.DiaSymReader.Native.*.dll" />
</ItemGroup>
<AddMetadataIsPE Items="@(SdkFiles)">
@ -235,6 +237,8 @@
JITPath="$(LibCLRJitPath)"
CrossgenPath="$(CrossgenPath)"
ReadyToRun="True"
CreateSymbols="True"
DiasymReaderPath="@(DiasymReaderPath)"
PlatformAssemblyPaths="@(PlatformAssemblies);
@(PublishDirSubDirectories);
$(SharedFrameworkNameVersionPath)" />
@ -265,6 +269,7 @@
AfterTargets="CreateSymbolsDirectory">
<ItemGroup>
<PdbsToClean Include="$(PublishDir)/**/*.pdb" />
<PdbsToClean Include="$(PublishDir)/**/*.ni.*.map" />
</ItemGroup>
<Delete Files="@(PdbsToClean)" />