From 0d9c684fc507f548dfde20e296a5e7abd2dad05f Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Fri, 8 May 2020 12:17:24 +0100 Subject: [PATCH 1/2] avoid calling tracestring and pass enabled flag to avoid repeated requesrt of log enabled in a loop --- .../src/Microsoft/Data/SqlClient/TdsParser.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index cfac61e4c7..c950e9fbfa 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -8872,6 +8872,8 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo // Stream out parameters int parametersLength = rpcext.userParamCount + rpcext.systemParamCount; + bool isAdvancedTraceOn = SqlClientEventSource.Log.IsAdvancedTraceOn(); + for (int i = (ii == startRpc) ? startParam : 0; i < parametersLength; i++) { byte options = 0; @@ -8904,7 +8906,7 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo if (mt.IsNewKatmaiType) { - WriteSmiParameter(param, i, 0 != (options & TdsEnums.RPC_PARAM_DEFAULT), stateObj); + WriteSmiParameter(param, i, 0 != (options & TdsEnums.RPC_PARAM_DEFAULT), stateObj, isAdvancedTraceOn); continue; } @@ -9601,7 +9603,7 @@ private void WriteParameterName(string parameterName, TdsParserStateObject state } } - private void WriteSmiParameter(SqlParameter param, int paramIndex, bool sendDefault, TdsParserStateObject stateObj) + private void WriteSmiParameter(SqlParameter param, int paramIndex, bool sendDefault, TdsParserStateObject stateObj, bool advancedTraceIsOn) { // // Determine Metadata @@ -9651,8 +9653,11 @@ private void WriteSmiParameter(SqlParameter param, int paramIndex, bool sendDefa typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(metaData.SqlDbType, metaData.IsMultiValued, value, null); } - var sendDefaultValue = sendDefault ? 1 : 0; - SqlClientEventSource.Log.AdvancedTraceEvent(" {0}, Sending parameter '{1}', default flag={2}, metadata:{3}", ObjectID, param.ParameterName, sendDefaultValue, metaData.TraceString(3)); + if (advancedTraceIsOn) + { + var sendDefaultValue = sendDefault ? 1 : 0; + SqlClientEventSource.Log.AdvancedTraceEvent(" {0}, Sending parameter '{1}', default flag={2}, metadata:{3}", ObjectID, param.ParameterName, sendDefaultValue, metaData); + } // // Write parameter metadata From 701174e19701e447df32d7ca24406896926ff9a5 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Sat, 9 May 2020 13:58:03 +0100 Subject: [PATCH 2/2] restore the TraceString call --- .../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index c950e9fbfa..20e48c9e7c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -9656,7 +9656,7 @@ private void WriteSmiParameter(SqlParameter param, int paramIndex, bool sendDefa if (advancedTraceIsOn) { var sendDefaultValue = sendDefault ? 1 : 0; - SqlClientEventSource.Log.AdvancedTraceEvent(" {0}, Sending parameter '{1}', default flag={2}, metadata:{3}", ObjectID, param.ParameterName, sendDefaultValue, metaData); + SqlClientEventSource.Log.AdvancedTraceEvent(" {0}, Sending parameter '{1}', default flag={2}, metadata:{3}", ObjectID, param.ParameterName, sendDefaultValue, metaData.TraceString(3)); } //