Avoid unnecessary allocation & better error message on file exists error (#371)
authorSung Yoon Whang <suwhang@microsoft.com>
Sun, 30 Jun 2019 04:51:05 +0000 (21:51 -0700)
committerGitHub <noreply@github.com>
Sun, 30 Jun 2019 04:51:05 +0000 (21:51 -0700)
src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs

index dbd329d7e2b2bb2f542b0263b4ac8fd2f5a0efa4..13d4d286cb347acb3367a0e448e8029c10c33342 100644 (file)
@@ -113,7 +113,7 @@ namespace Microsoft.Diagnostics.Tools.Trace
                     }
                     if (File.Exists(output.FullName))
                     {
-                        Console.Error.WriteLine("Unable to create file.");
+                        Console.Error.WriteLine($"Unable to create file {output.FullName}. Try using -o or --output option to specify a different output file name.");
                         return ErrorCodes.FileCreationError;
                     }
                     var collectingTask = new Task(() => {
@@ -125,10 +125,10 @@ namespace Microsoft.Diagnostics.Tools.Trace
                                 Console.Out.WriteLine($"Output File : {fs.Name}");
                                 Console.Out.WriteLine($"\tSession Id: 0x{sessionId:X16}");
                                 lineToClear = Console.CursorTop;
+                                var buffer = new byte[16 * 1024];
 
                                 while (true)
                                 {
-                                    var buffer = new byte[16 * 1024];
                                     int nBytesRead = stream.Read(buffer, 0, buffer.Length);
                                     if (nBytesRead <= 0)
                                         break;