Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/BenchmarkDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="deniszykov.WebSocketListener" Version="4.2.19" />
<PackageReference Include="Gee.External.Capstone" Version="2.3.0" />
<PackageReference Include="Iced" Version="1.21.0" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="3.1.512801" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="4.0.0-beta.26203.1" />
<PackageReference Include="Perfolizer" Version="[0.6.6]" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.30" PrivateAssets="contentfiles;analyzers" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
Expand Down
45 changes: 16 additions & 29 deletions src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Filters;
Expand Down Expand Up @@ -41,41 +41,36 @@ private static bool IsValidAddress(ulong address)

private DataTarget Attach(int processId)
{
var dataTargetOptions = new DataTargetOptions
{
SymbolPaths = ["https://msdl.microsoft.com/download/symbols"],
// TODO: Configure DataTargetLimits default values
};

// Ensure symbol cache directory exists https://github.com/microsoft/clrmd/issues/1417
Directory.CreateDirectory(dataTargetOptions.SymbolCachePath);

bool isSelf = processId == System.Diagnostics.Process.GetCurrentProcess().Id;
if (OsDetector.IsWindows())
{
// Windows CoreCLR fails to disassemble generic types when using CreateSnapshotAndAttach, and succeeds with AttachToProcess. https://github.com/microsoft/clrmd/issues/1334
return isSelf && !RuntimeInformation.IsNetCore
? DataTarget.CreateSnapshotAndAttach(processId)
: DataTarget.AttachToProcess(processId, suspend: false);
? DataTarget.CreateSnapshotAndAttach(processId, dataTargetOptions)
: DataTarget.AttachToProcess(processId, suspend: false, dataTargetOptions);
}
if (OsDetector.IsLinux())
{
// Linux crashes when using AttachToProcess in the same process.
// It seems not fixed by https://github.com/microsoft/clrmd/issues/1282
return isSelf
? DataTarget.CreateSnapshotAndAttach(processId)
: DataTarget.AttachToProcess(processId, suspend: false);
}
if (OsDetector.IsMacOS())
{
// ClrMD does not support CreateSnapshotAndAttach on MacOS, and AttachToProcess is unreliable, so we have to create a dump file and load it.
string dumpPath = Path.GetTempFileName();
try
{
try
{
new DiagnosticsClient(processId).WriteDump(DumpType.Full, dumpPath, logDumpGeneration: false);
}
catch (ServerErrorException sxe)
{
throw new ArgumentException($"Unable to create a snapshot of process {processId:x}.", sxe);
}
return DataTarget.LoadDump(dumpPath);
}
finally
{
File.Delete(dumpPath);
}
// On macOS it need to use CreateSnapshotAndAttach API instead of AttachToProcess.
// https://github.com/microsoft/clrmd/issues/1034
return DataTarget.CreateSnapshotAndAttach(processId, dataTargetOptions);
}
throw new NotSupportedException($"{System.Runtime.InteropServices.RuntimeInformation.OSDescription} is not supported");
}
Expand All @@ -86,8 +81,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)

var runtime = dataTarget.ClrVersions.Single().CreateRuntime();

ConfigureSymbols(dataTarget);

var state = new State(runtime, args.TargetFrameworkMoniker);

if (args.Filters.Length > 0)
Expand Down Expand Up @@ -120,12 +113,6 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
};
}

private static void ConfigureSymbols(DataTarget dataTarget)
{
// code copied from https://github.com/Microsoft/clrmd/issues/34#issuecomment-161926535
dataTarget.SetSymbolPath("http://msdl.microsoft.com/download/symbols");
}

private static void FilterAndEnqueue(State state, ClrMdArgs args)
{
Regex[] filters = GlobFilter.ToRegex(args.Filters);
Expand Down