Skip to content

Instantly share code, notes, and snippets.

@adamsitnik
Created February 9, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsitnik/50a6e3cfd218887803b7dc040c260b91 to your computer and use it in GitHub Desktop.
Save adamsitnik/50a6e3cfd218887803b7dc040c260b91 to your computer and use it in GitHub Desktop.
namespace BenchmarkDotNet.Samples
{
class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<TheTypeWithBenchmarks>(DefaultConfig.Instance.With(new SampleIntegrationWithProfiler()));
}
}
public class SampleIntegrationWithProfiler : IDiagnoser
{
private Process profiler;
public IEnumerable<string> Ids => new[] { nameof(SampleIntegrationWithProfiler) };
// it tells BDN to run benchmarks once again with this diagnoser enabled, do the diagnostics and discard results (they are affected by oveerhead)
public Diagnosers.RunMode GetRunMode(Benchmark benchmark) => Diagnosers.RunMode.ExtraRun;
public void Handle(HostSignal signal, DiagnoserActionParameters parameters)
{
if (signal == HostSignal.BeforeMainRun)
profiler = Process.Start("thePathToProfiler.exe", $"somehow tell the profiler to attach to this process {parameters.Process.Id}");
else if (signal == HostSignal.AfterMainRun)
profiler.Close();
}
public IEnumerable<IExporter> Exporters => Array.Empty<IExporter>();
public void DisplayResults(ILogger logger) { }
public IColumnProvider GetColumnProvider() => EmptyColumnProvider.Instance;
public IEnumerable<ValidationError> Validate(ValidationParameters validationParameters) => Array.Empty<ValidationError>();
public void ProcessResults(DiagnoserResults results) { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment