-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1629635 added system diagnostics
- Loading branch information
1 parent
31e3a0c
commit bc32fe5
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
} |