Exemplo n.º 1
0
        /// <summary>
        /// On timer elapse handler.
        /// </summary>
        /// <remarks>
        /// The main idea of this handler is to get GPU load values in order to
        /// make decision on restart supervised app. First we get all GPU load
        /// valuers and show them to user. After we calculate lowest one and if
        /// calculated value lowerer than the theshold supervised app restarts.
        /// We have 5 attempts.
        /// </remarks>
        private void OnElapse()
        {
            var hasInet = utilMgr.IsOnline();

            Output.Write(hasInet ? "Internet ok; " : "No internrt; ", ConsoleColor.Cyan);

            var gpus = computer.Hardware.Where(x => x.HardwareType == HardwareType.GpuNvidia || x.HardwareType == HardwareType.GpuAti);

            foreach (var gpu in gpus)
            {
                gpu.Update();
                var load = gpu.Sensors.FirstOrDefault(x => x.SensorType == SensorType.Load);
                var tmpr = gpu.Sensors.FirstOrDefault(x => x.SensorType == SensorType.Temperature);
                Output.Write($"gpu{Regex.Match(gpu.Identifier.ToString(), @"\d+").Value}(ld={load?.Value}%, t={tmpr?.Value} C);  ", ConsoleColor.Cyan);
            }
            Output.WriteLine();

            var minLoad = computer.Hardware.Min(x => x.Sensors.FirstOrDefault(y => y.SensorType == SensorType.Load)?.Value);

            if (minLoad < args.GpuLoadThreshold)
            {
                Output.WriteLine($"GPU LOAD {minLoad}%, THERESHOLD {args.GpuLoadThreshold}! RESTART MINER IN {--iteration}", ConsoleColor.Red);
            }
            else if (hasInet)
            {
                iteration = MaxItertions;
            }

            if (!hasInet)
            {
                Output.WriteLine($"NO INTERNET CONNECTION! RESTART MINER IN {--iteration}", ConsoleColor.Red);
            }
            else if (minLoad > args.GpuLoadThreshold)
            {
                iteration = MaxItertions;
            }

            if (iteration > 0)
            {
                return;
            }

            timer.Enabled = false;

            Output.Write("RESTARTING MINER...", ConsoleColor.Yellow);
            utilMgr.RestartProcess(supervisedProcess);
            Output.WriteLine(" OK!", ConsoleColor.Green);

            timer.Enabled = true;
            iteration     = MaxItertions;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Here is the behaviour logic depending on internet GPU load status.
        /// </summary>
        private void LoadActions()
        {
            if (isStopped)
            {
                return;
            }

            var gpus    = computer.Hardware.Where(x => x.HardwareType == HardwareType.GpuNvidia || x.HardwareType == HardwareType.GpuAti);
            var minLoad = Single.MaxValue;

            foreach (var gpu in gpus)
            {
                gpu.Update();
                var load = Single.NaN;
                var tmpr = Single.NaN;
                foreach (var sensor in gpu.Sensors)
                {
                    if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                    {
                        if (sensor.Value != null)
                        {
                            load = sensor.Value.Value;
                        }
                    }
                    if (sensor.SensorType == SensorType.Temperature && sensor.Name == "GPU Core")
                    {
                        if (sensor.Value != null)
                        {
                            tmpr = sensor.Value.Value;
                        }
                    }
                    if (load < minLoad)
                    {
                        minLoad = load;
                    }
                }
                Output.Write($"gpu{Regex.Match(gpu.Identifier.ToString(), @"\d+").Value}(ld={load}%, t={tmpr} C);  ", ConsoleColor.Cyan);
            }
            Output.WriteLine();

            if (minLoad < args.GpuLoadThreshold)
            {
                Output.WriteLine(args.Restart
                        ? $"GPU LOAD {minLoad}%, THRESHOLD {args.GpuLoadThreshold}! RESTART PC IN {--gpuLoadIterations}"
                        : $"GPU LOAD {minLoad}%, THRESHOLD {args.GpuLoadThreshold}! RESTART MINER IN {--gpuLoadIterations}",
                                 ConsoleColor.Red);
            }

            else
            {
                gpuLoadIterations = MaxItertions;
            }

            if (gpuLoadIterations > 0)
            {
                return;
            }

            if (args.Restart)
            {
                Output.Write("RESTARTING PC IN 5 SECONDS", ConsoleColor.Yellow);
                utilMgr.RestartPc();
            }
            Output.Write("RESTARTING MINER...", ConsoleColor.Yellow);
            utilMgr.RestartProcess(supervisedProcess);
            Output.WriteLine(" OK!", ConsoleColor.Yellow);
            gpuLoadIterations = MaxItertions;
        }