Skip to content

Commit

Permalink
Merge branch 'release/v2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswalpen committed Oct 31, 2022
2 parents 75af65c + 7d19293 commit 53e1b55
Show file tree
Hide file tree
Showing 36 changed files with 645 additions and 401 deletions.
6 changes: 5 additions & 1 deletion .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "object",
"properties": {
"BuildNo": {
"type": "string",
"type": "integer",
"description": "The Buildnumber provided by the CI"
},
"Configuration": {
Expand Down Expand Up @@ -74,6 +74,10 @@
"type": "string",
"description": "Root directory during build execution"
},
"RunTests": {
"type": "boolean",
"description": "Run UnitTests on build"
},
"Skip": {
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
Expand Down
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## vNext
### Added
-
- ThreadBehaviour to define how a thread is created
- Allow benchmarks to be run on the MainThread

### Changed
-
- Added IDisposable to IThreadSessionHandler

### Fixed
-

## v2.1.0
### Added
- ThreadBehaviour to define how a thread is created
- Allow benchmarks to be run on the MainThread

### Changed
- Added IDisposable to IThreadSessionHandler

## v2.0.2
### Added
- Added Benchmarks and samples oh how to use the BenchmarkRunner
Expand Down
2 changes: 1 addition & 1 deletion 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.0.2
base_version: 2.0.3

# version format
version: $(base_version).{build}
Expand Down
14 changes: 11 additions & 3 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository;

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

[Parameter("The Buildnumber provided by the CI")]
public string BuildNo = "1";
public int BuildNo = 6;

[Parameter("Is RC Version")]
public bool IsRc = false;

[Parameter("Run UnitTests on build")]
public bool RunTests = true;

AbsolutePath SourceDirectory => RootDirectory / "src";

AbsolutePath TestsDirectory => RootDirectory / "src" / "tests";
Expand Down Expand Up @@ -89,6 +92,11 @@ class Build : NukeBuild
.DependsOn(Compile)
.Executes(() =>
{
if (!RunTests)
{
return;
}

DotNetTest(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
Expand Down Expand Up @@ -131,6 +139,6 @@ class Build : NukeBuild
});

string PackageVersion
=> IsRc ? int.Parse(BuildNo) < 10 ? $"{Version}-RC0{BuildNo}" : $"{Version}-RC{BuildNo}" : Version;
=> IsRc ? BuildNo < 10 ? $"{Version}-RC0{BuildNo}" : $"{Version}-RC{BuildNo}" : Version;

}
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand Down
13 changes: 13 additions & 0 deletions src/MeasureMap/BenchmarkRunnerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,18 @@ public static BenchmarkRunner SetMinLogLevel(this BenchmarkRunner runner, LogLev
runner.Settings.Logger.MinLogLevel = level;
return runner;
}

/// <summary>
/// Set the <see cref="ThreadBehaviour"/> to the settings of the <see cref="BenchmarkRunner"/>.<br></br>
/// Using <see cref="ThreadBehaviour.RunOnMainThread"/> overwrites the ThreadingHandler defined in each ProfilerSession that is run in the Benchmark.
/// </summary>
/// <param name="runner"></param>
/// <param name="behaviour"></param>
/// <returns></returns>
public static BenchmarkRunner SetThreadBehaviour(this BenchmarkRunner runner, ThreadBehaviour behaviour)
{
runner.Settings.ThreadBehaviour = behaviour;
return runner;
}
}
}
13 changes: 2 additions & 11 deletions src/MeasureMap/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ public ExecutionContext()
/// </summary>
public ExecutionContext(IProfilerSettings settings)
{
Threads = new ThreadList();
Settings = settings;
}

/// <summary>
/// The data store for the context
/// </summary>
public IDictionary<string, object> SessionData { get; } = new Dictionary<string, object>();

/// <summary>
/// Gets a list containing all threads that are associated with this run
/// </summary>
public IThreadList Threads { get; set; }


/// <summary>
/// Gets the settings associated with the session
/// </summary>
Expand Down Expand Up @@ -140,10 +134,7 @@ public static IExecutionContext Clear(this IExecutionContext context)
/// <returns></returns>
public static IExecutionContext Clone(this IExecutionContext context)
{
var child = new ExecutionContext(context.Settings)
{
Threads = context.Threads
};
var child = new ExecutionContext(context.Settings);

foreach(var item in context.SessionData)
{
Expand Down
8 changes: 1 addition & 7 deletions src/MeasureMap/IExecutionContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MeasureMap.Diagnostics;
using MeasureMap.Threading;
using System.Collections.Generic;

namespace MeasureMap
Expand All @@ -13,12 +12,7 @@ public interface IExecutionContext
/// The data store for the context
/// </summary>
IDictionary<string, object> SessionData { get; }

/// <summary>
/// Gets a list containing all threads that are associated with this run
/// </summary>
IThreadList Threads { get; }


/// <summary>
/// Gets the settings associated with the session
/// </summary>
Expand Down
10 changes: 3 additions & 7 deletions src/MeasureMap/ProfilerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ public static ProfilerSession StartSession()
/// Sets the amount of threads that the profiling sessions should run in.
/// All iterations are run on every thread.
/// </summary>
/// <param name="thredCount">The amount of threads that the task is run on</param>
/// <returns>The current profiling session</returns>
public ProfilerSession SetThreads(int thredCount)
public ProfilerSession SetExecutionHandler(IThreadSessionHandler handler)
{
_executor = new MultyThreadSessionHandler(thredCount);
_executor = handler;

return this;
}
Expand Down Expand Up @@ -172,10 +171,7 @@ public void Dispose()
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
if (_executor is MultyThreadSessionHandler handler)
{
handler.DisposeThreads();
}
_executor.Dispose();
}
}
}
39 changes: 39 additions & 0 deletions src/MeasureMap/ProfilerSessionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,38 @@ public static ProfilerSession Task<T>(this ProfilerSession session, Func<IExecut
return session;
}

/// <summary>
/// Sets the amount of threads that the profiling sessions should run in.
/// All iterations are run on every thread.
/// </summary>
/// <param name="session"></param>
/// <param name="thredCount">The amount of threads that the task is run on</param>
/// <returns>The current profiling session</returns>
public static ProfilerSession SetThreads(this ProfilerSession session, int thredCount)
{
session.SetExecutionHandler(new MultyThreadSessionHandler(thredCount));

return session;
}

/// <summary>
/// Set the <see cref="ThreadBehaviour"/> to the settings of the <see cref="ProfilerSession"/>
/// </summary>
/// <param name="session"></param>
/// <param name="behaviour"></param>
/// <returns></returns>
public static ProfilerSession SetThreadBehaviour(this ProfilerSession session, ThreadBehaviour behaviour)
{
session.Settings.ThreadBehaviour = behaviour;

if (behaviour == ThreadBehaviour.RunOnMainThread)
{
session.SetExecutionHandler(new MainThreadSessionHandler());
}

return session;
}

/// <summary>
/// Sets the amount of iterations that the profileing session should run the task
/// </summary>
Expand Down Expand Up @@ -140,6 +172,13 @@ public static ProfilerSession RunWarmup(this ProfilerSession session, bool run)
public static ProfilerSession SetSettings(this ProfilerSession session, ProfilerSettings settings)
{
settings.MergeChangesTo(session.Settings);

if(session.Settings.ThreadBehaviour != ThreadBehaviour.Thread)
{
// ensure the ThreadBehaviour is set when using the new settings
// this is only set when using the default ThreadBehaviour in a ProfilerSession
session.SetThreadBehaviour(session.Settings.ThreadBehaviour);
}

return session;
}
Expand Down
19 changes: 18 additions & 1 deletion src/MeasureMap/ProfilerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using MeasureMap.Diagnostics;
using MeasureMap.Runners;
using MeasureMap.Threading;

namespace MeasureMap
{
Expand All @@ -15,6 +16,7 @@ public class ProfilerSettings : IProfilerSettings
private int _iterations = 1;
private bool _runWarmup = true;
private TimeSpan _duration = TimeSpan.Zero;
private ThreadBehaviour _threadBehaviour = ThreadBehaviour.Thread;

/// <summary>
///
Expand Down Expand Up @@ -70,6 +72,19 @@ public bool RunWarmup
}
}

/// <summary>
/// Defines the way threads are created
/// </summary>
public ThreadBehaviour ThreadBehaviour
{
get => _threadBehaviour;
set
{
_threadBehaviour = value;
AddChange("threadBehaviour", s => s.ThreadBehaviour, (s, v) => s.ThreadBehaviour = v);
}
}

/// <summary>
/// Gets the <see cref="ITaskRunner"/> that is used to run the tasks
/// </summary>
Expand All @@ -82,13 +97,15 @@ public bool RunWarmup

private void AddChange<T>(string property, Func<ProfilerSettings, T> func, Action<ProfilerSettings, T> action)
{
_changes[property] = (origSet, newSet) => action(origSet, func(newSet));
_changes[property] = (toSet, fromSet) => action(toSet, func(fromSet));
}

internal void MergeChangesTo(ProfilerSettings settings)
{
foreach (var action in _changes.Values)
{
// settings = to
// this = from
action(settings, this);
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/MeasureMap/ProfilerSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using MeasureMap.Threading;
using System;

namespace MeasureMap
{
/// <summary>
/// Extensions for <see cref="ProfilerSettings"/>
/// </summary>
public static class ProfilerSettingsExtensions
{
/// <summary>
/// Get the ThreadFactory based on the <see cref="ThreadBehaviour"/> setting in <see cref="ProfilerSettings"/>
/// </summary>
/// <param name="settings"></param>
/// <returns></returns>
public static Func<int, Func<Result>, IWorkerThread> GetThreadFactory(this ProfilerSettings settings)
{
return settings.ThreadBehaviour switch
{
ThreadBehaviour.Thread => WorkerThread.Factory,
ThreadBehaviour.Task => WorkerTask.Factory,
_ => WorkerThread.Factory
};
}
}
}
29 changes: 22 additions & 7 deletions src/MeasureMap/SessionHandlers/BasicSessionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

using System;
using MeasureMap.Threading;
using System;
using MeasureMap.Diagnostics;

namespace MeasureMap
{
/// <summary>
/// A single threaded task session handler
/// A single threaded task session handler. Runs all tasks in a separate thread.
/// </summary>
public class BasicSessionHandler : SessionHandler, IThreadSessionHandler
{
Expand All @@ -19,23 +18,39 @@ public class BasicSessionHandler : SessionHandler, IThreadSessionHandler
public override IProfilerResult Execute(ITask task, ProfilerSettings settings)
{
var runnerThreads = new WorkerThreadList();
var threads = new ThreadList();

var thread = runnerThreads.StartNew(0, () =>
{
var worker = new Worker(threads);
var worker = new Worker();
return worker.Run(task, settings);
});
}, settings.GetThreadFactory());

settings.Logger.Write($"Start thread {thread.Id}", LogLevel.Debug, nameof(BasicSessionHandler));

runnerThreads.WaitAll();
threads.WaitAll();

return new ProfilerResult
{
thread.Result
};
}

/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
// nothing to dispose
}
}
}
Loading

0 comments on commit 53e1b55

Please sign in to comment.