diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Common/ActivityCorrelator.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Common/ActivityCorrelator.cs index 550cbf24e0..27d4ffbdbb 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Common/ActivityCorrelator.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Common/ActivityCorrelator.cs @@ -15,30 +15,15 @@ namespace Microsoft.Data.Common internal static class ActivityCorrelator { - internal class ActivityId + internal sealed class ActivityId { - internal Guid Id { get; private set; } - internal UInt32 Sequence { get; private set; } + internal readonly Guid Id; + internal readonly uint Sequence; - internal ActivityId() + internal ActivityId(uint sequence) { this.Id = Guid.NewGuid(); - this.Sequence = 0; // the first event will start 1 - } - - // copy-constructor - internal ActivityId(ActivityId activity) - { - this.Id = activity.Id; - this.Sequence = activity.Sequence; - } - - internal void Increment() - { - unchecked - { - ++this.Sequence; - } + this.Sequence = sequence; } public override string ToString() @@ -51,7 +36,7 @@ public override string ToString() // The Sequence number will be incremented when each event happens. // Correlation along threads is consistent with the current XEvent mechanisam at server. [ThreadStaticAttribute] - static ActivityId tlsActivity; + static ActivityId t_tlsActivity; /// /// Get the current ActivityId @@ -60,12 +45,12 @@ internal static ActivityId Current { get { - if (tlsActivity == null) + if (t_tlsActivity == null) { - tlsActivity = new ActivityId(); + t_tlsActivity = new ActivityId(1); } - return new ActivityId(tlsActivity); + return t_tlsActivity; } } @@ -75,14 +60,9 @@ internal static ActivityId Current /// ActivityId internal static ActivityId Next() { - if (tlsActivity == null) - { - tlsActivity = new ActivityId(); - } - - tlsActivity.Increment(); - - return new ActivityId(tlsActivity); + t_tlsActivity = new ActivityId(t_tlsActivity?.Sequence ?? 0); + + return t_tlsActivity; } } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs index c4b835c2e7..ee768d9c9a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -1316,7 +1316,10 @@ internal void Deactivate(bool connectionIsDoomed) // Called when the connection that owns us is deactivated. SqlClientEventSource.Log.AdvanceTrace(" {0}# deactivating", ObjectID); - SqlClientEventSource.Log.StateDumpEvent(" {0}#, {1}", ObjectID, TraceString()); + if (SqlClientEventSource.Log.IsStateDumpEnabled()) + { + SqlClientEventSource.Log.StateDumpEvent(" {0}#, {1}", ObjectID, TraceString()); + } if (MARSOn) { @@ -13504,13 +13507,13 @@ internal ulong PlpBytesTotalLength(TdsParserStateObject stateObj) ; internal string TraceString() { - return String.Format(/*IFormatProvider*/ null, + return string.Format(/*IFormatProvider*/ null, StateTraceFormatString, - null == _physicalStateObj, - null == _pMarsPhysicalConObj, + null == _physicalStateObj ? bool.TrueString : bool.FalseString, + null == _pMarsPhysicalConObj ? bool.TrueString : bool.FalseString, _state, _server, - _fResetConnection, + _fResetConnection ? bool.TrueString : bool.FalseString, null == _defaultCollation ? "(null)" : _defaultCollation.TraceString(), _defaultCodePage, _defaultLCID, @@ -13522,19 +13525,19 @@ internal string TraceString() _retainedTransactionId, _nonTransactedOpenResultCount, null == _connHandler ? "(null)" : _connHandler.ObjectID.ToString((IFormatProvider)null), - _fMARS, + _fMARS ? bool.TrueString : bool.FalseString, null == _sessionPool ? "(null)" : _sessionPool.TraceString(), - _isShiloh, - _isShilohSP1, - _isYukon, + _isShiloh ? bool.TrueString : bool.FalseString, + _isShilohSP1 ? bool.TrueString : bool.FalseString, + _isYukon ? bool.TrueString : bool.FalseString, null == _sniSpnBuffer ? "(null)" : _sniSpnBuffer.Length.ToString((IFormatProvider)null), _physicalStateObj != null ? "(null)" : _physicalStateObj.ErrorCount.ToString((IFormatProvider)null), _physicalStateObj != null ? "(null)" : _physicalStateObj.WarningCount.ToString((IFormatProvider)null), _physicalStateObj != null ? "(null)" : _physicalStateObj.PreAttentionErrorCount.ToString((IFormatProvider)null), _physicalStateObj != null ? "(null)" : _physicalStateObj.PreAttentionWarningCount.ToString((IFormatProvider)null), - null == _statistics, - _statisticsIsInTransaction, - _fPreserveTransaction, + null == _statistics ? bool.TrueString : bool.FalseString, + _statisticsIsInTransaction ? bool.TrueString : bool.FalseString, + _fPreserveTransaction ? bool.TrueString : bool.FalseString, null == _connHandler ? "(null)" : _connHandler.ConnectionOptions.MultiSubnetFailover.ToString((IFormatProvider)null), null == _connHandler ? "(null)" : _connHandler.ConnectionOptions.TransparentNetworkIPResolution.ToString((IFormatProvider)null)); }