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

#7105 Trace when query is done. This is needed in order to get Select… #7106

Merged
merged 1 commit into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Data.Common;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Internal
{
Expand All @@ -15,6 +16,8 @@ internal static class RelationalDiagnostics
public const string AfterExecuteCommand = NamePrefix + nameof(AfterExecuteCommand);
public const string CommandExecutionError = NamePrefix + nameof(CommandExecutionError);

public const string DataReaderDisposing = NamePrefix + nameof(DataReaderDisposing);

public static void WriteCommandBefore(
this DiagnosticSource diagnosticSource,
DbCommand command, string executeMethod,
Expand Down Expand Up @@ -88,5 +91,13 @@ public static void WriteCommandError(
});
}
}

public static void WriteDataReaderDisposing(this DiagnosticSource diagnosticSource, DbDataReader dataReader)
{
if (diagnosticSource.IsEnabled(DataReaderDisposing))
{
diagnosticSource.Write(DataReaderDisposing, dataReader);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ protected virtual object Execute(
= new RelationalDataReader(
connection,
dbCommand,
dbCommand.ExecuteReader());
dbCommand.ExecuteReader(),
DiagnosticSource);
}
catch
{
Expand Down Expand Up @@ -344,7 +345,8 @@ protected virtual async Task<object> ExecuteAsync(
result = new RelationalDataReader(
connection,
dbCommand,
await dbCommand.ExecuteReaderAsync(cancellationToken));
await dbCommand.ExecuteReaderAsync(cancellationToken),
DiagnosticSource);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System;
using System.Data.Common;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Storage
Expand All @@ -22,6 +24,7 @@ public class RelationalDataReader : IDisposable
private readonly IRelationalConnection _connection;
private readonly DbCommand _command;
private readonly DbDataReader _reader;
private readonly DiagnosticSource _diagnosticSource;

private bool _disposed;

Expand All @@ -31,17 +34,21 @@ public class RelationalDataReader : IDisposable
/// <param name="connection"> The connection. </param>
/// <param name="command"> The command that was executed. </param>
/// <param name="reader"> The underlying reader for the result set. </param>
/// <param name="diagnosticSource"> The diagnostic source. </param>
public RelationalDataReader(
[CanBeNull] IRelationalConnection connection,
[NotNull] DbCommand command,
[NotNull] DbDataReader reader)
[NotNull] DbDataReader reader,
[NotNull] DiagnosticSource diagnosticSource)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add Check.NotNull

Copy link
Author

Choose a reason for hiding this comment

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

Done

{
Check.NotNull(command, nameof(command));
Check.NotNull(reader, nameof(reader));
Check.NotNull(diagnosticSource, nameof(diagnosticSource));

_connection = connection;
_command = command;
_reader = reader;
_diagnosticSource = diagnosticSource;
}

/// <summary>
Expand All @@ -65,6 +72,7 @@ public virtual void Dispose()
{
if (!_disposed)
{
_diagnosticSource.WriteDataReaderDisposing(_reader);
_reader.Dispose();
_command.Dispose();
_connection?.Close();
Expand Down