diff --git a/Snowflake.Data/Client/SnowflakeDbConnectionPool.cs b/Snowflake.Data/Client/SnowflakeDbConnectionPool.cs index a5ab65f63..6a546294c 100644 --- a/Snowflake.Data/Client/SnowflakeDbConnectionPool.cs +++ b/Snowflake.Data/Client/SnowflakeDbConnectionPool.cs @@ -132,6 +132,7 @@ internal static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolTy { if (s_connectionManager != null) return; + SystemDiagnostics.LogDiagnostics(); s_connectionManager?.ClearAllPools(); if (requestedPoolType == ConnectionPoolType.MultipleConnectionPool) { diff --git a/Snowflake.Data/Core/Tools/Diagnostics.cs b/Snowflake.Data/Core/Tools/Diagnostics.cs new file mode 100644 index 000000000..129d62892 --- /dev/null +++ b/Snowflake.Data/Core/Tools/Diagnostics.cs @@ -0,0 +1,63 @@ +using System; +using System.Diagnostics; +using System.Reflection; +using System.Runtime; +using System.Runtime.InteropServices; +using System.Text; +using Snowflake.Data.Client; +using Snowflake.Data.Log; + +namespace Snowflake.Data.Core.Tools +{ + internal class SystemDiagnostics + { + private const int padRight = -25; + private static SFLogger s_Logger = SFLoggerFactory.GetLogger(); + + public static void LogDiagnostics() => s_Logger.Info(GetDiagnosticInfo()); + + private static string GetDiagnosticInfo() + { + StringBuilder info = new StringBuilder("System Diagnostics:\n"); + info.AppendLine($"{"OS", padRight}: {OsName()}"); + info.AppendLine($"{"OS Description", padRight}: {RuntimeInformation.OSDescription}"); + info.AppendLine($"{"OS Architecture", padRight}: {RuntimeInformation.OSArchitecture}"); + info.AppendLine($"{"OS Version", padRight}: {Environment.OSVersion}"); + info.AppendLine($"{"OS x64", padRight}: {Environment.Is64BitOperatingSystem}"); + info.AppendLine($"{"Processor Architecture", padRight}: {RuntimeInformation.ProcessArchitecture}"); + info.AppendLine($"{"Processor Count", padRight}: {Environment.ProcessorCount}"); + info.AppendLine($"{".NET Framework", padRight}: {RuntimeInformation.FrameworkDescription}"); + info.AppendLine($"{"CLR Runtime Version", padRight}: {Environment.Version}"); + info.AppendLine($"{"App x64", padRight}: {Environment.Is64BitProcess}"); + info.AppendLine($"{"GC Server Mode", padRight}: {GCSettings.IsServerGC}"); + info.AppendLine($"{"GC LOH Compaction Mode", padRight}: {GCSettings.LargeObjectHeapCompactionMode}"); + info.AppendLine($"{"GC Latency Mode", padRight}: {GCSettings.LatencyMode}"); + info.AppendLine($"{"GC Total Memory", padRight}: {GC.GetTotalMemory(false)}"); + AppendAssemblyInfo(info, Assembly.GetEntryAssembly(), "App"); + AppendAssemblyInfo(info, Assembly.GetExecutingAssembly(), "Driver"); + return info.ToString(); + } + + private static void AppendAssemblyInfo(StringBuilder info, Assembly assembly, string assemblyTag) + { + if (assembly != null) + { + var assemblyVersion = FileVersionInfo.GetVersionInfo(assembly.Location); + info.AppendLine($"{assemblyTag + " Name", padRight}: {assemblyVersion.InternalName}"); + info.AppendLine($"{assemblyTag + " File", padRight}: {assemblyVersion.FileName}"); + info.AppendLine($"{assemblyTag + " Version", padRight}: {assemblyVersion.FileVersion}"); + } + } + + private static string OsName() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return "UNIX"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return "WINDOWS"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + return "OSX"; + return "Unknown"; + } + } +}