Skip to content

Commit

Permalink
SNOW-1814669 fix logging diagnostic info (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko authored Nov 25, 2024
1 parent 296a281 commit d212fc7
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions Snowflake.Data/Core/Tools/Diagnostics.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
Expand All @@ -18,33 +17,40 @@ internal class Diagnostics
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");
try
{
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");
}
catch (Exception exception)
{
var errorMessage = $"Error caught while collecting diagnostic info: {exception.Message}";
s_logger.Error(errorMessage, exception);
info.AppendLine(errorMessage);
}
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}");
info.AppendLine($"{assemblyTag + "Name",PadRight}: {assembly.GetName().Name}");
info.AppendLine($"{assemblyTag + "Version",PadRight}: {assembly.GetName().Version}");
}
}

Expand Down

0 comments on commit d212fc7

Please sign in to comment.