Skip to content

Commit c5c0695

Browse files
committed
Capture standard error.
1 parent 464caba commit c5c0695

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/BenchmarkDotNet/Helpers/ProcessHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal static class ProcessHelper
6363
UseShellExecute = false,
6464
CreateNoWindow = true,
6565
RedirectStandardOutput = true,
66-
RedirectStandardError = true
66+
RedirectStandardError = includeErrors
6767
};
6868

6969
foreach (var environmentVariable in environmentVariables ?? [])

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliExecutor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ private async ValueTask<ExecuteResult> Execute(BenchmarkCase benchmarkCase,
8080
$"{executableName.EscapeCommandLine()} {benchmarkId.ToArguments(port, diagnoserRunMode)}",
8181
redirectStandardOutput: true,
8282
redirectStandardInput: false,
83-
redirectStandardError: false); // #1629
83+
redirectStandardError: true);
8484

8585
startInfo.SetEnvironmentVariables(benchmarkCase, resolver);
8686

8787
using Process process = new() { StartInfo = startInfo };
8888
using ProcessCleanupHelper processCleanupHelper = new(process, logger);
89-
using AsyncProcessOutputReader processOutputReader = new(process, logOutput: true, logger, readStandardError: false);
89+
using AsyncProcessOutputReader processOutputReader = new(process, logOutput: true, logger, readStandardError: true);
9090

9191
bool processOutputStarted = false;
9292
List<string> results;
@@ -135,6 +135,15 @@ private async ValueTask<ExecuteResult> Execute(BenchmarkCase benchmarkCase,
135135
}
136136
}
137137

138+
if (process.HasExited && process.ExitCode != 0)
139+
{
140+
string stderr = processOutputReader.GetErrorText();
141+
if (!string.IsNullOrEmpty(stderr))
142+
{
143+
logger.WriteLineError($"// Benchmark process stderr: {stderr}");
144+
}
145+
}
146+
138147
return new ExecuteResult(true,
139148
process.HasExited ? process.ExitCode : null,
140149
process.Id,

src/BenchmarkDotNet/Toolchains/Executor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static async ValueTask<ExecuteResult> ExecuteCore(BenchmarkCase benchmar
6363

6464
using Process process = new() { StartInfo = CreateStartInfo(benchmarkCase, artifactsPaths, args, resolver) };
6565
using ProcessCleanupHelper processCleanupHelper = new(process, logger);
66-
using AsyncProcessOutputReader processOutputReader = new(process, logOutput: true, logger, readStandardError: false);
66+
using AsyncProcessOutputReader processOutputReader = new(process, logOutput: true, logger, readStandardError: true);
6767

6868
List<string> results;
6969
List<string> prefixedOutput;
@@ -121,6 +121,15 @@ private static async ValueTask<ExecuteResult> ExecuteCore(BenchmarkCase benchmar
121121
}
122122
}
123123

124+
if (process.HasExited && process.ExitCode != 0)
125+
{
126+
string stderr = processOutputReader.GetErrorText();
127+
if (!string.IsNullOrEmpty(stderr))
128+
{
129+
logger.WriteLineError($"// Benchmark process stderr: {stderr}");
130+
}
131+
}
132+
124133
if (results.Any(line => line.Contains("BadImageFormatException")))
125134
logger.WriteLineError("You are probably missing <PlatformTarget>AnyCPU</PlatformTarget> in your .csproj file.");
126135

@@ -140,7 +149,7 @@ private static ProcessStartInfo CreateStartInfo(BenchmarkCase benchmarkCase, Art
140149
UseShellExecute = false,
141150
RedirectStandardOutput = true,
142151
RedirectStandardInput = false,
143-
RedirectStandardError = false, // #1629
152+
RedirectStandardError = true,
144153
CreateNoWindow = true,
145154
WorkingDirectory = null // by default it's null
146155
};

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmExecutor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private static async ValueTask<ExecuteResult> Execute(BenchmarkCase benchmarkCas
145145
{
146146
using ProcessCleanupHelper processCleanupHelper = new(processListener.Process, logger);
147147
bool isFileBasedIpc = processListener.Listener is FileStdOutListener;
148-
using AsyncProcessOutputReader processOutputReader = new(processListener.Process, logOutput: !isFileBasedIpc, logger, readStandardError: false, channelStandardOutput: isFileBasedIpc);
148+
using AsyncProcessOutputReader processOutputReader = new(processListener.Process, logOutput: !isFileBasedIpc, logger, readStandardError: true, channelStandardOutput: isFileBasedIpc);
149149

150150
if (isFileBasedIpc)
151151
{
@@ -175,7 +175,7 @@ private static Process CreateProcess(BenchmarkCase benchmarkCase, ArtifactsPaths
175175
UseShellExecute = false,
176176
RedirectStandardOutput = true,
177177
RedirectStandardInput = false, // not supported by WASM!
178-
RedirectStandardError = false, // #1629
178+
RedirectStandardError = true,
179179
CreateNoWindow = true
180180
};
181181

@@ -235,6 +235,15 @@ await broker.ProcessData(cancellationToken)
235235
}
236236
}
237237

238+
if (process.HasExited && process.ExitCode != 0)
239+
{
240+
string stderr = processOutputReader.GetErrorText();
241+
if (!string.IsNullOrEmpty(stderr))
242+
{
243+
logger.WriteLineError($"// Benchmark process stderr: {stderr}");
244+
}
245+
}
246+
238247
return new ExecuteResult(true,
239248
process.HasExited ? process.ExitCode : null,
240249
process.Id,

0 commit comments

Comments
 (0)