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
11 changes: 7 additions & 4 deletions samples/BenchmarkDotNet.Samples/Intro/IntroGcMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ private class Config : ManualConfig
{
public Config()
{
Add(Job.Dry.WithGcServer(true).WithGcForce(true).WithId("ServerForce"));
Add(Job.Dry.WithGcServer(true).WithGcForce(false).WithId("Server"));
Add(Job.Dry.WithGcServer(false).WithGcForce(true).WithId("Workstation"));
Add(Job.Dry.WithGcServer(false).WithGcForce(false).WithId("WorkstationForce"));
Add(Job.MediumRun.WithGcServer(true).WithGcForce(true).WithId("ServerForce"));
Add(Job.MediumRun.WithGcServer(true).WithGcForce(false).WithId("Server"));
Add(Job.MediumRun.WithGcServer(false).WithGcForce(true).WithId("Workstation"));
Add(Job.MediumRun.WithGcServer(false).WithGcForce(false).WithId("WorkstationForce"));
#if !CORE
Add(new Diagnostics.Windows.MemoryDiagnoser());
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions samples/BenchmarkDotNet.Samples/JIT/Jit_Inlining.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace BenchmarkDotNet.Samples.JIT
{
// See http://en.wikipedia.org/wiki/Inline_expansion
// See http://aakinshin.net/en/blog/dotnet/inlining-and-starg/
#if !CORE
[Diagnostics.Windows.Configs.InliningDiagnoser]
#endif
[LegacyJitX86Job, LegacyJitX64Job, RyuJitX64Job]
public class Jit_Inlining
{
Expand Down
4 changes: 1 addition & 3 deletions samples/BenchmarkDotNet.Samples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Reflection;
using System.Reflection;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples
{
Expand Down
15 changes: 15 additions & 0 deletions src/BenchmarkDotNet.Core/Code/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal static string Generate(Benchmark benchmark)
Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark)).
Replace("$ParamsContent$", GetParamsContent(benchmark)).
Replace("$ExtraAttribute$", GetExtraAttributes(benchmark.Target)).
Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark)).
ToString();

text = Unroll(text, benchmark.Job.Run.UnrollFactor.Resolve(EnvResolver.Instance));
Expand Down Expand Up @@ -124,6 +125,20 @@ private static string GetExtraAttributes(Target target)
return string.Empty;
}

private static string GetEngineFactoryTypeName(Benchmark benchmark)
{
var factory = benchmark.Job.Infrastructure.EngineFactory.Resolve(InfrastructureResolver.Instance);
var factoryType = factory.GetType();

if (!factoryType.GetTypeInfo().DeclaredConstructors.Any(ctor => ctor.IsPublic && !ctor.GetParameters().Any()))
{
throw new NotSupportedException("Custom factory must have a public parameterless constructor");
}

return factoryType.GetCorrectTypeName();
}


private class SmartStringBuilder
{
private readonly string originalText;
Expand Down
37 changes: 10 additions & 27 deletions src/BenchmarkDotNet.Core/Diagnosers/CompositeDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Extensions;

namespace BenchmarkDotNet.Diagnosers
{
Expand All @@ -16,35 +17,19 @@ public CompositeDiagnoser(params IDiagnoser[] diagnosers)
this.diagnosers = diagnosers;
}

public void Start(Benchmark benchmark)
{
foreach (var diagnoser in diagnosers)
diagnoser.Start(benchmark);
}
public IColumnProvider GetColumnProvider()
=> new CompositeColumnProvider(diagnosers.Select(d => d.GetColumnProvider()).ToArray());

public void Stop(Benchmark benchmark, BenchmarkReport report)
{
foreach (var diagnoser in diagnosers)
diagnoser.Stop(benchmark, report);
}
public void BeforeAnythingElse(Process process, Benchmark benchmark)
=> diagnosers.ForEach(diagnoser => diagnoser.BeforeAnythingElse(process, benchmark));

public void ProcessStarted(Process process)
{
foreach (var diagnoser in diagnosers)
diagnoser.ProcessStarted(process);
}
public void AfterSetup(Process process, Benchmark benchmark)
=> diagnosers.ForEach(diagnoser => diagnoser.AfterSetup(process, benchmark));

public void AfterBenchmarkHasRun(Benchmark benchmark, Process process)
{
foreach (var diagnoser in diagnosers)
diagnoser.AfterBenchmarkHasRun(benchmark, process);
}
public void BeforeCleanup() => diagnosers.ForEach(diagnoser => diagnoser.BeforeCleanup());

public void ProcessStopped(Process process)
{
foreach (var diagnoser in diagnosers)
diagnoser.ProcessStopped(process);
}
public void ProcessResults(Benchmark benchmark, BenchmarkReport report)
=> diagnosers.ForEach(diagnoser => diagnoser.ProcessResults(benchmark, report));

public void DisplayResults(ILogger logger)
{
Expand All @@ -57,7 +42,5 @@ public void DisplayResults(ILogger logger)
logger.WriteLine();
}
}

public IColumnProvider GetColumnProvider() => new CompositeColumnProvider(diagnosers.Select(d => d.GetColumnProvider()).ToArray());
}
}
29 changes: 14 additions & 15 deletions src/BenchmarkDotNet.Core/Diagnosers/IDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@

namespace BenchmarkDotNet.Diagnosers
{
/// The events are guaranteed to happen in the following sequence:
/// Start // When the Benchmark run is started and most importantly BEFORE the process has been launched
/// ProcessStarted // After the Process (in a "Diagnostic" run) has been launched
/// AfterBenchmarkHasRun // After a "Warmup" iteration of the Benchmark has run, i.e. we know the [Benchmark] method has been
/// // executed and JITted, this is important if the Diagnoser needs to know when it can do a Memory Dump.
/// ProcessStopped // Once the Process (in a "Diagnostic" run) has stopped/completed
/// Stop // At the end, when the entire Benchmark run has complete
/// DisplayResults // When the results/output should be displayed
public interface IDiagnoser
{
void Start(Benchmark benchmark);
IColumnProvider GetColumnProvider();

void Stop(Benchmark benchmark, BenchmarkReport report);
/// <summary>
/// before jitting, warmup
/// </summary>
void BeforeAnythingElse(Process process, Benchmark benchmark);

void ProcessStarted(Process process);
/// <summary>
/// after setup, before run
/// </summary>
void AfterSetup(Process process, Benchmark benchmark);

void AfterBenchmarkHasRun(Benchmark benchmark, Process process);
/// <summary>
/// after run, before cleanup
/// </summary>
void BeforeCleanup();

void ProcessStopped(Process process);
void ProcessResults(Benchmark benchmark, BenchmarkReport report);

void DisplayResults(ILogger logger);

IColumnProvider GetColumnProvider();
}
}
Loading