dotnet-trace: don't fail if the trace file has no method calls (#4827)
authorKonstantin Gukov <gukkos@gmail.com>
Tue, 6 Aug 2024 18:19:39 +0000 (20:19 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Aug 2024 18:19:39 +0000 (14:19 -0400)
Before:

```
> dotnet-trace report dotnet_tracing_20240802_082746.nettrace topN -n 10
[ERROR] System.OverflowException: Arithmetic operation resulted in an overflow.
   at Microsoft.Diagnostics.Tools.Trace.CommandLine.PrintReportHelper.TopNWriteToStdOut(List`1 nodesToReport, Boolean isInclusive, Boolean isVerbose) in /_/src/Tools/dotnet-trace/CommandLine/PrintReportHelper.cs:line 99
   at Microsoft.Diagnostics.Tools.Trace.ReportCommandHandler.TopNReport(CancellationToken ct, IConsole console, String traceFile, Int32 number, Boolean inclusive, Boolean verbose) in /_/src/Tools/dotnet-trace/CommandLine/Commands/ReportCommand.cs:line 93
```

After:

```
> /home/gukov/diagnostics/artifacts/bin/dotnet-trace/Debug/net6.0/dotnet-trace report dotnet_tracing_20240802_082746.nettrace topN -n 10 -v
[WARNING] No method calls found
```

(written to stderr)

src/Tools/dotnet-trace/CommandLine/PrintReportHelper.cs

index d74f25043cb72cf5964c5bdac6a52c0d3a9d1796..ec60dd8f9fa43231894d900940d81bab688a3c07 100644 (file)
@@ -96,6 +96,12 @@ namespace Microsoft.Diagnostics.Tools.Trace.CommandLine
             }
 
             int n = nodesToReport.Count;
+            if (n == 0)
+            {
+                Console.Error.WriteLine("[WARNING] No method calls found");
+                return;
+            }
+
             int maxDigit = (int)Math.Log10(n) + 1;
             string extra = new(' ', maxDigit - 1);