From 37fcfe37147803c4183f6b46bf8981a958f61896 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Thu, 7 Dec 2023 16:42:29 -0300 Subject: [PATCH] Remove overhead at TraceRow method when log is turned off. --- .../GxClasses/Data/GXDataCommon.cs | 4 +- .../GxClasses/Data/GXDataMysqlConnector.cs | 5 +- .../GxClasses/Data/GXDataMysqlDriverCS.cs | 5 +- .../GxClasses/Data/GXDataNTierADO.cs | 46 +++++++++---------- .../GxClasses/Domain/GxCollections.cs | 5 +- .../GxClasses/Helpers/GXLogging.cs | 12 +++++ .../GxClasses/Services/Caching/GxCache.cs | 8 +++- 7 files changed, 54 insertions(+), 31 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs index 362374b08..58a261c3e 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs @@ -2174,7 +2174,7 @@ public class GxDataReader: IDataReader protected string stmt; protected GxConnectionCache cache; protected IGxConnection con; - protected GxArrayList block; + protected List block; protected string key; protected int pos; protected bool cached; @@ -2208,7 +2208,7 @@ public GxDataReader( IGxConnectionManager connManager, GxDataRecord dr, IGxConne reader=dr.GetCommand(con,stmt,parameters).ExecuteReader(); cache.SetAvailableCommand(stmt, false, dynStmt); open=true; - block=new GxArrayList(fetchSize); + block= new List(fetchSize); pos=-1; if (cached) { diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlConnector.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlConnector.cs index a804ae6c3..56d6684c2 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlConnector.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlConnector.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Reflection; @@ -570,7 +571,7 @@ public GxMySQLConnectorDataReader(IGxConnectionManager connManager, GxDataRecord reader = cmd.ExecuteReader(); cache.SetAvailableCommand(stmt, false, dynStmt); open = true; - block = new GxArrayList(fetchSize); + block = new List(fetchSize); pos = -1; if (cached) { @@ -622,7 +623,7 @@ public GxMySQLConnectorCursorDataReader(IGxConnectionManager connManager, GxData reader = cmd.ExecuteReader(); cache.SetAvailableCommand(stmt, false, dynStmt); open = true; - block = new GxArrayList(fetchSize); + block = new List(fetchSize); pos = -1; if (cached) { diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlDriverCS.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlDriverCS.cs index a2688ea3b..956b7c011 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlDriverCS.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataMysqlDriverCS.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Text; @@ -497,7 +498,7 @@ public GxMySQLDriverCSDataReader(IGxConnectionManager connManager, GxDataRecord reader = cmd.ExecuteReader(); cache.SetAvailableCommand(stmt, false, dynStmt); open = true; - block = new GxArrayList(fetchSize); + block = new List(fetchSize); pos = -1; if (cached) { @@ -542,7 +543,7 @@ public GxMySQLDriverCSCursorDataReader(IGxConnectionManager connManager, GxDataR reader = cmd.ExecuteReader(); cache.SetAvailableCommand(stmt, false, dynStmt); open = true; - block = new GxArrayList(fetchSize); + block = new List(fetchSize); pos = -1; if (cached) { diff --git a/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs b/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs index 94b1b7e90..7ade08946 100644 --- a/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs +++ b/dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs @@ -210,11 +210,11 @@ public GXFatFieldGetter(GxCommand gxDbCommand) { _gxDbCommand = gxDbCommand; } - void TraceRow(params string[] list) + void TraceRow(Func buildMsg) { if (_gxDbCommand.HasMoreRows) { - GXLogging.Trace(log, list); + GXLogging.Trace(log, buildMsg); } } public IDataReader DataReader @@ -225,57 +225,57 @@ public IDataReader DataReader public short getShort(int id) { short value = _gxDbCommand.Db.GetShort(_gxDbCommand, _DR, id - 1); - TraceRow("getShort - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(()=> $"getShort - index : {id} value:{value}"); return value; } public int getInt(int id) { int value = _gxDbCommand.Db.GetInt(_gxDbCommand, _DR, id - 1); - TraceRow("getInt - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getInt - index : {id} value:{value}"); return value; } public bool getBool(int id) { bool value = _gxDbCommand.Db.GetBoolean(_gxDbCommand, _DR, id - 1); - TraceRow("getBool - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getBool - index : {id} value:{value}"); return value; } public Guid getGuid(int id) { Guid value = _gxDbCommand.Db.GetGuid(_gxDbCommand, _DR, id - 1); - TraceRow("getGuid - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getGuid - index : {id} value:{value}"); return value; } public long getLong(int id) { long value = _gxDbCommand.Db.GetLong(_gxDbCommand, _DR, id - 1); - TraceRow("getLong - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getLong - index : {id} value:{value}"); return value; } public double getDouble(int id) { double value= _gxDbCommand.Db.GetDouble(_gxDbCommand, _DR, id - 1); - TraceRow("getDouble - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getDouble - index : {id} value:{value}"); return value; } public Decimal getDecimal(int id) { Decimal value= _gxDbCommand.Db.GetDecimal(_gxDbCommand, _DR, id - 1); - TraceRow("getDecimal - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getDecimal - index : {id} value:{value}"); return value; } public string getString(int id, int size) { String value = _gxDbCommand.Db.GetString(_gxDbCommand, _DR, id - 1, size); - TraceRow("getString - index : ", id.ToString(), " value:", (value!=null ? value.ToString(): string.Empty)); + TraceRow(() => $"getString - index : {id} value:{(value!=null ? value.ToString(): string.Empty)}"); return value; } public DateTime getDateTime(int id) { DateTime value = _gxDbCommand.Db.GetDateTime(_gxDbCommand, _DR, id - 1); - TraceRow("getDateTime - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getDateTime - index : {id} value:{value}"); return value; } public DateTime getDateTime(int id, Boolean precision) @@ -287,19 +287,19 @@ public DateTime getDateTime(int id, Boolean precision) else { value = _gxDbCommand.Db.GetDateTime(_gxDbCommand, _DR, id - 1); } - TraceRow("getDateTime - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getDateTime - index : {id} value:{value}"); return value; } public DateTime getDate(int id) { DateTime value = _gxDbCommand.Db.GetDate(_gxDbCommand, _DR, id - 1); - TraceRow("getDate - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getDate - index : {id} value:{value}"); return value; } public string getLongVarchar(int id) { string value = _gxDbCommand.Db.GetString(_gxDbCommand, _DR, id - 1); - TraceRow("getLongVarchar - index : ", id.ToString(), " value:", (value!=null ? value.ToString(): string.Empty)); + TraceRow(() => $"getLongVarchar - index : {id} value:{(value != null ? value.ToString() : string.Empty)}"); return value; } public DateTime getGXDateTime(int id, Boolean precision) @@ -309,7 +309,7 @@ public DateTime getGXDateTime(int id, Boolean precision) #else DateTime value = DateTimeUtil.DBserver2local(getDateTime(id, precision), _gxDbCommand.Conn.ClientTimeZone); #endif - TraceRow("getDateTime - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getDateTime - index : {id} value:{value}"); return value; } public DateTime getGXDateTime(int id) @@ -319,19 +319,19 @@ public DateTime getGXDateTime(int id) #else DateTime value = DateTimeUtil.DBserver2local(getDateTime(id, false), _gxDbCommand.Conn.ClientTimeZone); #endif - TraceRow("getGXDateTime - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getGXDateTime - index : {id} value:{value.ToString()}"); return value; } public DateTime getGXDate(int id) { DateTime value = getDate(id); - TraceRow("getGXDate - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getGXDate - index : {id} value:{value.ToString()}"); return value; } public string getBLOBFile(int id) { string value= getBLOBFile(id, "tmp", ""); - TraceRow("getBLOBFile - index : ", id.ToString(), " value:", (value!=null ? value.ToString() : string.Empty)); + TraceRow(() => $"getBLOBFile - index : {id} value:{(value != null ? value.ToString() : string.Empty)}"); return value; } @@ -339,7 +339,7 @@ public string getBLOBFile(int id, string extension, string name) { string fileName = FileUtil.getTempFileName(_gxDbCommand.Conn.BlobPath, name, extension, GxFileType.Private); String value = getBLOBFile(id, extension, name, fileName, true); - TraceRow("getBLOBFile - index : ", id.ToString(), " value:", (value!=null ? value.ToString() : string.Empty)); + TraceRow(() => $"getBLOBFile - index : {id} value:{(value != null ? value.ToString() : string.Empty)}"); return value; } @@ -389,7 +389,7 @@ private string getBLOBFile(int id, string extension, string name, string fileNam } streamClosed = true; - TraceRow("GetBlobFile fileName:" + fileName + ", retval bytes:" + retval); + TraceRow(() => $"GetBlobFile fileName:{fileName}, retval bytes:{retval}"); if (temporary) GXFileWatcher.Instance.AddTemporaryFile(file, _gxDbCommand.Conn.DataStore.Context); @@ -473,20 +473,20 @@ public string getMultimediaUri(int id, bool absUrl) public string getVarchar(int id) { string value = _gxDbCommand.Db.GetString(_gxDbCommand, _DR, id - 1); - TraceRow("getVarchar - index : ", id.ToString(), " value:", (value != null ? value.ToString() : string.Empty)); + TraceRow(() => $"getVarchar - index : {id} value:{(value != null ? value.ToString() : string.Empty)}"); return value; } public decimal getBigDecimal(int id, int dec) { decimal value =_gxDbCommand.Db.GetDecimal(_gxDbCommand, _DR, id - 1); - TraceRow("getBigDecimal - index : ", id.ToString(), " value:", value.ToString()); + TraceRow(() => $"getBigDecimal - index : {id} value:{value.ToString()}"); return value; } public IGeographicNative getGeospatial(int id) { IGeographicNative value = _gxDbCommand.Db.GetGeospatial(_gxDbCommand, _DR, id - 1); - TraceRow("getGeospatial - index : ", id.ToString(), " value:", (value != null ? value.ToString() : string.Empty)); + TraceRow(() => $"getGeospatial - index : {id} value:{(value != null ? value.ToString() : string.Empty)}"); return value; } diff --git a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs index e14805a46..6a69c2d9e 100644 --- a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs +++ b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs @@ -2044,6 +2044,10 @@ public GxArrayList(int capacity) { innerArray = new List(capacity); } + internal GxArrayList(List list) + { + innerArray = list; + } public GxArrayList() { innerArray = new List(); @@ -2076,7 +2080,6 @@ public object Item(int index, int i) return innerArray[index][i]; } } - [CollectionDataContract(Name = "GxUnknownObjectCollection")] [KnownType(typeof(GxSimpleCollection))] [KnownType(typeof(GxStringCollection))] diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs index 0cfa76acf..bde6a16b8 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs @@ -506,6 +506,18 @@ internal static void Trace(IGXLogger logger, params string[] list) logger.LogTrace(string.Join(" ", list)); } } + internal static void Trace(IGXLogger logger, Func buildMsg) + { + if (logger != null) + { + if (logger.IsTraceEnabled) + { + string msg = buildMsg(); + logger.LogTrace(msg); + } + } + } + public static void Critical(IGXLogger logger, params string[] list) { if (logger != null) diff --git a/dotnet/src/dotnetframework/GxClasses/Services/Caching/GxCache.cs b/dotnet/src/dotnetframework/GxClasses/Services/Caching/GxCache.cs index 1bda980fe..63f293597 100644 --- a/dotnet/src/dotnetframework/GxClasses/Services/Caching/GxCache.cs +++ b/dotnet/src/dotnetframework/GxClasses/Services/Caching/GxCache.cs @@ -587,7 +587,13 @@ public class CacheItem public CacheItem() { } - + internal CacheItem(List data, bool hasnext, int blockSize, long sizeInBytes) + { + Data = new GxArrayList(data); + HasNext = hasnext; + BlockSize = blockSize; + SizeInBytes = sizeInBytes; + } public CacheItem(GxArrayList data, bool hasnext, int blockSize, long sizeInBytes) { Data = data;