Skip to content

Commit cd50f7b

Browse files
authored
add HostSignal.AfterProcessStart to allow the users to obtain ID of a process that was started suspended (#2674)
1 parent fe5b2f5 commit cd50f7b

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/BenchmarkDotNet/Engines/HostSignal.cs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ public enum HostSignal
77
/// </summary>
88
BeforeProcessStart,
99

10+
/// <summary>
11+
/// right after we start the benchmarking process
12+
/// </summary>
13+
AfterProcessStart,
14+
1015
/// <summary>
1116
/// before jitting, warmup
1217
/// </summary>

src/BenchmarkDotNet/Loggers/Broker.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ internal class Broker
1515
{
1616
private readonly ILogger logger;
1717
private readonly Process process;
18-
private readonly IDiagnoser diagnoser;
1918
private readonly AnonymousPipeServerStream inputFromBenchmark, acknowledgments;
20-
private readonly DiagnoserActionParameters diagnoserActionParameters;
2119
private readonly ManualResetEvent finished;
2220

2321
public Broker(ILogger logger, Process process, IDiagnoser diagnoser,
2422
BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, AnonymousPipeServerStream inputFromBenchmark, AnonymousPipeServerStream acknowledgments)
2523
{
2624
this.logger = logger;
2725
this.process = process;
28-
this.diagnoser = diagnoser;
26+
this.Diagnoser = diagnoser;
2927
this.inputFromBenchmark = inputFromBenchmark;
3028
this.acknowledgments = acknowledgments;
31-
diagnoserActionParameters = new DiagnoserActionParameters(process, benchmarkCase, benchmarkId);
29+
DiagnoserActionParameters = new DiagnoserActionParameters(process, benchmarkCase, benchmarkId);
3230
finished = new ManualResetEvent(false);
3331

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

39+
internal IDiagnoser Diagnoser { get; }
40+
41+
internal DiagnoserActionParameters DiagnoserActionParameters { get; }
42+
4143
internal List<string> Results { get; }
4244

4345
internal List<string> PrefixedOutput { get; }
@@ -90,7 +92,7 @@ private void ProcessDataBlocking()
9092
}
9193
else if (Engine.Signals.TryGetSignal(line, out var signal))
9294
{
93-
diagnoser?.Handle(signal, diagnoserActionParameters);
95+
Diagnoser?.Handle(signal, DiagnoserActionParameters);
9496

9597
writer.WriteLine(Engine.Signals.Acknowledgment);
9698

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliExecutor.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ private ExecuteResult Execute(BenchmarkCase benchmarkCase,
8383

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

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

8888
process.Start();
89+
90+
diagnoser?.Handle(HostSignal.AfterProcessStart, broker.DiagnoserActionParameters);
91+
8992
processOutputReader.BeginRead();
9093

9194
process.EnsureHighPriority(logger);

src/BenchmarkDotNet/Toolchains/Executor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ private static ExecuteResult Execute(Process process, BenchmarkCase benchmarkCas
7979
return new ExecuteResult(true, null, null, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), launchIndex);
8080
}
8181

82+
broker.Diagnoser?.Handle(HostSignal.AfterProcessStart, broker.DiagnoserActionParameters);
83+
8284
processOutputReader.BeginRead();
8385

8486
process.EnsureHighPriority(logger);

0 commit comments

Comments
 (0)