Skip to content
Snippets Groups Projects
Commit 59cd92cb authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Add System.Diagnostics based function for getting the CPU load.

parent 149cc59b
No related branches found
No related tags found
No related merge requests found
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);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment