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

Fixing the reminder of crash dumps #2520

Merged
4 commits merged into from
Aug 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,19 @@ public override void Initialize(
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgEnableElfDumpOnMacOS", "1"));
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgEnableMiniDump", "1"));

if (!this.processFullDumpEnabled)
{
// https://github.com/dotnet/coreclr/blob/master/Documentation/botr/xplat-minidump-generation.md
// MiniDumpWithPrivateReadWriteMemory = 2
// MiniDumpNormal = 1
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgMiniDumpType", this.processFullDumpEnabled ? "2" : "1"));
}

var guid = Guid.NewGuid().ToString();

var dumpDirectory = Path.Combine(Path.GetTempPath(), guid);
Directory.CreateDirectory(dumpDirectory);
var dumpPath = Path.Combine(dumpDirectory, $"dotnet_%d_crashdump.dmp");
var dumpPath = Path.Combine(dumpDirectory, $"%e_%p_%t_crashdump.dmp");
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgMiniDumpName", dumpPath));
}

Expand Down Expand Up @@ -416,8 +424,12 @@ private void SessionEndedHandler(object sender, SessionEndEventArgs args)
var filepath = Path.Combine(this.GetTempDirectory(), Constants.AttachmentFileName + "_" + this.attachmentGuid);

filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, this.testObjectDictionary, filepath);
var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
this.dataCollectionSink.SendFileAsync(fileTranferInformation);
var fti = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
this.dataCollectionSink.SendFileAsync(fti);
}
else
{
this.logger.LogWarning(this.context.SessionDataCollectionContext, Resources.Resources.NotGeneratingSequenceFile);
}

if (this.collectProcessDumpOnTrigger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using NuGet.Frameworks;

internal class CrashDumperFactory : ICrashDumperFactory
{
public ICrashDumper Create(string targetFramework)
{
if (targetFramework is null)
{
throw new ArgumentNullException(nameof(targetFramework));
}

EqtTrace.Info($"CrashDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}.");

var tfm = NuGetFramework.Parse(targetFramework);

if (tfm == null || tfm.IsUnsupported)
{
EqtTrace.Error($"CrashDumperFactory: Could not parse target framework {targetFramework}, to a supported framework version.");
throw new NotSupportedException($"Could not parse target framework {targetFramework}, to a supported framework version.");
}

var isNet50OrNewer = tfm.Framework == ".NETCoreApp" && tfm.Version >= Version.Parse("5.0.0.0");

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
EqtTrace.Info($"CrashDumperFactory: This is Windows, returning ProcDumpCrashDumper that uses ProcDump utility.");
Expand All @@ -28,7 +45,7 @@ public ICrashDumper Create(string targetFramework)
// return new NetClientCrashDumper();
}

if (!string.IsNullOrWhiteSpace(targetFramework) && targetFramework.Contains("v5.0"))
if (isNet50OrNewer)
{
EqtTrace.Info($"CrashDumperFactory: This is {RuntimeInformation.OSDescription} on {targetFramework} .NETClient dumper which uses env variables to collect crashdumps of testhost and any child process.");
return new NetClientCrashDumper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using NuGet.Frameworks;

internal class HangDumperFactory : IHangDumperFactory
{
public IHangDumper Create(string targetFramework)
{
if (targetFramework is null)
{
throw new ArgumentNullException(nameof(targetFramework));
}

EqtTrace.Info($"HangDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}.");

var tfm = NuGetFramework.Parse(targetFramework);

if (tfm == null || tfm.IsUnsupported)
{
EqtTrace.Error($"HangDumperFactory: Could not parse target framework {targetFramework}, to a supported framework version.");
throw new NotSupportedException($"Could not parse target framework {targetFramework}, to a supported framework version.");
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
EqtTrace.Info($"HangDumperFactory: This is Windows, returning the default WindowsHangDumper that P/Invokes MiniDumpWriteDump.");
Expand All @@ -20,7 +35,8 @@ public IHangDumper Create(string targetFramework)

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (!string.IsNullOrWhiteSpace(targetFramework) && targetFramework.Contains("v2.1"))
var isLessThan31 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("3.1.0.0");
if (isLessThan31)
{
EqtTrace.Info($"HangDumperFactory: This is Linux on netcoreapp2.1, returning SigtrapDumper.");

Expand All @@ -33,7 +49,8 @@ public IHangDumper Create(string targetFramework)

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
if (!string.IsNullOrWhiteSpace(targetFramework) && !targetFramework.Contains("v5.0"))
var isLessThan50 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("5.0.0.0");
if (isLessThan50)
{
EqtTrace.Info($"HangDumperFactory: This is OSX on {targetFramework}, This combination of OS and framework is not supported.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ProjectReference Include="..\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' AND '$(OS)' != 'Windows_NT' ">
<Reference Include="System" />
<Reference Include="System.Runtime" />
<Reference Include="System.Xml" />
Expand All @@ -34,7 +34,6 @@
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client">
<Version>0.2.0-preview.20378.10</Version>
</PackageReference>
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Resources.Designer.cs">
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
<data name="InactivityTimeout" xml:space="preserve">
<value>The specified inactivity time of {0} minute/s has elapsed. Collecting a dump and killing the test host process.</value>
</data>
<data name="NotGeneratingSequenceFile" xml:space="preserve">
<value>All tests finished running, Sequence file will not be generated.</value>
<comment>"Sequence" is the name of the file.</comment>
</data>
<data name="ProcDumpCouldNotStart" xml:space="preserve">
<value>Could not start process dump: {0}</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/testhost.x86/testhost.x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<FromP2P>true</FromP2P>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
<Reference Include="netstandard" />
<Reference Include="System" />
<Reference Include="System.Runtime" />
Expand Down
2 changes: 1 addition & 1 deletion src/testhost/testhost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<FromP2P>true</FromP2P>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
<Reference Include="netstandard" />
<Reference Include="System" />
<Reference Include="System.Runtime" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Extensions.BlameDataCollector\Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' AND '$(OS)' != 'Windows_NT' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' AND '$(OS)' != 'Windows_NT' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
Expand Down