Skip to content

Commit

Permalink
SNOW-1629635 added system diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman committed Sep 11, 2024
1 parent 31e3a0c commit bc32fe5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Snowflake.Data/Client/SnowflakeDbConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ internal static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolTy
{
if (s_connectionManager != null)
return;
SystemDiagnostics.LogDiagnostics();
s_connectionManager?.ClearAllPools();
if (requestedPoolType == ConnectionPoolType.MultipleConnectionPool)
{
Expand Down
63 changes: 63 additions & 0 deletions Snowflake.Data/Core/Tools/Diagnostics.cs
Original file line number Diff line number Diff line change
@@ -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<SnowflakeDbConnectionPool>();

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";
}
}
}

0 comments on commit bc32fe5

Please sign in to comment.