Skip to content

Commit

Permalink
Merge branch 'release/v2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswalpen committed Dec 19, 2022
2 parents 854f86e + d496365 commit b613faf
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 61 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## vNext
## v2.2.0
### Added
- ThreadBehaviour to define how a thread is created
- Allow benchmarks to be run on the MainThread
- OnExecuted to run a delegate after each task run
- Trace - Edit TraceOptions as delegate

### Changed
- Added IDisposable to IThreadSessionHandler

### Fixed
-
- Markdowntracer traced all data when using DetailPerThread

## v2.1.0
### Added
Expand Down
3 changes: 1 addition & 2 deletions MeasureMap.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C302527D
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3BE4645D-C5EB-4675-AEE2-68BFE6AC84EB}"
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
.github\workflows\build.yml = .github\workflows\build.yml
CHANGELOG.md = CHANGELOG.md
Expand All @@ -21,7 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{364A83BE-EC1F-42DA-ACCB-69DE17631CF3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MeasureMap.Benchmark", "src\Tests\MeasureMap.Benchmark\MeasureMap.Benchmark.csproj", "{5BA1A434-30F8-4233-B4C1-A668AB50BC4B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MeasureMap.Benchmark", "src\Tests\MeasureMap.Benchmark\MeasureMap.Benchmark.csproj", "{5BA1A434-30F8-4233-B4C1-A668AB50BC4B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# MeasureMap
.NET Benchmarking made simple

[![Build Status](https://img.shields.io/travis/com/WickedFlame/MeasureMap/master.svg?label=Travis-CI&style=for-the-badge)](https://app.travis-ci.com/github/WickedFlame/MeasureMap)
[![Build status](https://img.shields.io/appveyor/build/chriswalpen/measuremap/master?label=Master&logo=appveyor&style=for-the-badge)](https://ci.appveyor.com/project/chriswalpen/measuremap/branch/master)
[![Build status](https://img.shields.io/appveyor/build/chriswalpen/measuremap/dev?label=Dev&logo=appveyor&style=for-the-badge)](https://ci.appveyor.com/project/chriswalpen/measuremap/branch/dev)

[![NuGet Version](https://img.shields.io/nuget/v/measuremap.svg?style=for-the-badge&label=Latest)](https://www.nuget.org/packages/measuremap/)
[![NuGet Version](https://img.shields.io/nuget/vpre/measuremap.svg?style=for-the-badge&label=RC)](https://www.nuget.org/packages/measuremap/)

[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=WickedFlame_MeasureMap&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=WickedFlame_MeasureMap)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=WickedFlame_MeasureMap&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=WickedFlame_MeasureMap)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=WickedFlame_MeasureMap&metric=coverage)](https://sonarcloud.io/summary/new_code?id=WickedFlame_MeasureMap)

Measuremap is a lightweight assembly that allows profiling and benchmarking code.
Measuremap allows profiling and benchmarking from simple code fragmets to full applications.

Visit [https://wickedflame.github.io/MeasureMap/](https://wickedflame.github.io/MeasureMap/) for the full documentation.


MeasureMap uses the builder pattern and a fluent API to make benchmarking as simple as possible.

## Profiling
Profiles are initiated with ProfilerSession.StartSession().

```csharp
var result = ProfilerSession.StartSession()
.Task(() =>
Expand All @@ -34,6 +38,9 @@ Assert.IsTrue(result.AverageMilliseconds < 20);


## Benchmarking
Benchmarks are a collection of ProfilerSessions.
These are initiated and started with the BenchmarkRunner.

```csharp
var sha256 = SHA256.Create();
var md5 = MD5.Create();
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# http://www.appveyor.com/docs/appveyor-yml

environment:
base_version: 2.1.0
base_version: 2.2.0

# version format
version: $(base_version).{build}
Expand All @@ -27,7 +27,7 @@ for:
- dotnet restore ./build/_build.csproj

build_script:
- nuke Release --isrc true --version "%base_version%" --buildno "%APPVEYOR_BUILD_NUMBER%"
- nuke Release --isrc true --buildno "%APPVEYOR_BUILD_NUMBER%"

test: off

Expand All @@ -48,7 +48,7 @@ for:
- dotnet restore ./build/_build.csproj

build_script:
- nuke Release --isrc false --version "%base_version%" --buildno "%APPVEYOR_BUILD_NUMBER%"
- nuke Release --isrc false --buildno "%APPVEYOR_BUILD_NUMBER%" --version $(base_version)

test: off

Expand Down
2 changes: 1 addition & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository;

[Parameter("Version to be injected in the Build")]
public string Version { get; set; } = $"2.1.0";
public string Version { get; set; } = $"2.1.1";

[Parameter("The Buildnumber provided by the CI")]
public int BuildNo = 6;
Expand Down
13 changes: 13 additions & 0 deletions src/MeasureMap/ProfilerResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public static void Trace(this IProfilerResult result, TraceOptions options)
result.Trace(options.Tracer, options.ResultWriter, options);
}

/// <summary>
/// Trace the output of a Profiler
/// </summary>
/// <param name="result"></param>
/// <param name="factory"></param>
public static void Trace(this IProfilerResult result, Action<TraceOptions> factory)
{
var options = TraceOptions.Default.Clone();
factory.Invoke(options);

result.Trace(options);
}

/// <summary>
/// Trace the output of a Profiler
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/MeasureMap/ProfilerSessionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using MeasureMap.Diagnostics;
using MeasureMap.Runners;
using MeasureMap.TaskHandlers;

namespace MeasureMap
{
Expand Down Expand Up @@ -298,6 +299,18 @@ public static ProfilerSession SetMinLogLevel(this ProfilerSession session, LogLe
return session;
}

/// <summary>
/// Add a delegate that is run after the task is executed. It is possible to add multiple delegates by calling this method multiple times
/// </summary>
/// <param name="session"></param>
/// <param name="execution"></param>
/// <returns></returns>
public static ProfilerSession OnExecuted(this ProfilerSession session, Action<IIterationResult> execution)
{
session.ProcessingPipeline.SetNext(new OnExecutedTaskHandler(execution));
return session;
}

internal static ProfilerSession AppendSettings(this ProfilerSession session, ProfilerSettings settings)
{
session.SetMinLogLevel(settings.Logger.MinLogLevel);
Expand Down
35 changes: 35 additions & 0 deletions src/MeasureMap/TaskHandlers/OnExecutedTaskHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace MeasureMap.TaskHandlers
{
/// <summary>
/// TaskHandler that executes a delegate after the taskrun
/// </summary>
public class OnExecutedTaskHandler : TaskHandler
{
private readonly Action<IIterationResult> _execution;

/// <summary>
///
/// </summary>
/// <param name="execution"></param>
public OnExecutedTaskHandler(Action<IIterationResult> execution)
{
_execution = execution;
}

/// <summary>
/// Executes the task
/// </summary>
/// <param name="context">The current execution context</param>
/// <returns>The resulting collection of the executions</returns>
public override IIterationResult Run(IExecutionContext context)
{
var result = base.Run(context);

System.Threading.Tasks.Task.Run(() => _execution.Invoke(result));

return result;
}
}
}
2 changes: 1 addition & 1 deletion src/MeasureMap/Tracers/MarkDownTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Trace(IProfilerResult result, IResultWriter writer, TraceOptions opt
}
}

if (options.TraceDetail >= TraceDetail.DetailPerThread)
if (options.TraceDetail > TraceDetail.DetailPerThread)
{
writer.WriteLine(string.Empty);
writer.WriteLine("## Details per Iteration and Thread");
Expand Down
53 changes: 53 additions & 0 deletions src/Tests/MeasureMap.UnitTest/ProfileSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,59 @@ public void ProfileSession_SetExecutionHandler()
mock.Verify(x => x.Execute(It.IsAny<ITask>(), It.IsAny<ProfilerSettings>()));
}

[Test]
public void ProfileSession_OnExecuted()
{
var calls = 0;

ProfilerSession.StartSession()
.SetIterations(5)
.RunWarmup(false)
.OnExecuted(r => calls++)
.Task(() => { })
.RunSession();

calls.Should().Be(5);
}

[Test]
public void ProfileSession_OnExecuted_Warmup()
{
var calls = 0;

ProfilerSession.StartSession()
.OnExecuted(r => calls++)
.Task(() => { })
.RunSession();

calls.Should().Be(2);
}

[Test]
public void ProfileSession_OnExecuted_IIterationResult()
{
ProfilerSession.StartSession()
.OnExecuted(r => r.Should().BeAssignableTo<IterationResult>())
.Task(() => { })
.RunSession();
}

[Test]
public void ProfileSession_OnExecuted_MultipleRegistrations()
{
var first = 0;
var second = 0;

ProfilerSession.StartSession()
.OnExecuted(r => first++)
.OnExecuted(r => second++)
.Task(() => { })
.RunSession();

first.Should().Be(2);
second.Should().Be(2);
}

private void Task()
{
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.002));
Expand Down
31 changes: 30 additions & 1 deletion src/Tests/MeasureMap.UnitTest/Tracers/TracerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text;
using System;
using System.Text;
using FluentAssertions;
using MeasureMap.Tracers;
using NUnit.Framework;
using Polaroider;
Expand Down Expand Up @@ -122,6 +124,33 @@ public void Tracer_Profiler_Options()

((StringResultWriter)options.ResultWriter).Value.MatchSnapshot();
}

[Test]
public void Tracer_Profiler_Options_Delegate()
{
TraceOptions options = null;

var result = ResultFactory.CreateResult();

result.Trace(o =>
{
o.ResultWriter = new StringResultWriter();
o.Tracer = new MarkDownTracer();
options = o;
});

((StringResultWriter)options.ResultWriter).Value.MatchSnapshot();
}

[Test]
public void Tracer_Profiler_Options_Delegate_Simple()
{
var result = ResultFactory.CreateResult();

Action action = () => result.Trace(o => o.TraceDetail = TraceDetail.DetailPerThread);

action.Should().NotThrow();
}
}

public class StringResultWriter : IResultWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,3 @@
| 1 | 10 | 00:00:00.0000013 | 00:00:00.0000018 | 00:00:00.0000009 | 740740.74074/s |
| 2 | 10 | 00:00:00.0000013 | 00:00:00.0000018 | 00:00:00.0000009 | 740740.74074/s |

## Details per Iteration and Thread
| ThreadId | Iteration | TimeStamp | Milliseconds |
| -------- | --------- | --------------------------- | -----------: |
| 1 | 1 | 2012-12-21T01:01:01.0010001 | 0.0018 ms |
| 2 | 1 | 2012-12-21T01:01:01.0010001 | 0.0018 ms |
| 1 | 2 | 2012-12-21T01:01:01.0010002 | 0.0017 ms |
| 2 | 2 | 2012-12-21T01:01:01.0010002 | 0.0017 ms |
| 1 | 3 | 2012-12-21T01:01:01.0010003 | 0.0016 ms |
| 2 | 3 | 2012-12-21T01:01:01.0010003 | 0.0016 ms |
| 1 | 4 | 2012-12-21T01:01:01.0010004 | 0.0015 ms |
| 2 | 4 | 2012-12-21T01:01:01.0010004 | 0.0015 ms |
| 1 | 5 | 2012-12-21T01:01:01.0010005 | 0.0014 ms |
| 2 | 5 | 2012-12-21T01:01:01.0010005 | 0.0014 ms |
| 1 | 6 | 2012-12-21T01:01:01.0010006 | 0.0013 ms |
| 2 | 6 | 2012-12-21T01:01:01.0010006 | 0.0013 ms |
| 1 | 7 | 2012-12-21T01:01:01.0010007 | 0.0012 ms |
| 2 | 7 | 2012-12-21T01:01:01.0010007 | 0.0012 ms |
| 1 | 8 | 2012-12-21T01:01:01.0010008 | 0.0011 ms |
| 2 | 8 | 2012-12-21T01:01:01.0010008 | 0.0011 ms |
| 1 | 9 | 2012-12-21T01:01:01.0010009 | 0.001 ms |
| 2 | 9 | 2012-12-21T01:01:01.0010009 | 0.001 ms |
| 1 | 10 | 2012-12-21T01:01:01.0010010 | 0.0009 ms |
| 2 | 10 | 2012-12-21T01:01:01.0010010 | 0.0009 ms |

Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,3 @@
| 1 | 10 | 00:00:00.0000013 | 00:00:00.0000018 | 00:00:00.0000009 | 740740.74074/s |
| 2 | 10 | 00:00:00.0000013 | 00:00:00.0000018 | 00:00:00.0000009 | 740740.74074/s |

## Details per Iteration and Thread
| ThreadId | Iteration | TimeStamp | Milliseconds |
| -------- | --------- | --------------------------- | -----------: |
| 1 | 1 | 2012-12-21T01:01:01.0010001 | 0.0018 ms |
| 2 | 1 | 2012-12-21T01:01:01.0010001 | 0.0018 ms |
| 1 | 2 | 2012-12-21T01:01:01.0010002 | 0.0017 ms |
| 2 | 2 | 2012-12-21T01:01:01.0010002 | 0.0017 ms |
| 1 | 3 | 2012-12-21T01:01:01.0010003 | 0.0016 ms |
| 2 | 3 | 2012-12-21T01:01:01.0010003 | 0.0016 ms |
| 1 | 4 | 2012-12-21T01:01:01.0010004 | 0.0015 ms |
| 2 | 4 | 2012-12-21T01:01:01.0010004 | 0.0015 ms |
| 1 | 5 | 2012-12-21T01:01:01.0010005 | 0.0014 ms |
| 2 | 5 | 2012-12-21T01:01:01.0010005 | 0.0014 ms |
| 1 | 6 | 2012-12-21T01:01:01.0010006 | 0.0013 ms |
| 2 | 6 | 2012-12-21T01:01:01.0010006 | 0.0013 ms |
| 1 | 7 | 2012-12-21T01:01:01.0010007 | 0.0012 ms |
| 2 | 7 | 2012-12-21T01:01:01.0010007 | 0.0012 ms |
| 1 | 8 | 2012-12-21T01:01:01.0010008 | 0.0011 ms |
| 2 | 8 | 2012-12-21T01:01:01.0010008 | 0.0011 ms |
| 1 | 9 | 2012-12-21T01:01:01.0010009 | 0.001 ms |
| 2 | 9 | 2012-12-21T01:01:01.0010009 | 0.001 ms |
| 1 | 10 | 2012-12-21T01:01:01.0010010 | 0.0009 ms |
| 2 | 10 | 2012-12-21T01:01:01.0010010 | 0.0009 ms |

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---data
# MeasureMap - Profiler result
## Summary
| Category | Metric | Value |
| :------- | :---------------- | ---------------: |
| Warmup | Duration Warmup | 00:00:00 |
| Setup | Threads | 2 |
| | Iterations | 20 |
| Duration | Duration | 00:00:00.0000270 |
| | Total Time | 00:00:00.0000270 |
| | Avg. Time | 00:00:00.0000013 |
| | Avg. Milliseconds | 0.0013 ms |
| | Throughput | 740740.74074/s |
| | Fastest | 00:00:00.0000009 |
| | Slowest | 00:00:00.0000018 |
| Memory | Memory init size | 0 |
| | Memory end size | 0 |
| | Memory increase | 0 |

0 comments on commit b613faf

Please sign in to comment.