Various allocation & GC improvements
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
"profileSaveIntervalSeconds": 60,
|
"profileSaveIntervalSeconds": 60,
|
||||||
"sptFriendNickname": "SPT",
|
"sptFriendNickname": "SPT",
|
||||||
"allowProfileWipe": true,
|
"allowProfileWipe": true,
|
||||||
"enableNoGCRegions": true,
|
"enableNoGCRegions": false,
|
||||||
"noGCRegionMaxMemoryGB": 4,
|
"noGCRegionMaxMemoryGB": 4,
|
||||||
"noGCRegionMaxLOHMemoryGB": 3,
|
"noGCRegionMaxLOHMemoryGB": 3,
|
||||||
"bsgLogging": {
|
"bsgLogging": {
|
||||||
|
|||||||
@@ -8,19 +8,32 @@ public abstract class BaseLogHandler : ILogHandler
|
|||||||
|
|
||||||
protected string FormatMessage(string processedMessage, SptLogMessage message, BaseSptLoggerReference reference)
|
protected string FormatMessage(string processedMessage, SptLogMessage message, BaseSptLoggerReference reference)
|
||||||
{
|
{
|
||||||
var formattedMessage = reference
|
var format = reference.GetCompiledFormat();
|
||||||
.Format.Replace("%date%", message.LogTime.ToString("yyyy-MM-dd"))
|
|
||||||
.Replace("%time%", message.LogTime.ToString("HH:mm:ss.fff"))
|
var formattedMessage = string.Format(
|
||||||
.Replace("%message%", processedMessage)
|
null,
|
||||||
.Replace("%loggerShort%", message.Logger.Split('.').Last())
|
format,
|
||||||
.Replace("%logger%", message.Logger)
|
message.LogTime.ToString("yyyy-MM-dd"),
|
||||||
.Replace("%tid%", message.threadId.ToString())
|
message.LogTime.ToString("HH:mm:ss.fff"),
|
||||||
.Replace("%tname%", message.threadName)
|
processedMessage,
|
||||||
.Replace("%level%", Enum.GetName(message.LogLevel));
|
GetLoggerShortName(message.Logger),
|
||||||
|
message.Logger,
|
||||||
|
message.threadId,
|
||||||
|
message.threadName,
|
||||||
|
message.LogLevel.ToString()
|
||||||
|
);
|
||||||
|
|
||||||
if (message.Exception != null)
|
if (message.Exception != null)
|
||||||
{
|
{
|
||||||
formattedMessage += $"\n{message.Exception.Message}\n{message.Exception.StackTrace}";
|
return string.Concat(formattedMessage, "\n", message.Exception.Message, "\n", message.Exception.StackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formattedMessage;
|
return formattedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string GetLoggerShortName(string logger)
|
||||||
|
{
|
||||||
|
var lastDotIndex = logger.AsSpan().LastIndexOf('.');
|
||||||
|
return lastDotIndex >= 0 ? logger.Substring(lastDotIndex + 1) : logger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class SptLogger<T> : ISptLogger<T>
|
|||||||
|
|
||||||
private const string ConfigurationPath = "./sptLogger.json";
|
private const string ConfigurationPath = "./sptLogger.json";
|
||||||
private const string ConfigurationPathDev = "./sptLogger.Development.json";
|
private const string ConfigurationPathDev = "./sptLogger.Development.json";
|
||||||
private SptLoggerConfiguration _config;
|
private static SptLoggerConfiguration? _config = null;
|
||||||
|
|
||||||
public SptLogger(FileUtil fileUtil, JsonUtil jsonUtil, SptLoggerQueueManager loggerQueueManager)
|
public SptLogger(FileUtil fileUtil, JsonUtil jsonUtil, SptLoggerQueueManager loggerQueueManager)
|
||||||
{
|
{
|
||||||
@@ -27,6 +27,8 @@ public class SptLogger<T> : ISptLogger<T>
|
|||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (_config is null)
|
||||||
|
{
|
||||||
if (!ProgramStatics.DEBUG() || IsReleaseType)
|
if (!ProgramStatics.DEBUG() || IsReleaseType)
|
||||||
{
|
{
|
||||||
LoadConfig(fileUtil, jsonUtil, ConfigurationPath);
|
LoadConfig(fileUtil, jsonUtil, ConfigurationPath);
|
||||||
@@ -35,6 +37,7 @@ public class SptLogger<T> : ISptLogger<T>
|
|||||||
{
|
{
|
||||||
LoadConfig(fileUtil, jsonUtil, ConfigurationPathDev);
|
LoadConfig(fileUtil, jsonUtil, ConfigurationPathDev);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_config == null)
|
if (_config == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Text;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
|
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
|
||||||
@@ -28,7 +29,31 @@ public abstract class BaseSptLoggerReference
|
|||||||
public LogLevel LogLevel { get; set; }
|
public LogLevel LogLevel { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("format")]
|
[JsonPropertyName("format")]
|
||||||
public string Format { get; set; }
|
public required string Format { get; set; }
|
||||||
|
|
||||||
|
private string? _cachedFormat;
|
||||||
|
private CompositeFormat? _compiledFormat;
|
||||||
|
|
||||||
|
public virtual CompositeFormat GetCompiledFormat()
|
||||||
|
{
|
||||||
|
if (_cachedFormat != Format)
|
||||||
|
{
|
||||||
|
var convertedFormat = Format
|
||||||
|
.Replace("%date%", "{0}")
|
||||||
|
.Replace("%time%", "{1}")
|
||||||
|
.Replace("%message%", "{2}")
|
||||||
|
.Replace("%loggerShort%", "{3}")
|
||||||
|
.Replace("%logger%", "{4}")
|
||||||
|
.Replace("%tid%", "{5}")
|
||||||
|
.Replace("%tname%", "{6}")
|
||||||
|
.Replace("%level%", "{7}");
|
||||||
|
|
||||||
|
_compiledFormat = CompositeFormat.Parse(convertedFormat);
|
||||||
|
_cachedFormat = Format;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _compiledFormat!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SptLoggerFilter
|
public class SptLoggerFilter
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"configProperties": {
|
||||||
|
"System.GC.ConserveMemory": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user