Add database and aspnet-requests profiles to dotnet-trace (#2132)
authorNik Karpinsky <karpinsn@gmail.com>
Thu, 8 Apr 2021 19:58:03 +0000 (12:58 -0700)
committerGitHub <noreply@github.com>
Thu, 8 Apr 2021 19:58:03 +0000 (12:58 -0700)
* Add database and aspnet-requests profiles to dotnet-trace

- Add database profile to dotnet-trace that captures ADO.NET and
EntityFramework events through DiagnosticSourceEventSource. Resulting
file can be viewed in Visual Studio with the PerformanceProfiler
- Add aspnet-requests profile to dotnet-trace that captures ASP.NET
requests and TPL events through DiagnosticSourceEventSource. Resulting
file can be viewed in Visual Studio with the PerformanceProfiler

* Remove aspnet-requests and trim usage of TPL provider.

- Remove the aspnet-requests profile for now. This also reduces the TPL
provider to just informational TaskFlowActivityIds to enable the
ActivityTracker

Co-authored-by: Nik Karpinsky <nikarpin@microsoft.com>
src/Tools/dotnet-trace/CommandLine/Commands/ListProfilesCommandHandler.cs

index 5230e4881a11dbbdf710bc52bdc047f5585f9575..13b17cb81ea46b1b5de6f94c12788eb34d87bf23 100644 (file)
@@ -70,6 +70,44 @@ namespace Microsoft.Diagnostics.Tools.Trace
                     )
                 },
                 "Tracks GC collections only at very low overhead."),
+            new Profile(
+                "database",
+                new EventPipeProvider[] {
+                    new EventPipeProvider(
+                        name: "System.Threading.Tasks.TplEventSource",
+                        eventLevel: EventLevel.Informational,
+                        keywords: (long)TplEtwProviderTraceEventParser.Keywords.TasksFlowActivityIds
+                    ),
+                    new EventPipeProvider(
+                        name: "Microsoft-Diagnostics-DiagnosticSource",
+                        eventLevel: EventLevel.Verbose,
+                        keywords:   (long)DiagnosticSourceKeywords.Messages |
+                                    (long)DiagnosticSourceKeywords.Events,
+                        arguments: new Dictionary<string, string> {
+                            {
+                                "FilterAndPayloadSpecs",
+                                    "SqlClientDiagnosticListener/System.Data.SqlClient.WriteCommandBefore@Activity1Start:-Command;Command.CommandText;ConnectionId;Operation;Command.Connection.ServerVersion;Command.CommandTimeout;Command.CommandType;Command.Connection.ConnectionString;Command.Connection.Database;Command.Connection.DataSource;Command.Connection.PacketSize\r\n" + 
+                                    "SqlClientDiagnosticListener/System.Data.SqlClient.WriteCommandAfter@Activity1Stop:\r\n" + 
+                                    "Microsoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.Database.Command.CommandExecuting@Activity2Start:-Command.CommandText;Command;ConnectionId;IsAsync;Command.Connection.ClientConnectionId;Command.Connection.ServerVersion;Command.CommandTimeout;Command.CommandType;Command.Connection.ConnectionString;Command.Connection.Database;Command.Connection.DataSource;Command.Connection.PacketSize\r\n" + 
+                                    "Microsoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted@Activity2Stop:"
+                            }
+                        }
+                    )
+                },
+                "Captures ADO.NET and Entity Framework database commands")
         };
+
+        /// <summary>
+        /// Keywords for DiagnosticSourceEventSource provider
+        /// </summary>
+        /// <remarks>See https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs</remarks>
+        private enum DiagnosticSourceKeywords : long
+        {
+            Messages = 0x1,
+            Events = 0x2,
+            IgnoreShortCutKeywords = 0x0800,
+            AspNetCoreHosting = 0x1000,
+            EntityFrameworkCoreCommands = 0x2000
+        }
     }
 }