Beispiel #1
0
        public void Example1()
        {
            var stats = new SimpleAverage();

            stats.Add(4);
            stats.Add(7);
            stats.Add(13);
            stats.Add(16);
            Assert.Equal(4, stats.Count);
            Assert.Equal(10, stats.Average, 15);
        }
Beispiel #2
0
        public void Example4()
        {
            var stats = new SimpleAverage();

            stats.Add(6);
            stats.Add(2);
            stats.Add(3);
            stats.Add(1);
            Assert.Equal(4, stats.Count);
            Assert.Equal(3, stats.Average, 15);
        }
Beispiel #3
0
        public void NoInfinity()
        {
            var stats = new SimpleAverage();

            Assert.Throws <ArgumentOutOfRangeException>(delegate {
                stats.Add(double.NegativeInfinity);
            });
            Assert.Throws <ArgumentOutOfRangeException>(delegate {
                stats.Add(double.PositiveInfinity);
            });
            Assert.Throws <ArgumentOutOfRangeException>(delegate {
                stats.Add(double.NaN);
            });
        }
Beispiel #4
0
        public void OneValue()
        {
            var stats = new SimpleAverage();

            stats.Add(1);
            Assert.Equal(1, stats.Count);
            Assert.Equal(1, stats.Average);
        }
        private void TimerOnElapsed(object sender, ElapsedEventArgs e)
        {
            _timerStopwatch.Restart();

            var sensors = UpdateSensors();

            if (sensors.Count == 0)
            {
                ScheduleTimer();
                return;
            }

            var coreFrequencies = _cpuVendor == Vendor.AMD
                ? sensors.Where(s => s.Identifier.ToString().Contains("clock") && s.Name.Contains("Core"))
                : sensors.Where(s => s.Identifier.ToString().Contains("clock") && s.Name.Contains("CPU"));
            var clockAvg = 0.0f;

            foreach (var sensor in coreFrequencies)
            {
                var value = sensor.Value;

                if (!value.HasValue)
                {
                    continue;
                }

                var freq = value.Value;
                if (freq < _clockMin)
                {
                    _clockMin = freq;
                }

                if (freq > _clockMax)
                {
                    _clockMax = freq;
                }
                clockAvg = _clockAverage.Add(value.Value);
            }
            var   coreUtil    = sensors.FirstOrDefault(s => s.Identifier.ToString().Contains("load") && s.Name.Contains("Total"))?.Value;
            float?utilAverage = null;

            if (coreUtil != null)
            {
                utilAverage = _utilAverage.Add(coreUtil.Value);
            }
            var pkgTemp = _cpuVendor == Vendor.AMD
                ? sensors.FirstOrDefault(s => s.Identifier.ToString().Contains("temperature") && (s.Name.Contains("Core #1 - ") || s.Name.Contains("Tdie")))?.Value
                : sensors.FirstOrDefault(s => s.Identifier.ToString().Contains("temperature") && s.Name.Contains("Package"))?.Value;
            float?tempAverage = null;

            if (pkgTemp != null)
            {
                tempAverage = _tempAverage.Add(pkgTemp.Value);
            }

            if (DateTime.Now - _lastGraphUpdate < TimeSpan.FromMilliseconds(_screenUpdateResolution))
            {
                ScheduleTimer();
                return;
            }

            if (_lastGraphUpdate > DateTime.MinValue && DateTime.Now - _lastGraphUpdate > TimeSpan.FromSeconds(5))
            {
                _lastGraphUpdate = DateTime.MinValue;
                ScheduleTimer();
                return;
            }

            _lastGraphUpdate = DateTime.Now;

            var powers = sensors.Where(s => s.Identifier.ToString().Contains("power")).ToList();

            var pkgPower   = powers.FirstOrDefault(s => s.Name.Contains("Package"))?.Value;
            var powerLimit = sensors.FirstOrDefault(s => s.Identifier.ToString().Contains("power") && s.Name.Contains("PL1"))?.Value;
            var corePower  = _cpuVendor == Vendor.AMD
                ? powers.Where(s => s.Name.Contains("Core")).Select(s => s.Value ?? 0.0f).Sum()
                : powers.FirstOrDefault(s => s.Name.Contains("Core"))?.Value;
            var dramPower = powers.FirstOrDefault(s => s.Name.Contains("Memory"))?.Value;

            Dispatcher?.Invoke(() =>
            {
                UpdateUi(clockAvg, pkgPower, corePower, dramPower, tempAverage, utilAverage);

                _powerLimitGraph.Update(powerLimit, _pkgPowerGraph, pkgPower);
                _pkgPowerGraph.Update(pkgPower);
                _corePowerGraph.Update(corePower);
                _dramPowerGraph.Update(dramPower);
                _avgFreqGraph.Update(clockAvg / 1000);
                _minFreqGraph.Update(_clockMin / 1000);
                _maxFreqGraph.Update(_clockMax / 1000);
                _pkgTempGraph.Update(tempAverage);
                _coreUtilGraph.Update(utilAverage);
            });

            _clockMin = float.MaxValue;
            _clockMax = float.MinValue;
            _clockAverage.Reset();
            _utilAverage.Reset();
            _tempAverage.Reset();

            ScheduleTimer();
        }