From 59cd92cb98e91b06fb682f79b4cc04a49e367582 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Sun, 11 Mar 2018 14:35:56 +0100
Subject: [PATCH] Add System.Diagnostics based function for getting the CPU
 load.

---
 ATxDiagnostics/ATxDiagnostics.cs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/ATxDiagnostics/ATxDiagnostics.cs b/ATxDiagnostics/ATxDiagnostics.cs
index a03d5af..90c7231 100644
--- a/ATxDiagnostics/ATxDiagnostics.cs
+++ b/ATxDiagnostics/ATxDiagnostics.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Diagnostics;
 using System.Management;
 using ATxCommon;
 using NLog;
@@ -24,6 +25,7 @@ namespace ATxDiagnostics
             LogManager.Configuration = logConfig;
 
             Log.Debug(Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:")));
+            GetCpuCounter();
             /*
             Log.Debug(SystemChecks.GetCpuUsage());
             Log.Debug(SystemChecks.GetCpuUsage());
@@ -74,5 +76,19 @@ namespace ATxDiagnostics
 
             return usageInt32;
         }
+
+        private static void GetCpuCounter() {
+            var counter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
+            var i = 0;
+            while (true) {
+                i++;
+                //Log.Debug("PerformanceCounter reading {1}: {0}", counter.NextValue(), i);
+                var watch = Stopwatch.StartNew();
+                var reading = counter.NextValue();
+                watch.Stop();
+                Console.WriteLine("reading {1} (took {2} ms): {0}", reading, i, watch.ElapsedMilliseconds);
+                System.Threading.Thread.Sleep(250);
+            }
+        }
     }
 }
-- 
GitLab