-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API review: add interception for DbCommand creation #16716
Conversation
@roji @smitpatel Could one of you review this since there are not many people not on vacation right now. :-) |
src/EFCore.Relational/Diagnostics/CommandCorrelatedEventData.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See two perf comments.
@@ -75,16 +74,17 @@ public virtual int ExecuteNonQuery(RelationalCommandParameterObject parameterObj | |||
{ | |||
var (connection, context, logger) = (parameterObject.Connection, parameterObject.Context, parameterObject.Logger); | |||
|
|||
var command = CreateCommand(connection, parameterObject.ParameterValues); | |||
var commandId = Guid.NewGuid(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd only do this if we have interceptors configured (GUID generation unfortunately isn't free, e.g. dotnet/coreclr#1738 (comment)) but this is likely negligible.
|
||
var command = connection.DbConnection.CreateCommand(); | ||
var startTime = DateTimeOffset.UtcNow; | ||
var stopwatch = Stopwatch.StartNew(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am curious - IIRC usually start/end activities and durations are calculated by EventSource/DiagnosticSource (have no idea to what extent we support activities in those etc).
Note that StopWatch is an additional allocation for every command creation that won't actually be needed for the general case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last I was aware of, activities don't work for interleaved events. (That is, when, for example, multiple commands are created before any of them finish.)
I added a note to #16197 about perf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no expert but I seem to remember that interleaved activities are possible, at least with EventSource - an ActivityID is used to correlate between start and stop (we'd use the GUID here). See this post.
333038d
to
ffd6df3
Compare
Fixes #16715