Skip to content

Commit

Permalink
Support new event source types & add the test unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Davoud Eshtehari authored and Davoud Eshtehari committed Sep 2, 2020
1 parent ada285a commit 51a6f63
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp' AND '$(TargetFramework)' != 'netcoreapp2.1'">
<DefineConstants>$(DefineConstants);NETCORE3</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard' AND '$(TargetFramework)' != 'netstandard2.0'">
<DefineConstants>$(DefineConstants);NETSTANDARD21</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
Expand All @@ -45,7 +42,6 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEventSource.cs">
<Link>Microsoft\Data\SqlClient\SqlClientEventSource.cs</Link>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlClientEventSource.NetCoreApp.cs" />
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientLogger.cs">
<Link>Microsoft\Data\SqlClient\SqlClientLogger.cs</Link>
</Compile>
Expand Down Expand Up @@ -251,6 +247,14 @@
<Compile Include="Microsoft\Data\SqlClient\EnclaveProviderBase.cs" />
<Compile Include="Microsoft\Data\SqlClient\EnclaveSessionCache.cs" />
</ItemGroup>
<!-- netcoreapp 2.1 & netstandard 2.0 -->
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND ('$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netstandard2.0')">
<Compile Include="Microsoft\Data\SqlClient\SqlClientEventSource.NetCoreApp2.cs" />
</ItemGroup>
<!-- netcoreapp 3.1 & netstandard 2.1 and above -->
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetFramework)' != 'netcoreapp2.1' AND '$(TargetFramework)' != 'netstandard2.0'">
<Compile Include="Microsoft\Data\SqlClient\SqlClientEventSource.NetCoreApp3.cs" />
</ItemGroup>
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetGroup)' == 'netcoreapp'">
<Compile Include="Microsoft\Data\Common\DbConnectionStringCommon.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPool.NetCoreApp.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

namespace Microsoft.Data.SqlClient
{
internal partial class SqlClientEventSource : EventSource
/// <summary>
/// supported frameworks: .Net core 2.1 and .Net standard 2.0
/// </summary>
internal partial class SqlClientEventSource : SqlClientEventSourceBase
{
private EventCounter _activeHardConnections;
private EventCounter _hardConnectsPerSecond;
Expand Down Expand Up @@ -53,151 +56,31 @@ internal partial class SqlClientEventSource : EventSource
private long _stasisConnectionsCounter = 0;
private long _reclaimedConnectionsCounter = 0;

public SqlClientEventSource()
protected override void EventCommandMethodCall(EventCommandEventArgs command)
{
_activeHardConnections = _activeHardConnections ??
new EventCounter("active-hard-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Actual active connections are made to servers",
DisplayUnits = "count"
#endif
};

_hardConnectsPerSecond = _hardConnectsPerSecond ??
new EventCounter("hard-connects", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Actual connections are made to servers",
DisplayUnits = "count / sec"
#endif
};

_hardDisconnectsPerSecond = _hardDisconnectsPerSecond ??
new EventCounter("hard-disconnects", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Actual disconnections are made to servers",
DisplayUnits = "count / sec"
#endif
};

_activeSoftConnections = _activeSoftConnections ??
new EventCounter("active-soft-connects", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Active connections got from connection pool",
DisplayUnits = "count"
#endif
};

_softConnects = _softConnects ??
new EventCounter("soft-connects", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Connections got from connection pool",
DisplayUnits = "count / sec"
#endif
};

_softDisconnects = _softDisconnects ??
new EventCounter("soft-disconnects", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Connections returned to the connection pool",
DisplayUnits = "count / sec"
#endif
};

_numberOfNonPooledConnections = _numberOfNonPooledConnections ??
new EventCounter("number-of-non-pooled-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of connections are not using connection pooling",
DisplayUnits = "count / sec"
#endif
};

_numberOfPooledConnections = _numberOfPooledConnections ??
new EventCounter("number-of-pooled-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of connections are managed by connection pooler",
DisplayUnits = "count / sec"
#endif
};

_numberOfActiveConnectionPoolGroups = _numberOfActiveConnectionPoolGroups ??
new EventCounter("number-of-active-connection-pool-groups", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of active unique connection strings",
DisplayUnits = "count"
#endif
};

_numberOfInactiveConnectionPoolGroups = _numberOfInactiveConnectionPoolGroups ??
new EventCounter("number-of-inactive-connection-pool-groups", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of unique connection strings waiting for pruning",
DisplayUnits = "count"
#endif
};

_numberOfActiveConnectionPools = _numberOfActiveConnectionPools ??
new EventCounter("number-of-active-connection-pools", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of active connection pools",
DisplayUnits = "count"
#endif
};

_numberOfInactiveConnectionPools = _numberOfInactiveConnectionPools ??
new EventCounter("number-of-inactive-connection-pools", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of inactive connection pools",
DisplayUnits = "count"
#endif
};

_numberOfActiveConnections = _numberOfActiveConnections ??
new EventCounter("number-of-active-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of active connections",
DisplayUnits = "count"
#endif
};

_numberOfFreeConnections = _numberOfFreeConnections ??
new EventCounter("number-of-free-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of free-ready connections",
DisplayUnits = "count"
#endif
};

_numberOfStasisConnections = _numberOfStasisConnections ??
new EventCounter("number-of-stasis-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of connections currently waiting to be ready",
DisplayUnits = "count"
#endif
};

_numberOfReclaimedConnections = _numberOfReclaimedConnections ??
new EventCounter("number-of-reclaimed-connections", this)
{
#if NETCORE3 || NETSTANDARD21
DisplayName = "Number of reclaimed connections from GC",
DisplayUnits = "count"
#endif
};
if (command.Command != EventCommand.Enable)
{
return;
}

_activeHardConnections = _activeHardConnections ?? new EventCounter("active-hard-connections", this);
_hardConnectsPerSecond = _hardConnectsPerSecond ?? new EventCounter("hard-connects", this);
_hardDisconnectsPerSecond = _hardDisconnectsPerSecond ?? new EventCounter("hard-disconnects", this);

_activeSoftConnections = _activeSoftConnections ?? new EventCounter("active-soft-connects", this);
_softConnects = _softConnects ?? new EventCounter("soft-connects", this);
_softDisconnects = _softDisconnects ?? new EventCounter("soft-disconnects", this);

_numberOfNonPooledConnections = _numberOfNonPooledConnections ?? new EventCounter("number-of-non-pooled-connections", this);
_numberOfPooledConnections = _numberOfPooledConnections ?? new EventCounter("number-of-pooled-connections", this);
_numberOfActiveConnectionPoolGroups = _numberOfActiveConnectionPoolGroups ?? new EventCounter("number-of-active-connection-pool-groups", this);
_numberOfInactiveConnectionPoolGroups = _numberOfInactiveConnectionPoolGroups ?? new EventCounter("number-of-inactive-connection-pool-groups", this);
_numberOfActiveConnectionPools = _numberOfActiveConnectionPools ?? new EventCounter("number-of-active-connection-pools", this);
_numberOfInactiveConnectionPools = _numberOfInactiveConnectionPools ?? new EventCounter("number-of-inactive-connection-pools", this);
_numberOfActiveConnections = _numberOfActiveConnections ?? new EventCounter("number-of-active-connections", this);
_numberOfFreeConnections = _numberOfFreeConnections ?? new EventCounter("number-of-free-connections", this);
_numberOfStasisConnections = _numberOfStasisConnections ?? new EventCounter("number-of-stasis-connections", this);
_numberOfReclaimedConnections = _numberOfReclaimedConnections ?? new EventCounter("number-of-reclaimed-connections", this);
}

/// <summary>
Expand Down
Loading

0 comments on commit 51a6f63

Please sign in to comment.