From 1903956b859c6360289e8ce3865ba64b06be29dd Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Tue, 1 Dec 2020 22:34:25 +1300 Subject: [PATCH] Fixed LogReporter Fixed LogReporter error introduced by my earlier modifications of HeliosPlus due to ProfileItem object changes. This messed up the LogReporter writing logic which in turn made log files balloon to multiple GB in size! Also added capture of the various JSON files that are used to store settings so that we can help fix JSON errors. --- .../App.config | 0 .../FodyWeavers.xml | 0 .../FodyWeavers.xsd | 0 .../HeliosPlus.LogReporter.csproj | 3 +- .../HeliosPlus.ico | Bin .../Program.cs | 138 +++++++++++++----- .../Properties/AssemblyInfo.cs | 0 7 files changed, 105 insertions(+), 36 deletions(-) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/App.config (100%) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/FodyWeavers.xml (100%) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/FodyWeavers.xsd (100%) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/HeliosPlus.LogReporter.csproj (97%) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/HeliosPlus.ico (100%) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/Program.cs (64%) rename {HeliosPlus.Reporting => HeliosPlus.LogReporter}/Properties/AssemblyInfo.cs (100%) diff --git a/HeliosPlus.Reporting/App.config b/HeliosPlus.LogReporter/App.config similarity index 100% rename from HeliosPlus.Reporting/App.config rename to HeliosPlus.LogReporter/App.config diff --git a/HeliosPlus.Reporting/FodyWeavers.xml b/HeliosPlus.LogReporter/FodyWeavers.xml similarity index 100% rename from HeliosPlus.Reporting/FodyWeavers.xml rename to HeliosPlus.LogReporter/FodyWeavers.xml diff --git a/HeliosPlus.Reporting/FodyWeavers.xsd b/HeliosPlus.LogReporter/FodyWeavers.xsd similarity index 100% rename from HeliosPlus.Reporting/FodyWeavers.xsd rename to HeliosPlus.LogReporter/FodyWeavers.xsd diff --git a/HeliosPlus.Reporting/HeliosPlus.LogReporter.csproj b/HeliosPlus.LogReporter/HeliosPlus.LogReporter.csproj similarity index 97% rename from HeliosPlus.Reporting/HeliosPlus.LogReporter.csproj rename to HeliosPlus.LogReporter/HeliosPlus.LogReporter.csproj index 2836785..3c884da 100644 --- a/HeliosPlus.Reporting/HeliosPlus.LogReporter.csproj +++ b/HeliosPlus.LogReporter/HeliosPlus.LogReporter.csproj @@ -8,7 +8,7 @@ AnyCPU {76DF2BCF-911B-4820-B63E-8F3468DB5E79} Exe - HeliosPlus.Reporting + HeliosPlus.LogReporter HeliosPlus.LogReporter v4.8 512 @@ -42,6 +42,7 @@ prompt 4 true + false AnyCPU diff --git a/HeliosPlus.Reporting/HeliosPlus.ico b/HeliosPlus.LogReporter/HeliosPlus.ico similarity index 100% rename from HeliosPlus.Reporting/HeliosPlus.ico rename to HeliosPlus.LogReporter/HeliosPlus.ico diff --git a/HeliosPlus.Reporting/Program.cs b/HeliosPlus.LogReporter/Program.cs similarity index 64% rename from HeliosPlus.Reporting/Program.cs rename to HeliosPlus.LogReporter/Program.cs index 1cf9cf2..21753a0 100644 --- a/HeliosPlus.Reporting/Program.cs +++ b/HeliosPlus.LogReporter/Program.cs @@ -11,20 +11,20 @@ using HeliosPlus.Shared; using NvAPIWrapper.GPU; using NvAPIWrapper.Mosaic; -namespace HeliosPlus.Reporting +namespace HeliosPlus.LogReporter { internal class Program { private static StreamWriter _writer; internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); - private static void Dump( + private static void DumpObject( IEnumerable items, string title, Tuple, string>[] actions = null, int deepIn = 0) { - Console.WriteLine(title); + Console.Write($"- {title}..."); _writer.WriteLine(title + new string('=', Console.BufferWidth - title.Length)); var totalTime = TimeSpan.Zero; var stopWatch = new Stopwatch(); @@ -43,21 +43,68 @@ namespace HeliosPlus.Reporting stopWatch.Stop(); totalTime += stopWatch.Elapsed; - Console.Write(@"-- Elapsed: {0}", totalTime); + Console.WriteLine(@"(Took {0} to complete)", totalTime); _writer.WriteLine(@"-- Total Elapsed: {0}", totalTime); - Console.WriteLine(); _writer.WriteLine(); + _writer.WriteLine(new string('#', Console.BufferWidth)); + _writer.WriteLine(); + } + + private static void IngestFile(string fileName, string title) + { + + Console.Write($"- {title}..."); + _writer.WriteLine(new string('=', Console.BufferWidth)); + _writer.WriteLine(title + new string('=', Console.BufferWidth - title.Length)); + _writer.WriteLine(new string('=', Console.BufferWidth)); + var totalTime = TimeSpan.Zero; + var stopWatch = new Stopwatch(); + + if (File.Exists(fileName)) + { + stopWatch.Start(); + + StreamReader reader = new StreamReader(fileName); + string fileContents = reader.ReadToEnd(); + _writer.WriteLine(fileContents); + + stopWatch.Stop(); + totalTime += stopWatch.Elapsed; + Console.WriteLine(@"(Took {0} to complete)", totalTime); + _writer.WriteLine(@"-- Total Elapsed: {0}", totalTime); + _writer.WriteLine(); + _writer.WriteLine(new string('#', Console.BufferWidth)); + _writer.WriteLine(); + + } + else + { + + } + + } private static void Main(string[] args) { + Console.WriteLine("HeliosPlus LogReporter"); + Console.WriteLine("======================"); + Console.WriteLine(); + Console.WriteLine("This program will interrogate your HeliosPlus configuration settings, the Windows Display "); + Console.WriteLine("Subsystem and any NVIDIA Display Drivers to record what they can detect and report. This"); + Console.WriteLine("recorded information is then stored in a log file. If you report a problem then you may be"); + Console.WriteLine("asked to send us the log file generated by this program in order for us to help you."); + Console.WriteLine(); + Console.WriteLine("Starting the interrogation..."); + Console.WriteLine(); + string date = DateTime.Now.ToString("yyyyMMdd.HHmmss"); _writer = new StreamWriter(new FileStream( - string.Format("HeliosPlus.Reporting.{0}.log", Process.GetCurrentProcess().Id), + string.Format("HeliosPlus.Reporting.{0}.log", date), FileMode.CreateNew)); try { - Dump(DisplayAdapter.GetDisplayAdapters(), "WindowsDisplayAPI.DisplayAdapter.GetDisplayAdapters()"); + IngestFile(Path.Combine(AppDataPath, "Settings_1.0.json"), "Storing HeliosPlus Settings JSON File"); } catch (Exception e) { @@ -66,7 +113,35 @@ namespace HeliosPlus.Reporting try { - Dump(Display.GetDisplays(), "WindowsDisplayAPI.Display.GetDisplays()", new[] + IngestFile(Path.Combine(AppDataPath, "Profiles", "DisplayProfiles_1.0.json"), "Storing HeliosPlus Display Profiles JSON File"); + } + catch (Exception e) + { + WriteException(e); + } + + try + { + IngestFile(Path.Combine(AppDataPath, "Shortcuts", "Shortcuts_1.0.json"), "Storing HeliosPlus Shortcuts JSON File"); + } + catch (Exception e) + { + WriteException(e); + } + + + try + { + DumpObject(DisplayAdapter.GetDisplayAdapters(), "Storing a list of Display Adapters currently in this computer"); + } + catch (Exception e) + { + WriteException(e); + } + + try + { + DumpObject(Display.GetDisplays(), "Storing a list of possible settings for Displays currently connected to this computer", new[] { new Tuple, string>(display => display.GetPossibleSettings(), "GetPossibleSettings()") @@ -79,8 +154,8 @@ namespace HeliosPlus.Reporting try { - Dump(UnAttachedDisplay.GetUnAttachedDisplays(), - "WindowsDisplayAPI.UnAttachedDisplay.GetUnAttachedDisplays()"); + DumpObject(UnAttachedDisplay.GetUnAttachedDisplays(), + "Storing a list of Displays not currently in use, but currently connected to this computer"); } catch (Exception e) { @@ -89,8 +164,8 @@ namespace HeliosPlus.Reporting try { - Dump(PathDisplayAdapter.GetAdapters(), - "WindowsDisplayAPI.DisplayConfig.PathDisplayAdapter.GetAdapters()", + DumpObject(PathDisplayAdapter.GetAdapters(), + "Storing a list of Displays Targets for all Display Adapters currently in this computer", new[] { new Tuple, string>(adapter => adapter.ToDisplayAdapter(), @@ -104,8 +179,8 @@ namespace HeliosPlus.Reporting try { - Dump(PathDisplaySource.GetDisplaySources(), - "WindowsDisplayAPI.DisplayConfig.PathDisplaySource.GetDisplaySources()", new[] + DumpObject(PathDisplaySource.GetDisplaySources(), + "Storing a list of Display Sources for Displays currently connected to this computer", new[] { new Tuple, string>(source => source.ToDisplayDevices(), "ToDisplayDevices()") @@ -118,8 +193,8 @@ namespace HeliosPlus.Reporting try { - Dump(PathDisplayTarget.GetDisplayTargets(), - "WindowsDisplayAPI.DisplayConfig.PathDisplayTarget.GetDisplayTargets()", new[] + DumpObject(PathDisplayTarget.GetDisplayTargets(), + "Storing a list of Displays Targets for Displays currently connected to this computer", new[] { new Tuple, string>(target => target.ToDisplayDevice(), "ToDisplayDevice()") @@ -134,7 +209,7 @@ namespace HeliosPlus.Reporting { if (PathInfo.IsSupported) { - Dump(PathInfo.GetActivePaths(), "WindowsDisplayAPI.DisplayConfig.PathInfo.GetActivePaths()", null, + DumpObject(PathInfo.GetActivePaths(), "Storing a list of Active Displays currently connected to this computer", null, 2); } } @@ -145,7 +220,7 @@ namespace HeliosPlus.Reporting try { - Dump(LogicalGPU.GetLogicalGPUs(), "NvAPIWrapper.GPU.LogicalGPU.GetLogicalGPUs()", null, 1); + DumpObject(LogicalGPU.GetLogicalGPUs(), "Storing a list of logical NVIDIA GPUs formed by NVIDIA GPUs currently in this computer (e.g. SLI)", null, 1); } catch (Exception e) { @@ -154,7 +229,7 @@ namespace HeliosPlus.Reporting try { - Dump(PhysicalGPU.GetPhysicalGPUs(), "NvAPIWrapper.GPU.PhysicalGPU.GetPhysicalGPUs()"); + DumpObject(PhysicalGPU.GetPhysicalGPUs(), "Storing a list of physical NVIDIA GPUs currently in this computer"); } catch (Exception e) { @@ -163,7 +238,7 @@ namespace HeliosPlus.Reporting try { - Dump(NvAPIWrapper.Display.Display.GetDisplays(), "NvAPIWrapper.Display.Display.GetDisplays()", new[] + DumpObject(NvAPIWrapper.Display.Display.GetDisplays(), "Storing a list of Displays currently connected to this computer through a NVIDIA GPU", new[] { new Tuple, string>( display => display.GetSupportedViews(), @@ -177,8 +252,8 @@ namespace HeliosPlus.Reporting try { - Dump(NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays(), - "NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays()"); + DumpObject(NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays(), + "Storing a list of Displays currently connected to this computer through a NVIDIA GPU but not active"); } catch (Exception e) { @@ -187,8 +262,8 @@ namespace HeliosPlus.Reporting try { - Dump(NvAPIWrapper.Display.PathInfo.GetDisplaysConfig(), - "NvAPIWrapper.Display.PathInfo.GetDisplaysConfig()", + DumpObject(NvAPIWrapper.Display.PathInfo.GetDisplaysConfig(), + "Storing a list of configuration of Displays currently connected to this computer through a NVIDIA GPU", null, 3); } catch (Exception e) @@ -198,17 +273,7 @@ namespace HeliosPlus.Reporting try { - Dump(GridTopology.GetGridTopologies(), "NvAPIWrapper.Mosaic.GridTopology.GetGridTopologies()", null, 3); - } - catch (Exception e) - { - WriteException(e); - } - - - try - { - Dump(ProfileRepository.AllProfiles, "HeliosPlus.Shared.ProfileRepository.AllProfiles", null, 99); + DumpObject(GridTopology.GetGridTopologies(), "Storing a list of configured NZIVIDA Surround/Mosaic settings involving multiple Displays via a NVIDIA GPU", null, 3); } catch (Exception e) { @@ -219,12 +284,15 @@ namespace HeliosPlus.Reporting _writer.Close(); _writer.Dispose(); + Console.WriteLine(new string('=', Console.BufferWidth)); + Console.WriteLine(); Console.WriteLine(@"Done, press enter to exit."); Console.ReadLine(); } private static void WriteException(Exception ex) { + Console.WriteLine("{0} - Error: {1}", ex.GetType().Name, ex.Message); _writer.WriteLine("{0} - Error: {1}", ex.GetType().Name, ex.Message); } diff --git a/HeliosPlus.Reporting/Properties/AssemblyInfo.cs b/HeliosPlus.LogReporter/Properties/AssemblyInfo.cs similarity index 100% rename from HeliosPlus.Reporting/Properties/AssemblyInfo.cs rename to HeliosPlus.LogReporter/Properties/AssemblyInfo.cs