Skip to content
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/BenchmarkDotNet/BenchmarkDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageReference Include="System.Management" Version="10.0.1" />
<PackageReference Include="System.Text.Json" Version="10.0.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
Expand Down
64 changes: 20 additions & 44 deletions src/BenchmarkDotNet/Disassemblers/ClrMdArgs.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
using System;
using BenchmarkDotNet.Serialization;
using System.Linq;
using SimpleJson;
using System.Text.Json.Serialization;

#nullable enable

namespace BenchmarkDotNet.Disassemblers
{
internal struct ClrMdArgs(int processId, string typeName, string methodName, bool printSource, int maxDepth, string syntax, string tfm, string[] filters, string resultsPath = "")
{
[JsonIgnore]
internal int ProcessId = processId;
internal string TypeName = typeName;

[JsonIgnore]
internal string TypeName = typeName ?? "";

[JsonInclude]
internal string MethodName = methodName;

[JsonInclude]
internal bool PrintSource = printSource;

[JsonInclude]
internal int MaxDepth = methodName == DisassemblerConstants.DisassemblerEntryMethodName && maxDepth != int.MaxValue ? maxDepth + 1 : maxDepth;

[JsonInclude]
internal string[] Filters = filters;

[JsonInclude]
internal string Syntax = syntax;

[JsonInclude]
internal string TargetFrameworkMoniker = tfm;

[JsonInclude]
internal string ResultsPath = resultsPath;

internal static ClrMdArgs FromArgs(string[] args)
Expand All @@ -30,46 +47,5 @@ internal static ClrMdArgs FromArgs(string[] args)
tfm: args[7],
filters: [.. args.Skip(8)]
);

internal readonly string Serialize()
{
SimpleJsonSerializer.CurrentJsonSerializerStrategy.Indent = false;
var jsonObject = new JsonObject()
{
[nameof(MethodName)] = MethodName,
[nameof(PrintSource)] = PrintSource,
[nameof(MaxDepth)] = MaxDepth,
[nameof(Syntax)] = Syntax,
[nameof(TargetFrameworkMoniker)] = TargetFrameworkMoniker,
[nameof(ResultsPath)] = ResultsPath,
};
var filters = new JsonArray(Filters.Length);
foreach (var filter in Filters)
{
filters.Add(filter);
}
jsonObject[nameof(Filters)] = filters;
return jsonObject.ToString();
}

internal void Deserialize(string? json)
{
var jsonObject = SimpleJsonSerializer.DeserializeObject<JsonObject>(json);
if (jsonObject == null)
return;

MethodName = (string)jsonObject[nameof(MethodName)];
PrintSource = (bool)jsonObject[nameof(PrintSource)];
MaxDepth = Convert.ToInt32(jsonObject[nameof(MaxDepth)]);
Syntax = (string) jsonObject[nameof(Syntax)];
TargetFrameworkMoniker = (string) jsonObject[nameof(TargetFrameworkMoniker)];
ResultsPath = (string) jsonObject[nameof(ResultsPath)];
var filters = (JsonArray) jsonObject[nameof(Filters)];
Filters = new string[filters.Count];
for (int i = 0; i < filters.Count; ++i)
{
Filters[i] = (string) filters[i];
}
}
}
}
8 changes: 4 additions & 4 deletions src/BenchmarkDotNet/Disassemblers/ClrMdDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static ulong GetMinValidAddress()
if (OsDetector.IsWindows())
return ushort.MaxValue + 1;
if (OsDetector.IsLinux())
return (ulong) Environment.SystemPageSize;
return (ulong)Environment.SystemPageSize;
if (OsDetector.IsMacOS())
return RuntimeInformation.GetCurrentPlatform() switch
{
Expand Down Expand Up @@ -121,8 +121,8 @@ internal DisassemblyResult AttachAndDisassemble(ClrMdArgs args)
return new DisassemblyResult
{
Methods = filteredMethods,
SerializedAddressToNameMapping = state.AddressToNameMapping.Select(x => new DisassemblyResult.MutablePair { Key = x.Key, Value = x.Value }).ToArray(),
PointerSize = (uint) IntPtr.Size
AddressToNameMapping = state.AddressToNameMapping,
PointerSize = (uint)IntPtr.Size
};
}

Expand Down Expand Up @@ -296,7 +296,7 @@ protected void TryTranslateAddressToName(ulong address, bool isAddressPrecodeMD,
}

var method = runtime.GetMethodByInstructionPointer(address);
if (method is null && (address & ((uint) runtime.DataTarget.DataReader.PointerSize - 1)) == 0
if (method is null && (address & ((uint)runtime.DataTarget.DataReader.PointerSize - 1)) == 0
&& runtime.DataTarget.DataReader.ReadPointer(address, out ulong newAddress) && IsValidAddress(newAddress))
{
method = runtime.GetMethodByInstructionPointer(newAddress);
Expand Down
Loading