Skip to content
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

Merged
merged 1 commit into from
Jul 25, 2019

Conversation

ajcvickers
Copy link
Member

Fixes #16715

@ajcvickers
Copy link
Member Author

@roji @smitpatel Could one of you review this since there are not many people not on vacation right now. :-)

Copy link
Contributor

@smitpatel smitpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Member

@roji roji left a 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();
Copy link
Member

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();
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add interception for command creation
3 participants