Skip to content

Commit

Permalink
dotnet#7105 Trace when query is done. This is needed in order to get …
Browse files Browse the repository at this point in the history
…SelectRows statistics. Take dotnet#2: Use the DiagnosticSource on RelationalDataReader.
  • Loading branch information
Fitzchak Yitzchaki committed Nov 29, 2016
1 parent 89d1503 commit 71ab7c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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 DataReaderDisposed = NamePrefix + nameof(DataReaderDisposed);

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 WriteDataReaderDisposed(this DiagnosticSource diagnosticSource, RelationalDataReader dataReader)
{
if (diagnosticSource.IsEnabled(DataReaderDisposed))
{
diagnosticSource.Write(DataReaderDisposed, dataReader);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected virtual object Execute(
= new RelationalDataReader(
connection,
dbCommand,
dbCommand.ExecuteReader());
dbCommand.ExecuteReader(), DiagnosticSource);
}
catch
{
Expand Down Expand Up @@ -344,7 +344,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,20 @@ 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)
{
Check.NotNull(command, nameof(command));
Check.NotNull(reader, nameof(reader));

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

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

0 comments on commit 71ab7c4

Please sign in to comment.