Skip to content

Commit

Permalink
Upgrade to BenchmarkDotNet 0.13.2 (#118)
Browse files Browse the repository at this point in the history
* Upgrade to BenchmarkDotNet 0.13.2
- Bump BDN dependency to 0.13.2 and remove transitive pinning for System.Management.
- Bump SDK version to 6.0.400 in global.json.
- Resync ApiCompat wrappers for 0.13.2 (drop support for older versions)
- Adjust tests for API changes in 0.13.2
Closes #116, closes #115, closes #104.
Contributes to #117.

* Local copy of xrefmap-BenchmarkDotNet.yml no longer necessary for BDN 0.13.2

* Temporarly disable DocFx build on Windows
See dotnet/docfx#8097
See #119

* Set 0.13.2 as baseline for BDN API Compatibility Check
Contributes to #117
  • Loading branch information
mawosoft authored Aug 28, 2022
1 parent 221e2aa commit 0615978
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 34,047 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ jobs:
fetch-depth: 0
- name: DotNet Info
run: dotnet --info
- name: Temp. disable DocFx build on Windows
# See https://github.com/dotnet/docfx/issues/8097
if: ${{ matrix.os == 'windows-latest' }}
run: dotnet sln .\Mawosoft.Extensions.BenchmarkDotNet.sln remove .\docs\docs.csproj
- name: Build
env:
MSBuildDebugEngine: 1 # Auto-creates binlogs in ./MSBuild_Logs
Expand Down
4 changes: 1 addition & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.2" />
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
<PackageVersion Include="docfx.console" Version="2.59.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
Expand All @@ -15,8 +15,6 @@
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<!-- Transitive pinning for bug caused by outdated ref in BDN 0.13.1 -->
<PackageVersion Include="System.Management" Version="6.0.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions build/checkBdnApiCompatibility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
IsBreaking - 'true' if a new breaking issue has been reported.
.NOTES
This is currently designed for single-TFM because BDN packages target netstandard2.0.
The exception is BenchmarkDotNet.Annotations which includes netstandard1.0 as a legacy TFM.
If BDN ever becomes multi-TFM, we need to change our approach.
TODO: Add multi-TFM support.
- BenchmarkDotNet: netstandard2.0 + net6.0
- BenchmarkDotNet.Annotations: netstandard2.0 + netstandard1.0
#>

#Requires -Version 7
Expand Down Expand Up @@ -87,7 +87,7 @@ class BdnPackageInfo {
class BdnPackageSet {
static [string]$BaselineFeed = 'https://api.nuget.org/v3/index.json'
static [string]$NightlyFeed = 'https://ci.appveyor.com/nuget/benchmarkdotnet'
static [string]$BaselineVersion = '0.13.1'
static [string]$BaselineVersion = '0.13.2'
static [string]$DownloadProjectFilePath = (Join-Path $script:PSScriptRoot "ApiCompat/BdnDownload/BdnDownload.proj")
static [string]$NugetPackageRootPath = (Join-Path ([Environment]::GetFolderPath('UserProfile')) '.nuget/packages')
static [ValidateNotNullOrEmpty()][BdnPackageInfo[]]$Infos = @(
Expand Down
2 changes: 1 addition & 1 deletion docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"default",
"templates/custom"
],
"xref": [ "xrefmap-BenchmarkDotNet.yml" ],
"xref": [ "https://github.com/dotnet/BenchmarkDotNet/raw/gh-pages/xrefmap.yml" ],
"xrefService": [
"https://xref.docs.microsoft.com/query?uid={uid}"
],
Expand Down
33,874 changes: 0 additions & 33,874 deletions docs/xrefmap-BenchmarkDotNet.yml

This file was deleted.

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.302",
"version": "6.0.400",
"rollForward": "latestMinor"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Reports;
Expand All @@ -11,23 +12,23 @@ namespace Mawosoft.Extensions.BenchmarkDotNet.ApiCompat
{
internal static class ExecuteResultWrapper
{
private static readonly ConstructorInfo? s_ctorNightly;
private static readonly ConstructorInfo? s_ctorInternalStable;

static ExecuteResultWrapper()
{
s_ctorNightly = typeof(ExecuteResult).GetConstructor(
s_ctorInternalStable = typeof(ExecuteResult).GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null,
new Type[] { typeof(List<Measurement>), typeof(GcStats), typeof(ThreadingStats) },
null);
}

public static ExecuteResult CreateNightly(
List<Measurement> measurements,
public static ExecuteResult Create(
IEnumerable<Measurement> measurements,
GcStats gcStats,
ThreadingStats threadingStats)
{
return s_ctorNightly != null
? (ExecuteResult)s_ctorNightly.Invoke(new object[] { measurements, gcStats, threadingStats })
return s_ctorInternalStable != null
? (ExecuteResult)s_ctorInternalStable.Invoke(new object[] { measurements.ToList(), gcStats, threadingStats })
: throw new MissingMethodException(nameof(ExecuteResult), ".ctor");
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,18 @@ private class MockMetricDescriptor : IMetricDescriptor
1, SummaryStyle.Default) }),
DefaultConfig.Instance.CreateImmutableConfig()
);
GenerateResult generateResult = GenerateResultWrapper.Success();
GenerateResult generateResult = GenerateResult.Success(ArtifactsPaths.Empty, Array.Empty<string>(), false);
BuildResult buildResult = BuildResult.Success(generateResult);
ExecuteResult[] executeResults = Array.Empty<ExecuteResult>();
Measurement[] allMeasurements = new[] {
new Measurement(1, IterationMode.Workload, IterationStage.Result, 1, 1, 1)
};
ExecuteResult[] executeResults = new[] { ExecuteResultWrapper.Create(allMeasurements, default, default) };
Metric[] metrics = new[] { new Metric(new MockMetricDescriptor(), 1) };
BenchmarkReport benchmarkReport = BenchmarkReportWrapper.Create(
true, benchmarkCase, generateResult, buildResult, executeResults, allMeasurements,
(GcStats)default, metrics);
BenchmarkReport benchmarkReport = new(true, benchmarkCase, generateResult, buildResult, executeResults, metrics);
return new Summary(
string.Empty, ImmutableArray.Create(benchmarkReport), HostEnvironmentInfo.GetCurrent(),
string.Empty, string.Empty, TimeSpan.Zero, SummaryExtensions.GetCultureInfo(null),
ImmutableArray.Create<ValidationError>());
ImmutableArray.Create<ValidationError>(), ImmutableArray.Create<IColumnHidingRule>());
});

// Get the default columns from provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>embedded</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageReleaseNotes>
- This release supports the official BenchmarkDotNet 0.13.1 release and BenchmarkDotNet Nightly builds up to at least 0.13.1.1795.
- A reference to System.Management v6.0.0 is included to override an outdated reference in BenchmarkDotNet 0.13.1. See https://github.com/dotnet/BenchmarkDotNet/pull/1805
</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>0.2.1</PackageValidationBaselineVersion>
</PropertyGroup>
Expand Down
26 changes: 15 additions & 11 deletions src/Mawosoft.Extensions.BenchmarkDotNet/WhatifFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Environments;
Expand Down Expand Up @@ -111,17 +112,18 @@ public void PrintAsSummaries(ILogger logger)
if (_filteredBenchmarkCases.Count == 0)
return;

bool join = _filteredBenchmarkCases.Any(bc => (bc.Config.Options & ConfigOptions.JoinSummary) != 0);
IConfig? joinedConfig = _filteredBenchmarkCases.FirstOrDefault(bc => (bc.Config.Options & ConfigOptions.JoinSummary) != 0)?.Config;

GenerateResult generateResult = GenerateResultWrapper.Success();
GenerateResult generateResult = GenerateResult.Success(ArtifactsPaths.Empty, Array.Empty<string>(), false);
BuildResult buildResult = BuildResult.Success(generateResult);
IEnumerable<BenchmarkReport> reports = _filteredBenchmarkCases.Select((bc, i)
=> BenchmarkReportWrapper.Create(
true, bc, generateResult, buildResult, Array.Empty<ExecuteResult>(),
new[] { new Measurement(1, IterationMode.Workload, IterationStage.Result, 1, 1,
100_000_000 + i * 1_000_000) },
(GcStats)default, Array.Empty<Metric>()));

=> new BenchmarkReport(true, bc, generateResult, buildResult,
new[] {
ExecuteResultWrapper.Create(
new[] { new Measurement(1, IterationMode.Workload, IterationStage.Result, 1, 1, 100_000_000 + (i * 1_000_000)) },
default, default)
},
Array.Empty<Metric>()));
HostEnvironmentInfo hostEnvironmentInfo = HostEnvironmentInfo.GetCurrent();
// This is the way BDN does it. SummaryStyle.CultureInfo seems to be getting ignored.
CultureInfo cultureInfo = _filteredBenchmarkCases.First().Config.CultureInfo
Expand All @@ -137,10 +139,11 @@ public void PrintAsSummaries(ILogger logger)
logger.WriteLine();
}
logger.WriteLineInfo(HostEnvironmentInfo.GetInformation());
if (join)
if (joinedConfig != null)
{
Summary summary = new(string.Empty, reports.ToImmutableArray(), hostEnvironmentInfo,
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors);
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors,
joinedConfig.GetColumnHidingRules().ToImmutableArray());
PrintSummary(summary, logger);
}
else
Expand All @@ -151,7 +154,8 @@ public void PrintAsSummaries(ILogger logger)
reports.GroupBy(r => r.BenchmarkCase.Descriptor.Type))
{
Summary summary = new(string.Empty, group.ToImmutableArray(), hostEnvironmentInfo,
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors);
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors,
group.First().BenchmarkCase.Config.GetColumnHidingRules().ToImmutableArray());
logger.WriteLine();
logger.WriteLineHeader($"// {(useFullName ? group.Key.FullName : group.Key.Name)}");
logger.WriteLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private class GetExtendedColumnCategory_TheoryData : TheoryData<IColumn, Extende
// to discover any new additions not covered by test.
public GetExtendedColumnCategory_TheoryData()
{
Func<Type, bool> predicate = t => t.IsClass && !t.IsAbstract && typeof(IColumn).IsAssignableFrom(t);
static bool predicate(Type t) => t.IsClass && !t.IsAbstract && typeof(IColumn).IsAssignableFrom(t);

IEnumerable<Type> columnTypes =
typeof(IColumn).Assembly.GetTypes().Where(predicate)
Expand Down Expand Up @@ -103,11 +103,9 @@ public GetExtendedColumnCategory_TheoryData()
Add(TargetMethodColumn.Type, ExtendedColumnCategory.TargetMethod);
Add(TargetMethodColumn.Method, ExtendedColumnCategory.TargetMethod);
break;
// BenchmarkDotNet 0.13.1.x-nightly
// BenchmarkDotNet 0.13.2
case "BaselineAllocationRatioColumn":
IColumn barc = (Activator.CreateInstance(type) as IColumn)!;
Assert.NotNull(barc);
Add(barc, ExtendedColumnCategory.Metric);
Add(BaselineAllocationRatioColumn.RatioMean, ExtendedColumnCategory.Metric);
break;
// Mawosoft.Extensions.BenchmarkDotNet
case "CombinedParamsColumn":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
Expand All @@ -29,13 +30,13 @@ public partial class ConfigExtensionsTests
.Where(m => !m.IsSpecialName
&& m.ReturnType.IsGenericType
&& typeof(IEnumerable).IsAssignableFrom(m.ReturnType));
Assert.Equal(10, getter.Count());
Assert.Equal(11, getter.Count());
(MethodInfo m, Type? t)[] adder = typeof(ManualConfig)
.GetMethods()
.Where(m => !m.IsSpecialName
&& m.ReturnType == typeof(ManualConfig)
&& m.Name != "AddColumn"
&& m.Name.StartsWith("Add", StringComparison.Ordinal))
&& ((m.Name.StartsWith("Add", StringComparison.Ordinal) && m.Name != "AddColumn")
|| m.Name == "HideColumns"))
.Select(m =>
{
Type? retType = null;
Expand Down Expand Up @@ -71,6 +72,7 @@ private static ManualConfig CloneConfigExcept(IConfig source, Type? itemTypeToEx
config.ArtifactsPath = source.ArtifactsPath;
config.CultureInfo = source.CultureInfo;
config.Options = source.Options;
config.BuildTimeout = source.BuildTimeout;
return config;
}

Expand Down

0 comments on commit 0615978

Please sign in to comment.