Repository navigation
Closed
Labels
Description
I would like to use dotnet trace as a profiler in BenchmarkDotNet (dotnet/BenchmarkDotNet#1315)
But there is a problem. I have to run process and read output of this process.
using (Process p = new Process())
{
p.StartInfo.CreateNoWindow = false;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.OutputDataReceived += (sender, args) => logger.WriteLine(LogKind.Default, args.Data);
p.ErrorDataReceived += (sender, args) => logger.WriteLine(LogKind.Error, args.Data);
p.StartInfo.FileName = "dotnet";
p.StartInfo.Arguments = $"trace collect --process-id {parameters.Process.Id} --output {GetFilePath(parameters, DateTime.Now)} --format Speedscope";
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit(180 * 1000);
if (!p.HasExited)
{
Debug.WriteLine("Killing process");
p.Kill();
}
}After run I got the exception:
[ERROR] System.IO.IOException: The handle is invalid
at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.ConsolePal.Clear()
at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration) in /_/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs:line 42
The exception was thrown here:
| Console.Clear(); |
This line should be executed only if there is a console. E.g.:
if (GetConsoleWindow() != IntPtr.Zero) Console.Clear();
Activity
josalem commentedon Nov 25, 2019
Is there a reason you are running
dotnet-traceinstead of just using the managed library? The library is available in a preview form today, but the productized version is almost finished (see: #617). I think this would be more straightforward and less cumbersome than shelling out todotnet-trace. That being said,dotnet-traceshould work under redirection.josalem commentedon Nov 27, 2019
Closing as a dup of the issue #637 which was fixed in #644