From: Andrew Au Date: Thu, 30 May 2019 00:26:49 +0000 (-0700) Subject: Do not swallow exception and stuck in case we have an exception thrown during tracing X-Git-Tag: submit/tizen/20190813.035844~6^2^2~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03c882f585f599df1a419f00ad3bdfc29e87a116;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Do not swallow exception and stuck in case we have an exception thrown during tracing --- diff --git a/src/Tools/dotnet-counters/CounterMonitor.cs b/src/Tools/dotnet-counters/CounterMonitor.cs index d88809fee..ffda06f9d 100644 --- a/src/Tools/dotnet-counters/CounterMonitor.cs +++ b/src/Tools/dotnet-counters/CounterMonitor.cs @@ -206,7 +206,7 @@ namespace Microsoft.Diagnostics.Tools.Counters { EventPipeClient.StopTracing(_processId, _sessionId); } - catch (System.IO.EndOfStreamException) {} // If the app we're monitoring exits abrubtly, this may throw in which case we just swallow the exception and exit gracefully. + catch (System.IO.EndOfStreamException) {} // If the app we're monitoring exits abruptly, this may throw in which case we just swallow the exception and exit gracefully. } return 0; diff --git a/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs b/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs index 6d42a03dd..00bd26c27 100644 --- a/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs +++ b/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs @@ -99,26 +99,36 @@ namespace Microsoft.Diagnostics.Tools.Trace } var collectingTask = new Task(() => { - using (var fs = new FileStream(output.FullName, FileMode.Create, FileAccess.Write)) + try { - Console.Out.WriteLine($"Process : {process.MainModule.FileName}"); - Console.Out.WriteLine($"Output File : {fs.Name}"); - Console.Out.WriteLine($"\tSession Id: 0x{sessionId:X16}"); - lineToClear = Console.CursorTop; - - while (true) + using (var fs = new FileStream(output.FullName, FileMode.Create, FileAccess.Write)) { - var buffer = new byte[16 * 1024]; - int nBytesRead = stream.Read(buffer, 0, buffer.Length); - if (nBytesRead <= 0) - break; - fs.Write(buffer, 0, nBytesRead); - - ResetCurrentConsoleLine(vTermMode.IsEnabled); - Console.Out.Write($"\tRecording trace {GetSize(fs.Length)}"); - - Debug.WriteLine($"PACKET: {Convert.ToBase64String(buffer, 0, nBytesRead)} (bytes {nBytesRead})"); + Console.Out.WriteLine($"Process : {process.MainModule.FileName}"); + Console.Out.WriteLine($"Output File : {fs.Name}"); + Console.Out.WriteLine($"\tSession Id: 0x{sessionId:X16}"); + lineToClear = Console.CursorTop; + + while (true) + { + var buffer = new byte[16 * 1024]; + int nBytesRead = stream.Read(buffer, 0, buffer.Length); + if (nBytesRead <= 0) + break; + fs.Write(buffer, 0, nBytesRead); + + ResetCurrentConsoleLine(vTermMode.IsEnabled); + Console.Out.Write($"\tRecording trace {GetSize(fs.Length)}"); + + Debug.WriteLine($"PACKET: {Convert.ToBase64String(buffer, 0, nBytesRead)} (bytes {nBytesRead})"); + } } + } + catch (Exception ex) + { + Console.Error.WriteLine($"[ERROR] {ex.ToString()}"); + } + finally + { terminated = true; shouldExit.Set(); }