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

Remove unused method GetCpuUsage.

parent 4ebb8ee0
Branches bug-cpuload
No related tags found
No related merge requests found
......@@ -32,77 +32,6 @@ namespace ATxCommon
return -1;
}
/// <summary>
/// Get the CPU usage in percent over all cores.
/// </summary>
/// <returns>CPU usage in percent or -1 if an error occured.</returns>
public static int GetCpuUsage() {
// TODO: fix bug #36
return 0;
try {
Log.Trace("Querying WMI for CPU load...");
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.Debug("WMI query returned {0} objects.", managementObjects.Count);
foreach (var mo in managementObjects) {
var obj = (ManagementObject)mo;
var usage = obj["PercentProcessorTime"];
var name = obj["Name"];
usageInt32 = Convert.ToInt32(usage);
Log.Debug("CPU usage {1}: {0}", usageInt32, name);
}
watch.Stop();
Log.Debug("WMI query took {0} ms.", watch.ElapsedMilliseconds);
return usageInt32;
/*
var cpuTimes = searcher.Get()
.Cast<ManagementObject>()
.Select(mo => new {
Name = mo["Name"],
Usage = mo["PercentProcessorTime"]
}
)
.ToList();
if (cpuTimes.Count == 0)
return -1;
Log.Trace("WMI query returned {0} objects.", cpuTimes.Count);
// The '_Total' value represents the average usage across all cores,
// and is the best representation of overall CPU usage
var query = cpuTimes.Where(x => x.Name.ToString() == "_Total").Select(x => x.Usage);
var cpuUsage = query.SingleOrDefault();
usageInt32 = Convert.ToInt32(cpuUsage);
Log.Trace("CPU usage: {0}", usageInt32);
return usageInt32;
*/
}
catch (Exception ex) {
Log.Trace("Error in GetCpuUsage: {0}", ex.Message);
}
Log.Trace("Failed querying CPU usage!");
return -1;
}
/// <summary>
/// Get the free space of a drive in bytes.
/// </summary>
......
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