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

Working prototype for monitoring the CPU load in a separate thread.

parent 41e13f05
Branches
No related tags found
No related merge requests found
......@@ -379,13 +379,13 @@ namespace ATxService
private void UpdateCpuLoad(object sender, ElapsedEventArgs elapsedEventArgs) {
_loadTimer.Enabled = false;
try {
Log.Debug("UpdateCpuLoad()");
Log.Debug(_cpuLoadLastReadings.Average());
Log.Trace("UpdateCpuLoad(), old values: {0}, average: {1}",
string.Join(", ", _cpuLoadLastReadings), _cpuLoadLastReadings.Average());
Array.ConstrainedCopy(_cpuLoadLastReadings, 1, _cpuLoadLastReadings, 0, 3);
// var counter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
_cpuLoadLastReadings[3] = CpuCounter.NextValue();
Log.Debug(_cpuLoadLastReadings.Average());
Log.Debug("UpdateCpuLoad() finished");
_cpuLoad = _cpuLoadLastReadings.Average();
Log.Trace("UpdateCpuLoad(), new values: {0}, average: {1}",
string.Join(", ", _cpuLoadLastReadings), _cpuLoadLastReadings.Average());
}
catch (Exception ex) {
Log.Error("UpdateCpuLoad failed: {0}", ex.Message);
......@@ -406,7 +406,7 @@ namespace ATxService
_mainTimer.Elapsed += OnTimedEvent;
_mainTimer.Enabled = true;
_loadTimer = new Timer(1000);
_loadTimer = new Timer(250);
_loadTimer.Elapsed += UpdateCpuLoad;
_loadTimer.Enabled = true;
}
......@@ -499,6 +499,8 @@ namespace ATxService
// while this method has not finished yet:
_mainTimer.Enabled = false;
Log.Debug("Current CPU load: {0}", _cpuLoad);
try {
RunMainTasks();
GC.Collect();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment