forked from petabridge/NBench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished implementing configurator searching within ReflectionDiscovery refactored the internals of BenchmarkSettings and ReflectionDiscovery to use configurators close petabridge#67 - fixed warmup with no numbers issue close petabridge#61 Added NBench.PerformanceCounters
- Loading branch information
1 parent
0771ca7
commit 84eea83
Showing
69 changed files
with
1,797 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...tion/PerformanceCounterMetricCollector.cs → ...tion/PerformanceCounterMetricCollector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/NBench.PerformanceCounters/Collection/PerformanceCounterSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics.Contracts; | ||
using NBench.Collection; | ||
using NBench.Metrics; | ||
using NBench.PerformanceCounters.Metrics; | ||
using NBench.Sdk; | ||
using NBench.Sys; | ||
|
||
namespace NBench.PerformanceCounters.Collection | ||
{ | ||
/// <summary> | ||
/// Factory that actually creates <see cref="PerformanceCounter"/> instances internally | ||
/// to correspond with each <see cref="PerformanceCounterBenchmarkSetting"/> | ||
/// </summary> | ||
public class PerformanceCounterSelector : MetricsCollectorSelector | ||
{ | ||
public PerformanceCounterSelector() : this(PerformanceCounterMetricName.DefaultName) { } | ||
|
||
public PerformanceCounterSelector(MetricName name) : base(name) | ||
{ | ||
} | ||
|
||
public PerformanceCounterSelector(MetricName name, SysInfo systemInfo) : base(name, systemInfo) | ||
{ | ||
} | ||
|
||
public override MetricCollector Create(RunMode runMode, WarmupData warmup, IBenchmarkSetting setting) | ||
{ | ||
Contract.Assert(setting != null); | ||
Contract.Assert(setting is PerformanceCounterBenchmarkSetting); | ||
var counterBenchmarkSetting = setting as PerformanceCounterBenchmarkSetting; | ||
var name = counterBenchmarkSetting.PerformanceCounterMetric; | ||
|
||
try | ||
{ | ||
var performanceCounter = new PerformanceCounter(name.CategoryName, name.CounterName, | ||
name.InstanceName ?? string.Empty, true); | ||
|
||
return new PerformanceCounterMetricCollector(name, name.UnitName ?? MetricNames.DefaultUnitName, performanceCounter, true); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new NBenchException($"Failed to create PerformanceCounterMeasurement {name.ToHumanFriendlyString()} - internal error while creating performance counter.", ex); | ||
} | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/NBench.PerformanceCounters/Metrics/PerformanceCounterBenchmarkSetting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using NBench.Metrics; | ||
using NBench.Sdk; | ||
|
||
namespace NBench.PerformanceCounters.Metrics | ||
{ | ||
/// <summary> | ||
/// <see cref="IBenchmarkSetting"/> used to instrument performance counters inside a <see cref="Benchmark"/> | ||
/// </summary> | ||
public sealed class PerformanceCounterBenchmarkSetting : IBenchmarkSetting, IEquatable<PerformanceCounterBenchmarkSetting> | ||
{ | ||
public PerformanceCounterBenchmarkSetting(PerformanceCounterMetricName performanceCounterMetric, AssertionType assertionType, Assertion assertion) | ||
{ | ||
PerformanceCounterMetric = performanceCounterMetric; | ||
AssertionType = assertionType; | ||
Assertion = assertion; | ||
} | ||
|
||
public PerformanceCounterMetricName PerformanceCounterMetric { get; } | ||
|
||
public MetricName MetricName => PerformanceCounterMetric; | ||
public AssertionType AssertionType { get; } | ||
public Assertion Assertion { get; } | ||
|
||
public bool Equals(IBenchmarkSetting other) | ||
{ | ||
return (other is PerformanceCounterBenchmarkSetting) | ||
&& Equals((PerformanceCounterBenchmarkSetting) other); | ||
} | ||
|
||
|
||
public bool Equals(PerformanceCounterBenchmarkSetting other) | ||
{ | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
return PerformanceCounterMetric.Equals(other.PerformanceCounterMetric) | ||
&& AssertionType == other.AssertionType | ||
&& Assertion.Equals(other.Assertion); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != this.GetType()) return false; | ||
return Equals((PerformanceCounterBenchmarkSetting) obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = PerformanceCounterMetric.GetHashCode(); | ||
hashCode = (hashCode*397) ^ (int) AssertionType; | ||
hashCode = (hashCode*397) ^ Assertion.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
|
||
public static bool operator ==(PerformanceCounterBenchmarkSetting left, PerformanceCounterBenchmarkSetting right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(PerformanceCounterBenchmarkSetting left, PerformanceCounterBenchmarkSetting right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/NBench.PerformanceCounters/Metrics/PerformanceCounterMetricName.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Diagnostics.Contracts; | ||
using NBench.Metrics; | ||
|
||
namespace NBench.PerformanceCounters.Metrics | ||
{ | ||
/// <summary> | ||
/// Uniquely represents a performance counter measurement name inside our collections engine | ||
/// </summary> | ||
public sealed class PerformanceCounterMetricName : MetricName, IEquatable<PerformanceCounterMetricName> | ||
{ | ||
public static readonly PerformanceCounterMetricName DefaultName = new PerformanceCounterMetricName("Category", "Instance", "Instance", "Units"); | ||
|
||
public PerformanceCounterMetricName(string categoryName, string counterName, string instanceName, string unitName) | ||
{ | ||
Contract.Requires(categoryName != null); | ||
Contract.Requires(counterName != null); | ||
CategoryName = categoryName; | ||
CounterName = counterName; | ||
InstanceName = instanceName; | ||
UnitName = unitName; | ||
} | ||
|
||
/// <summary> | ||
/// The name of the performance counter category with which this performance counter is associated. | ||
/// </summary> | ||
public string CategoryName { get; } | ||
|
||
/// <summary> | ||
/// The name of the performance counter. | ||
/// </summary> | ||
public string CounterName { get; } | ||
|
||
/// <summary> | ||
/// The name of the performance counter category instance, or an empty string (""), if the category contains a single instance. | ||
/// </summary> | ||
public string InstanceName { get; } | ||
|
||
/// <summary> | ||
/// Human-readable name of the measurement units associated with this performance counter. | ||
/// | ||
/// Used solely for reporting purposes - designed to make it easier to understand what the metric reads. | ||
/// For instance, if this performance counter was measuring disk writes the unit name would be "bytes" | ||
/// Or if this performance counter were measuring page faults, the unit name would be "page faults" | ||
/// </summary> | ||
public string UnitName { get; } | ||
|
||
public override bool Equals(MetricName other) | ||
{ | ||
return other is PerformanceCounterMetricName | ||
&& Equals((PerformanceCounterMetricName) other); | ||
} | ||
|
||
public bool Equals(PerformanceCounterMetricName other) | ||
{ | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
return string.Equals(CategoryName, other.CategoryName) | ||
&& string.Equals(CounterName, other.CounterName) | ||
&& string.Equals(InstanceName, other.InstanceName); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != this.GetType()) return false; | ||
return Equals((PerformanceCounterMetricName) obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = CategoryName?.GetHashCode() ?? 0; | ||
hashCode = (hashCode*397) ^ (CounterName?.GetHashCode() ?? 0); | ||
hashCode = (hashCode*397) ^ (InstanceName?.GetHashCode() ?? 0); | ||
return hashCode; | ||
} | ||
} | ||
|
||
public static bool operator ==(PerformanceCounterMetricName left, PerformanceCounterMetricName right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(PerformanceCounterMetricName left, PerformanceCounterMetricName right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
|
||
public override string ToHumanFriendlyString() | ||
{ | ||
if(!string.IsNullOrEmpty(InstanceName)) | ||
return $"[PerformanceCounter] {CategoryName}:{CounterName}:{InstanceName}"; | ||
return $"[PerformanceCounter] {CategoryName}:{CounterName}"; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/NBench.PerformanceCounters/NBench.PerformanceCounters.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{3112B845-6A64-4AD2-9FA9-88F47BE980C8}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>NBench.PerformanceCounters</RootNamespace> | ||
<AssemblyName>NBench.PerformanceCounters</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\SharedAssemblyInfo.cs"> | ||
<Link>Properties\SharedAssemblyInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="Collection\PerformanceCounterSelector.cs" /> | ||
<Compile Include="Metrics\PerformanceCounterBenchmarkSetting.cs" /> | ||
<Compile Include="Metrics\PerformanceCounterMetricName.cs" /> | ||
<Compile Include="PerformanceCounterMeasurementAttribute.cs" /> | ||
<Compile Include="Collection\PerformanceCounterMetricCollector.cs" /> | ||
<Compile Include="PerformanceCounterMeasurementConfigurator.cs" /> | ||
<Compile Include="PerformanceCounterThroughputAssertionAttribute.cs" /> | ||
<Compile Include="PerformanceCounterTotalAssertionAttribute.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\NBench\NBench.csproj"> | ||
<Project>{4e0b1852-7b6d-49e7-9939-a315d086b094}</Project> | ||
<Name>NBench</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.