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

Homogenize code with ATxCommon.

parent 2eef7120
No related branches found
No related tags found
No related merge requests found
......@@ -30,25 +30,31 @@ namespace ATxDiagnostics
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
*/
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(QueryCpuLoad());
}
private static int QueryCpuLoad() {
Log.Trace("Querying WMI for CPU load...");
var searcher = new ManagementObjectSearcher(
"root\\CIMV2",
"select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor",
new EnumerationOptions {
Timeout = new TimeSpan(0, 0, 10),
ReturnImmediately = false,
}
);
var watch = Stopwatch.StartNew();
var queryString = "SELECT Name, PercentProcessorTime " +
"FROM Win32_PerfFormattedData_PerfOS_Processor";
var opts = new EnumerationOptions {
Timeout = new TimeSpan(0, 0, 10),
ReturnImmediately = false,
};
var searcher = new ManagementObjectSearcher("", queryString, opts);
Int32 usageInt32 = -1;
var managementObjects = searcher.Get();
if (managementObjects.Count == 0) {
Log.Error("No objects returned from WMI!");
watch.Stop();
Log.Debug("WMI query took {0} ms.", watch.ElapsedMilliseconds);
return -1;
}
Log.Trace("WMI query returned {0} objects.", managementObjects.Count);
foreach (var mo in managementObjects) {
var obj = (ManagementObject)mo;
......@@ -58,16 +64,14 @@ namespace ATxDiagnostics
usageInt32 = Convert.ToInt32(usage);
Log.Trace("CPU usage {1}: {0}", usageInt32, name);
//if (name.ToString().Equals("_Total")) {
// usageInt32 = Convert.ToInt32(usage);
// Log.Trace("CPU usage: {0}", usageInt32);
//}
}
managementObjects.Dispose();
searcher.Dispose();
watch.Stop();
Log.Debug("WMI query took {0} ms.", watch.ElapsedMilliseconds);
return usageInt32;
}
}
......
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