Skip to content

Commit

Permalink
add HostSignal.AfterProcessStart to allow the users to obtain ID of a…
Browse files Browse the repository at this point in the history
… process that was started suspended (#2674)
  • Loading branch information
adamsitnik authored Dec 13, 2024
1 parent fe5b2f5 commit cd50f7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/BenchmarkDotNet/Engines/HostSignal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public enum HostSignal
/// </summary>
BeforeProcessStart,

/// <summary>
/// right after we start the benchmarking process
/// </summary>
AfterProcessStart,

/// <summary>
/// before jitting, warmup
/// </summary>
Expand Down
12 changes: 7 additions & 5 deletions src/BenchmarkDotNet/Loggers/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ internal class Broker
{
private readonly ILogger logger;
private readonly Process process;
private readonly IDiagnoser diagnoser;
private readonly AnonymousPipeServerStream inputFromBenchmark, acknowledgments;
private readonly DiagnoserActionParameters diagnoserActionParameters;
private readonly ManualResetEvent finished;

public Broker(ILogger logger, Process process, IDiagnoser diagnoser,
BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, AnonymousPipeServerStream inputFromBenchmark, AnonymousPipeServerStream acknowledgments)
{
this.logger = logger;
this.process = process;
this.diagnoser = diagnoser;
this.Diagnoser = diagnoser;
this.inputFromBenchmark = inputFromBenchmark;
this.acknowledgments = acknowledgments;
diagnoserActionParameters = new DiagnoserActionParameters(process, benchmarkCase, benchmarkId);
DiagnoserActionParameters = new DiagnoserActionParameters(process, benchmarkCase, benchmarkId);
finished = new ManualResetEvent(false);

Results = new List<string>();
Expand All @@ -38,6 +36,10 @@ public Broker(ILogger logger, Process process, IDiagnoser diagnoser,
process.Exited += OnProcessExited;
}

internal IDiagnoser Diagnoser { get; }

internal DiagnoserActionParameters DiagnoserActionParameters { get; }

internal List<string> Results { get; }

internal List<string> PrefixedOutput { get; }
Expand Down Expand Up @@ -90,7 +92,7 @@ private void ProcessDataBlocking()
}
else if (Engine.Signals.TryGetSignal(line, out var signal))
{
diagnoser?.Handle(signal, diagnoserActionParameters);
Diagnoser?.Handle(signal, DiagnoserActionParameters);

writer.WriteLine(Engine.Signals.Acknowledgment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ private ExecuteResult Execute(BenchmarkCase benchmarkCase,

logger.WriteLineInfo($"// Execute: {process.StartInfo.FileName} {process.StartInfo.Arguments} in {process.StartInfo.WorkingDirectory}");

diagnoser?.Handle(HostSignal.BeforeProcessStart, new DiagnoserActionParameters(process, benchmarkCase, benchmarkId));
diagnoser?.Handle(HostSignal.BeforeProcessStart, broker.DiagnoserActionParameters);

process.Start();

diagnoser?.Handle(HostSignal.AfterProcessStart, broker.DiagnoserActionParameters);

processOutputReader.BeginRead();

process.EnsureHighPriority(logger);
Expand Down
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Toolchains/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private static ExecuteResult Execute(Process process, BenchmarkCase benchmarkCas
return new ExecuteResult(true, null, null, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), launchIndex);
}

broker.Diagnoser?.Handle(HostSignal.AfterProcessStart, broker.DiagnoserActionParameters);

processOutputReader.BeginRead();

process.EnsureHighPriority(logger);
Expand Down

0 comments on commit cd50f7b

Please sign in to comment.