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. Take dotnet#3: Fix requested changes.
  • Loading branch information
Fitzchak Yitzchaki committed Nov 30, 2016
1 parent 89d1503 commit 2a66ac9
Show file tree
Hide file tree
Showing 3 changed files with 24 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 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)
{
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

0 comments on commit 2a66ac9

Please sign in to comment.