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

Clean local PerformanceCounter stuff from ATxService.

parent 16815f4a
No related branches found
No related tags found
No related merge requests found
......@@ -44,9 +44,6 @@ namespace ATxService
private long _txCurFileSize;
private int _txCurFileProgress;
private int _waitCyclesBeforeNextTx;
public PerformanceCounter CpuCounter;
private float _cpuLoad;
private readonly float[] _cpuLoadLastReadings = {0F, 0F, 0F, 0F};
private Cpu _cpu;
private DateTime _lastUserDirCheck = DateTime.MinValue;
......@@ -77,7 +74,6 @@ namespace ATxService
private ServiceStatus _status;
private static Timer _mainTimer;
private static Timer _loadTimer;
#endregion
......@@ -92,12 +88,6 @@ namespace ATxService
SetupFileLogging();
Log.Info("=".PadLeft(80, '='));
Log.Info("Attempting to start {0} service...", ServiceName);
try {
CpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
}
catch (Exception ex) {
Log.Error("initializing PerformanceCounter failed: {0}", ex.Message);
}
CreateEventLog();
LoadSettings();
CreateIncomingDirectories();
......@@ -378,24 +368,6 @@ namespace ATxService
#endregion
private void UpdateCpuLoad(object sender, ElapsedEventArgs elapsedEventArgs) {
_loadTimer.Enabled = false;
try {
Log.Trace("UpdateCpuLoad(), old values: {0}, average: {1}",
string.Join(", ", _cpuLoadLastReadings), _cpuLoadLastReadings.Average());
Array.ConstrainedCopy(_cpuLoadLastReadings, 1, _cpuLoadLastReadings, 0, 3);
_cpuLoadLastReadings[3] = CpuCounter.NextValue();
_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);
}
finally {
_loadTimer.Enabled = true;
}
}
#region overrides for ServiceBase methods (start, stop, ...)
......@@ -408,9 +380,6 @@ namespace ATxService
_mainTimer.Elapsed += OnTimedEvent;
_mainTimer.Enabled = true;
_loadTimer = new Timer(250);
_loadTimer.Elapsed += UpdateCpuLoad;
_loadTimer.Enabled = true;
_cpu = new Cpu();
}
......@@ -503,7 +472,7 @@ namespace ATxService
// while this method has not finished yet:
_mainTimer.Enabled = false;
Log.Debug("CPU load: {0:#} / {1:#} ({2:#.##})", _cpuLoad, _cpu.Load(), _cpuLoad - _cpu.Load());
Log.Debug("CPU load: {0:#.##}", _cpu.Load());
try {
RunMainTasks();
......
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