Exemple #1
0
        public void SetCurrentSpeed(IGpuSpeed gpuSpeed)
        {
            Guid mainCoinId = _root.MinerProfile.CoinId;

            if (_mainCoinId != mainCoinId)
            {
                _mainCoinId = mainCoinId;
                DateTime now = DateTime.Now;
                foreach (var item in _gpuSpeedHistory)
                {
                    item.Value.Clear();
                }
                foreach (var item in _currentGpuSpeed)
                {
                    item.Value.MainCoinSpeed.Value   = 0;
                    item.Value.MainCoinSpeed.SpeedOn = now;
                    item.Value.DualCoinSpeed.Value   = 0;
                    item.Value.DualCoinSpeed.SpeedOn = now;
                }
            }
            if (_currentGpuSpeed.ContainsKey(gpuSpeed.Gpu.Index))
            {
                _currentGpuSpeed[gpuSpeed.Gpu.Index].Update(gpuSpeed);
            }
            if (_gpuSpeedHistory.ContainsKey(gpuSpeed.Gpu.Index))
            {
                _gpuSpeedHistory[gpuSpeed.Gpu.Index].Add(gpuSpeed);
            }
        }
Exemple #2
0
 public static GpuSpeedData ToGpuSpeedData(this IGpuSpeed data)
 {
     return(new GpuSpeedData {
         Index = data.Gpu.Index,
         Name = data.Gpu.Name,
         TotalMemory = data.Gpu.TotalMemory,
         MainCoinSpeed = data.MainCoinSpeed.Value,
         DualCoinSpeed = data.DualCoinSpeed.Value,
         AcceptShare = data.MainCoinSpeed.AcceptShare,
         FoundShare = data.MainCoinSpeed.FoundShare,
         RejectShare = data.MainCoinSpeed.RejectShare,
         IncorrectShare = data.MainCoinSpeed.IncorrectShare,
         FanSpeed = data.Gpu.FanSpeed,
         Temperature = data.Gpu.Temperature,
         MemoryTemperature = data.Gpu.MemoryTemperature,
         PowerUsage = data.Gpu.PowerUsage,
         Cool = data.Gpu.Cool,
         PowerCapacity = data.Gpu.PowerCapacity,
         CoreClockDelta = data.Gpu.CoreClockDelta,
         MemoryClockDelta = data.Gpu.MemoryClockDelta,
         TempLimit = data.Gpu.TempLimit,
         CoreVoltage = data.Gpu.CoreVoltage,
         MemoryVoltage = data.Gpu.MemoryVoltage
     });
 }
Exemple #3
0
        private static void PickGpuSpeed(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string gpuSpeedPattern = kernelOutput.GpuSpeedPattern;

            if (isDual)
            {
                gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern;
            }
            if (string.IsNullOrEmpty(gpuSpeedPattern))
            {
                return;
            }
            var             now      = DateTime.Now;
            bool            hasGpuId = gpuSpeedPattern.Contains("?<gpu>");
            Regex           regex    = new Regex(gpuSpeedPattern);
            MatchCollection matches  = regex.Matches(input);

            if (matches.Count > 0)
            {
                GpusSpeed gpuSpeeds = (GpusSpeed)NTMinerRoot.Instance.GpusSpeed;
                for (int i = 0; i < matches.Count; i++)
                {
                    Match  match        = matches[i];
                    string gpuSpeedText = match.Groups["gpuSpeed"].Value;
                    string gpuSpeedUnit = match.Groups["gpuSpeedUnit"].Value;

                    int gpu = i;
                    if (hasGpuId)
                    {
                        string gpuText = match.Groups["gpu"].Value;
                        if (!int.TryParse(gpuText, out gpu))
                        {
                            gpu = i;
                        }
                    }
                    double gpuSpeed;
                    if (double.TryParse(gpuSpeedText, out gpuSpeed))
                    {
                        double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit);
                        gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now);
                    }
                }
                string totalSpeedPattern = kernelOutput.DualTotalSpeedPattern;
                if (isDual)
                {
                    totalSpeedPattern = kernelOutput.DualTotalSpeedPattern;
                }
                if (string.IsNullOrEmpty(totalSpeedPattern))
                {
                    // 求和分算力
                    IGpuSpeed totalGpuSpeed = gpuSpeeds.First(a => a.Gpu.Index == NTMinerRoot.GpuAllId);
                    double    speed         = isDual? gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.DualCoinSpeed.Value)
                                         : gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.MainCoinSpeed.Value);
                    gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, speed, isDual, now);
                }
            }
        }
Exemple #4
0
 public GpuSpeedViewModel(IGpuSpeed gpuSpeed)
 {
     _gpuSpeed           = gpuSpeed;
     this._mainCoinSpeed = new SpeedViewModel(gpuSpeed.MainCoinSpeed);
     this._dualCoinSpeed = new SpeedViewModel(gpuSpeed.DualCoinSpeed);
     this.OpenChart      = new DelegateCommand(() => {
         SpeedCharts.ShowWindow(this);
     });
 }
        public GpuSpeedViewModel(IGpuSpeed gpuSpeed)
        {
            GpuViewModel gpuVm;

            GpuViewModels.Current.TryGetGpuVm(gpuSpeed.Gpu.Index, out gpuVm);
            _gpuVm = gpuVm;
            this._mainCoinSpeed = new SpeedViewModel(gpuSpeed.MainCoinSpeed);
            this._dualCoinSpeed = new SpeedViewModel(gpuSpeed.DualCoinSpeed);
            this.OpenChart      = new DelegateCommand(() => {
                SpeedCharts.ShowWindow(this);
            });
        }
Exemple #6
0
 internal static IGpuSpeed Clone(this IGpuSpeed gpuSpeed)
 {
     return(new GpuSpeed(gpuSpeed.Gpu, new Speed()
     {
         Value = gpuSpeed.MainCoinSpeed.Value,
         SpeedOn = gpuSpeed.MainCoinSpeed.SpeedOn
     }, new Speed()
     {
         Value = gpuSpeed.DualCoinSpeed.Value,
         SpeedOn = gpuSpeed.DualCoinSpeed.SpeedOn
     }));
 }
Exemple #7
0
        public GpuSpeedViewModel(IGpuSpeed gpuSpeed)
        {
            GpuViewModel gpuVm;

            AppContext.Instance.GpuVms.TryGetGpuVm(gpuSpeed.Gpu.Index, out gpuVm);
            _gpuVm = gpuVm;
            this._mainCoinSpeed = new SpeedViewModel(gpuSpeed.MainCoinSpeed);
            this._dualCoinSpeed = new SpeedViewModel(gpuSpeed.DualCoinSpeed);
            this.OpenChart      = new DelegateCommand(() => {
                VirtualRoot.Execute(new ShowSpeedChartsCommand(this));
            });
        }
Exemple #8
0
        public static SpeedData CreateSpeedData()
        {
            INTMinerRoot root = NTMinerRoot.Instance;
            SpeedData    data = new SpeedData {
                KernelSelfRestartCount = 0,
                IsAutoBoot             = NTMinerRegistry.GetIsAutoBoot(),
                IsAutoStart            = NTMinerRegistry.GetIsAutoStart(),
                Version       = NTMinerRoot.CurrentVersion.ToString(4),
                BootOn        = root.CreatedOn,
                MineStartedOn = null,
                IsMining      = root.IsMining,
                MineWorkId    = root.MinerProfile.MineWork != null?root.MinerProfile.MineWork.GetId() : Guid.Empty,
                                    MinerName           = root.MinerProfile.MinerName,
                                    GpuInfo             = root.GpuSetInfo,
                                    ClientId            = VirtualRoot.Id,
                                    MainCoinCode        = string.Empty,
                                    MainCoinWallet      = string.Empty,
                                    MainCoinTotalShare  = 0,
                                    MainCoinRejectShare = 0,
                                    MainCoinSpeed       = 0,
                                    DualCoinCode        = string.Empty,
                                    DualCoinTotalShare  = 0,
                                    DualCoinRejectShare = 0,
                                    DualCoinSpeed       = 0,
                                    DualCoinPool        = string.Empty,
                                    DualCoinWallet      = string.Empty,
                                    IsDualCoinEnabled   = false,
                                    Kernel                       = string.Empty,
                                    MainCoinPool                 = string.Empty,
                                    OSName                       = Windows.OS.Instance.WindowsEdition,
                                    GpuDriver                    = root.GpuSet.DriverVersion,
                                    GpuType                      = root.GpuSet.GpuType,
                                    OSVirtualMemoryMb            = NTMinerRoot.OSVirtualMemoryMb,
                                    KernelCommandLine            = NTMinerRoot.UserKernelCommandLine,
                                    DiskSpace                    = NTMinerRoot.DiskSpace,
                                    IsAutoRestartKernel          = root.MinerProfile.IsAutoRestartKernel,
                                    IsNoShareRestartKernel       = root.MinerProfile.IsNoShareRestartKernel,
                                    IsPeriodicRestartComputer    = root.MinerProfile.IsPeriodicRestartComputer,
                                    IsPeriodicRestartKernel      = root.MinerProfile.IsPeriodicRestartKernel,
                                    NoShareRestartKernelMinutes  = root.MinerProfile.NoShareRestartKernelMinutes,
                                    PeriodicRestartComputerHours = root.MinerProfile.PeriodicRestartComputerHours,
                                    PeriodicRestartKernelHours   = root.MinerProfile.PeriodicRestartKernelHours,
                                    GpuTable                     = root.GpusSpeed.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => new GpuSpeedData {
                    Index            = a.Gpu.Index,
                    Name             = a.Gpu.Name,
                    TotalMemory      = a.Gpu.TotalMemory,
                    MainCoinSpeed    = a.MainCoinSpeed.Value,
                    DualCoinSpeed    = a.DualCoinSpeed.Value,
                    FanSpeed         = a.Gpu.FanSpeed,
                    Temperature      = a.Gpu.Temperature,
                    PowerUsage       = a.Gpu.PowerUsage,
                    Cool             = a.Gpu.Cool,
                    PowerCapacity    = a.Gpu.PowerCapacity,
                    CoreClockDelta   = a.Gpu.CoreClockDelta,
                    MemoryClockDelta = a.Gpu.MemoryClockDelta,
                    TempLimit        = a.Gpu.TempLimit
                }).ToArray()
            };

            #region 当前选中的币种是什么
            if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out ICoin mainCoin))
            {
                data.MainCoinCode = mainCoin.Code;
                ICoinProfile coinProfile = root.MinerProfile.GetCoinProfile(mainCoin.GetId());
                data.MainCoinWallet = coinProfile.Wallet;
                if (root.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
                {
                    data.MainCoinPool = mainCoinPool.Server;
                    if (mainCoinPool.IsUserMode)
                    {
                        IPoolProfile mainCoinPoolProfile = root.MinerProfile.GetPoolProfile(coinProfile.PoolId);
                        data.MainCoinWallet = mainCoinPoolProfile.UserName;
                    }
                }
                else
                {
                    data.MainCoinPool = string.Empty;
                }
                if (root.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
                {
                    if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
                    {
                        data.Kernel = kernel.GetFullName();
                        ICoinKernelProfile coinKernelProfile = root.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
                        data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                        if (coinKernelProfile.IsDualCoinEnabled)
                        {
                            if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                            {
                                data.DualCoinCode = dualCoin.Code;
                                ICoinProfile dualCoinProfile = root.MinerProfile.GetCoinProfile(dualCoin.GetId());
                                data.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                                if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                                {
                                    data.DualCoinPool = dualCoinPool.Server;
                                    if (dualCoinPool.IsUserMode)
                                    {
                                        IPoolProfile dualCoinPoolProfile = root.MinerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId);
                                        data.DualCoinWallet = dualCoinPoolProfile.UserName;
                                    }
                                }
                                else
                                {
                                    data.DualCoinPool = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (root.IsMining)
            {
                var mineContext = root.CurrentMineContext;
                if (mineContext != null)
                {
                    data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount;
                    data.MineStartedOn          = mineContext.CreatedOn;
                    data.KernelCommandLine      = mineContext.CommandLine;
                }
                // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.CurrentMineContext.MainCoin)
                {
                    _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin;
                    Guid       coinId     = root.CurrentMineContext.MainCoin.GetId();
                    IGpusSpeed gpuSpeeds  = NTMinerRoot.Instance.GpusSpeed;
                    IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                    data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value;
                    ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                    data.MainCoinTotalShare  = share.TotalShareCount;
                    data.MainCoinRejectShare = share.RejectShareCount;
                }
                else
                {
                    _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin;
                }
                if (root.CurrentMineContext is IDualMineContext dualMineContext)
                {
                    // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                    if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin)
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                        Guid       coinId     = dualMineContext.DualCoin.GetId();
                        IGpusSpeed gpuSpeeds  = NTMinerRoot.Instance.GpusSpeed;
                        IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                        data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value;
                        ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                        data.DualCoinTotalShare  = share.TotalShareCount;
                        data.DualCoinRejectShare = share.RejectShareCount;
                    }
                    else
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                    }
                }
            }
            return(data);
        }
        public SpeedCharts()
        {
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }
            this.Vm          = new SpeedChartsViewModel();
            this.DataContext = this.Vm;
            InitializeComponent();
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }
            Guid mainCoinId = NTMinerContext.Instance.MinerProfile.CoinId;

            this.OnLoaded((window) => {
                window.AddEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新算力图界面", LogEnum.DevConsole,
                                                           action: (message) => {
                    UIThread.Execute(() => {
                        if (mainCoinId != NTMinerContext.Instance.MinerProfile.CoinId)
                        {
                            mainCoinId = NTMinerContext.Instance.MinerProfile.CoinId;
                            foreach (var speedChartVm in Vm.SpeedChartVms.Items)
                            {
                                SeriesCollection series       = speedChartVm.Series;
                                SeriesCollection seriesShadow = speedChartVm.SeriesShadow;
                                foreach (var item in series)
                                {
                                    item.Values.Clear();
                                }
                                foreach (var item in seriesShadow)
                                {
                                    item.Values.Clear();
                                }
                            }
                        }
                        IGpuSpeed gpuSpeed = message.Source;
                        int index          = gpuSpeed.Gpu.Index;
                        if (Vm.SpeedChartVms.ContainsKey(index))
                        {
                            SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[index];
                            SeriesCollection series          = speedChartVm.Series;
                            SeriesCollection seriesShadow    = speedChartVm.SeriesShadow;
                            DateTime now = DateTime.Now;
                            if (gpuSpeed.MainCoinSpeed != null && series.Count > 0)
                            {
                                IChartValues chartValues = series[0].Values;
                                chartValues.Add(new MeasureModel()
                                {
                                    DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                    Value    = gpuSpeed.MainCoinSpeed.Value
                                });
                                if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now)
                                {
                                    chartValues.RemoveAt(0);
                                }
                                chartValues = seriesShadow[0].Values;
                                chartValues.Add(new MeasureModel()
                                {
                                    DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                    Value    = gpuSpeed.MainCoinSpeed.Value
                                });
                                if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now)
                                {
                                    chartValues.RemoveAt(0);
                                }
                            }
                            if (gpuSpeed.DualCoinSpeed != null && series.Count > 1)
                            {
                                IChartValues chartValues = series[1].Values;
                                chartValues.Add(new MeasureModel()
                                {
                                    DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                    Value    = gpuSpeed.DualCoinSpeed.Value
                                });
                                if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now)
                                {
                                    chartValues.RemoveAt(0);
                                }
                                chartValues = seriesShadow[1].Values;
                                chartValues.Add(new MeasureModel()
                                {
                                    DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                    Value    = gpuSpeed.DualCoinSpeed.Value
                                });
                                if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now)
                                {
                                    chartValues.RemoveAt(0);
                                }
                            }

                            speedChartVm.SetAxisLimits(now);
                        }
                    });
                }, location: this.GetType());
            });

            Vm.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                if (e.PropertyName == nameof(Vm.CurrentSpeedChartVm))
                {
                    SpeedChartViewModel currentItem = Vm.CurrentSpeedChartVm;
                    if (currentItem != null)
                    {
                        foreach (var item in _chartDic.Values)
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                        CartesianChart chart;
                        if (!_chartDic.ContainsKey(currentItem))
                        {
                            chart = new CartesianChart()
                            {
                                DisableAnimations = true,
                                Hoverable         = false,
                                DataTooltip       = null,
                                Background        = WpfUtil.WhiteBrush,
                                Padding           = new Thickness(4, 0, 0, 0),
                                Visibility        = Visibility.Visible
                            };
                            chart.Series = currentItem.SeriesShadow;
                            chart.AxisX  = currentItem.AxisXShadow;
                            chart.AxisY  = currentItem.AxisYShadow;
                            _chartDic.Add(currentItem, chart);
                            DetailsGrid.Children.Add(chart);
                        }
                        else
                        {
                            chart            = _chartDic[currentItem];
                            chart.Visibility = Visibility.Visible;
                        }
                    }
                }
            };

            Vm.CurrentSpeedChartVm = Vm.SpeedChartVms.Items.FirstOrDefault();

            if (AppRoot.MinerProfileVm.CoinVm != null)
            {
                Guid coinId = AppRoot.MinerProfileVm.CoinId;
                foreach (var item in NTMinerContext.Instance.GpuSet.AsEnumerable())
                {
                    List <IGpuSpeed>    gpuSpeedHistory = item.GetGpuSpeedHistory();
                    SpeedChartViewModel speedChartVm    = Vm.SpeedChartVms[item.Index];
                    SeriesCollection    series          = speedChartVm.Series;
                    SeriesCollection    seriesShadow    = speedChartVm.SeriesShadow;
                    DateTime            now             = DateTime.Now;
                    foreach (var gpuSpeed in gpuSpeedHistory)
                    {
                        if (gpuSpeed.MainCoinSpeed != null && series.Count > 0)
                        {
                            series[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            seriesShadow[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                        }
                        if (gpuSpeed.DualCoinSpeed != null && series.Count > 1)
                        {
                            series[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            seriesShadow[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                        }
                    }
                    IChartValues values = series[0].Values;
                    if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now)
                    {
                        series[0].Values.RemoveAt(0);
                    }
                    values = seriesShadow[0].Values;
                    if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerContext.SpeedHistoryLengthByMinute) < now)
                    {
                        seriesShadow[0].Values.RemoveAt(0);
                    }
                    speedChartVm.SetAxisLimits(now);
                }
            }
        }
Exemple #10
0
        private static void ReportSpeed(INTMinerRoot root)
        {
            try {
                SpeedData data = new SpeedData {
                    MessageId          = Guid.NewGuid(),
                    MinerName          = root.MinerProfile.MinerName,
                    ClientId           = ClientId.Id,
                    Timestamp          = DateTime.Now,
                    MainCoinCode       = string.Empty,
                    MainCoinShareDelta = 0,
                    MainCoinSpeed      = 0,
                    DualCoinCode       = string.Empty,
                    DualCoinShareDelta = 0,
                    DualCoinSpeed      = 0,
                    IsMining           = root.IsMining,
                    DualCoinPool       = string.Empty,
                    DualCoinWallet     = string.Empty,
                    IsDualCoinEnabled  = false,
                    Kernel             = string.Empty,
                    MainCoinPool       = string.Empty,
                    MainCoinWallet     = string.Empty
                };
                #region 当前选中的币种是什么
                ICoin mainCoin;
                if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin))
                {
                    data.MainCoinCode = mainCoin.Code;
                    ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId());
                    IPool        mainCoinPool;
                    if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool))
                    {
                        data.MainCoinPool = mainCoinPool.Server;
                    }
                    else
                    {
                        data.MainCoinPool = string.Empty;
                    }
                    data.MainCoinWallet = coinProfile.Wallet;
                    ICoinKernel coinKernel;
                    if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel))
                    {
                        IKernel kernel;
                        if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel))
                        {
                            data.Kernel = kernel.FullName;
                            ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId);
                            data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                            if (coinKernelProfile.IsDualCoinEnabled)
                            {
                                ICoin dualCoin;
                                if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin))
                                {
                                    data.DualCoinCode = dualCoin.Code;
                                    ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId());
                                    data.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                                    IPool dualCoinPool;
                                    if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool))
                                    {
                                        data.DualCoinPool = dualCoinPool.Server;
                                    }
                                    else
                                    {
                                        data.DualCoinPool = string.Empty;
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion

                if (root.IsMining)
                {
                    // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                    if (_lastSpeedMainCoin == null || _lastSpeedMainCoin == root.CurrentMineContext.MainCoin)
                    {
                        _lastSpeedMainCoin = root.CurrentMineContext.MainCoin;
                        CoinShareData preCoinShare;
                        Guid          coinId     = root.CurrentMineContext.MainCoin.GetId();
                        IGpusSpeed    gpuSpeeds  = NTMinerRoot.Current.GpusSpeed;
                        IGpuSpeed     totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                        data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value;
                        ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                        if (!_coinShareDic.TryGetValue(coinId, out preCoinShare))
                        {
                            preCoinShare = new CoinShareData()
                            {
                                TotalShareCount = share.TotalShareCount
                            };
                            _coinShareDic.Add(coinId, preCoinShare);
                            data.MainCoinShareDelta = share.TotalShareCount;
                        }
                        else
                        {
                            data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount;
                        }
                    }
                    if (root.CurrentMineContext is IDualMineContext dualMineContext)
                    {
                        // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                        if (_lastSpeedDualCoin == null || _lastSpeedDualCoin == dualMineContext.DualCoin)
                        {
                            _lastSpeedDualCoin = dualMineContext.DualCoin;
                            CoinShareData preCoinShare;
                            Guid          coinId     = dualMineContext.DualCoin.GetId();
                            IGpusSpeed    gpuSpeeds  = NTMinerRoot.Current.GpusSpeed;
                            IGpuSpeed     totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                            data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value;
                            ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                            if (!_coinShareDic.TryGetValue(coinId, out preCoinShare))
                            {
                                preCoinShare = new CoinShareData()
                                {
                                    TotalShareCount = share.TotalShareCount
                                };
                                _coinShareDic.Add(coinId, preCoinShare);
                                data.DualCoinShareDelta = share.TotalShareCount;
                            }
                            else
                            {
                                data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount;
                            }
                        }
                    }
                }
                Server.ReportService.ReportSpeed(data);
            }
            catch (Exception e) {
                Global.Logger.ErrorDebugLine(e.Message, e);
            }
        }
Exemple #11
0
        public GpusSpeed(INTMinerRoot root)
        {
            _root = root;
            foreach (var gpu in _root.GpuSet)
            {
                _currentGpuSpeed.Add(gpu.Index, new GpuSpeed(gpu)
                {
                    MainCoinSpeed = new Speed()
                    {
                        Value   = 0,
                        SpeedOn = DateTime.Now
                    },
                    DualCoinSpeed = new Speed()
                    {
                        Value   = 0,
                        SpeedOn = DateTime.Now
                    }
                });
            }
            IGpuSpeed totalGpuSpeed    = this._currentGpuSpeed[NTMinerRoot.GpuAllId];
            var       speedExceptTotal = _currentGpuSpeed.Values.Where(a => a != totalGpuSpeed).ToArray();

            totalGpuSpeed.MainCoinSpeed.Value = speedExceptTotal.Sum(a => a.MainCoinSpeed.Value);
            totalGpuSpeed.DualCoinSpeed.Value = speedExceptTotal.Sum(a => a.DualCoinSpeed.Value);
            foreach (var item in _currentGpuSpeed)
            {
                _gpuSpeedHistory.Add(item.Key, new List <IGpuSpeed>());
            }
            Global.Access <Per10MinuteEvent>(
                Guid.Parse("9A17AE73-34B8-4EBA-BE91-22BBD163A3E8"),
                "周期清除过期的历史算力",
                LogEnum.Console,
                action: message => {
                ClearOutOfDateHistory();
            });

            Global.Access <MineStopedEvent>(
                Guid.Parse("1C79954C-0311-4C94-B001-09B39FC11DC6"),
                "停止挖矿后产生一次0算力",
                LogEnum.Console,
                action: message => {
                var now = DateTime.Now;
                foreach (var gpu in _root.GpuSet)
                {
                    Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: false, gpuSpeed: new GpuSpeed(gpu)
                    {
                        MainCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        },
                        DualCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        }
                    }));
                    if (message.MineContext is IDualMineContext dualMineContext)
                    {
                        Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: true, gpuSpeed: new GpuSpeed(gpu)
                        {
                            MainCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            },
                            DualCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            }
                        }));
                    }
                }
            });

            Global.Access <MineStartedEvent>(
                Guid.Parse("997bc22f-9bee-4fd6-afe8-eec7eb664daf"),
                "挖矿开始时产生一次0算力0份额",
                LogEnum.Console,
                action: message => {
                var now                = DateTime.Now;
                ICoinShare share       = _root.CoinShareSet.GetOrCreate(message.MineContext.MainCoin.GetId());
                share.AcceptShareCount = 0;
                share.RejectCount      = 0;
                share.ShareOn          = now;
                Global.Happened(new ShareChangedEvent(share));
                foreach (var gpu in _root.GpuSet)
                {
                    Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: false, gpuSpeed: new GpuSpeed(gpu)
                    {
                        MainCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        },
                        DualCoinSpeed = new Speed {
                            Value   = 0,
                            SpeedOn = now
                        }
                    }));
                }
                if (message.MineContext is IDualMineContext dualMineContext)
                {
                    share = _root.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                    share.AcceptShareCount = 0;
                    share.RejectCount      = 0;
                    share.ShareOn          = now;
                    Global.Happened(new ShareChangedEvent(share));
                    foreach (var gpu in _root.GpuSet)
                    {
                        Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: true, gpuSpeed: new GpuSpeed(gpu)
                        {
                            MainCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            },
                            DualCoinSpeed = new Speed {
                                Value   = 0,
                                SpeedOn = now
                            }
                        }));
                    }
                }
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }
Exemple #12
0
 internal static IGpuSpeed Clone(this IGpuSpeed gpuSpeed)
 {
     return(new GpuSpeed(gpuSpeed.Gpu,
                         mainCoinSpeed: new Speed(gpuSpeed.MainCoinSpeed),
                         dualCoinSpeed: new Speed(gpuSpeed.DualCoinSpeed)));
 }
Exemple #13
0
        public static SpeedData CreateSpeedData()
        {
            INTMinerRoot root        = NTMinerRoot.Instance;
            IWorkProfile workProfile = root.MinerProfile;
            string       macAddress  = string.Empty;
            string       localIp     = string.Empty;

            foreach (var item in VirtualRoot.LocalIpSet.AsEnumerable())
            {
                if (macAddress.Length != 0)
                {
                    macAddress += "," + item.MACAddress;
                    localIp    += "," + item.IPAddress;
                }
                else
                {
                    macAddress = item.MACAddress;
                    localIp    = item.IPAddress;
                }
            }
            SpeedData data = new SpeedData {
                LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp,
                KernelSelfRestartCount      = 0,
                IsAutoBoot            = workProfile.IsAutoBoot,
                IsAutoStart           = workProfile.IsAutoStart,
                AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds,
                Version                        = MainAssemblyInfo.CurrentVersion.ToString(4),
                BootOn                         = root.CreatedOn,
                MineStartedOn                  = null,
                IsMining                       = root.IsMining,
                MineWorkId                     = Guid.Empty,
                MineWorkName                   = string.Empty,
                MinerName                      = workProfile.MinerName,
                GpuInfo                        = root.GpuSetInfo,
                ClientId                       = VirtualRoot.Id,
                MACAddress                     = macAddress,
                LocalIp                        = localIp,
                MainCoinCode                   = string.Empty,
                MainCoinWallet                 = string.Empty,
                MainCoinTotalShare             = 0,
                MainCoinRejectShare            = 0,
                MainCoinSpeed                  = 0,
                DualCoinCode                   = string.Empty,
                DualCoinTotalShare             = 0,
                DualCoinRejectShare            = 0,
                DualCoinSpeed                  = 0,
                DualCoinPool                   = string.Empty,
                DualCoinWallet                 = string.Empty,
                IsDualCoinEnabled              = false,
                Kernel                         = string.Empty,
                MainCoinPool                   = string.Empty,
                OSName                         = Windows.OS.Instance.WindowsEdition,
                GpuDriver                      = root.GpuSet.DriverVersion.ToString(),
                GpuType                        = root.GpuSet.GpuType,
                OSVirtualMemoryMb              = NTMinerRoot.OSVirtualMemoryMb,
                KernelCommandLine              = string.Empty,
                DiskSpace                      = NTMinerRoot.DiskSpace,
                IsAutoRestartKernel            = workProfile.IsAutoRestartKernel,
                AutoRestartKernelTimes         = workProfile.AutoRestartKernelTimes,
                IsNoShareRestartKernel         = workProfile.IsNoShareRestartKernel,
                NoShareRestartKernelMinutes    = workProfile.NoShareRestartKernelMinutes,
                IsNoShareRestartComputer       = workProfile.IsNoShareRestartComputer,
                NoShareRestartComputerMinutes  = workProfile.NoShareRestartComputerMinutes,
                IsPeriodicRestartComputer      = workProfile.IsPeriodicRestartComputer,
                PeriodicRestartComputerHours   = workProfile.PeriodicRestartComputerHours,
                IsPeriodicRestartKernel        = workProfile.IsPeriodicRestartKernel,
                PeriodicRestartKernelHours     = workProfile.PeriodicRestartKernelHours,
                PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes,
                PeriodicRestartKernelMinutes   = workProfile.PeriodicRestartKernelMinutes,
                IsAutoStartByCpu               = workProfile.IsAutoStartByCpu,
                IsAutoStopByCpu                = workProfile.IsAutoStopByCpu,
                CpuGETemperatureSeconds        = workProfile.CpuGETemperatureSeconds,
                CpuLETemperatureSeconds        = workProfile.CpuLETemperatureSeconds,
                CpuStartTemperature            = workProfile.CpuStartTemperature,
                CpuStopTemperature             = workProfile.CpuStopTemperature,
                MainCoinPoolDelay              = string.Empty,
                DualCoinPoolDelay              = string.Empty,
                MinerIp                        = string.Empty,
                IsFoundOneGpuShare             = false,
                IsGotOneIncorrectGpuShare      = false,
                IsRejectOneGpuShare            = false,
                CpuPerformance                 = root.CpuPackage.Performance,
                CpuTemperature                 = root.CpuPackage.Temperature,
                IsRaiseHighCpuEvent            = workProfile.IsRaiseHighCpuEvent,
                HighCpuPercent                 = workProfile.HighCpuBaseline,
                HighCpuSeconds                 = workProfile.HighCpuSeconds,
                GpuTable                       = root.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray()
            };

            if (workProfile.MineWork != null)
            {
                data.MineWorkId   = workProfile.MineWork.GetId();
                data.MineWorkName = workProfile.MineWork.Name;
            }
            #region 当前选中的币种是什么
            if (root.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin))
            {
                data.MainCoinCode = mainCoin.Code;
                ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId());
                data.MainCoinWallet = coinProfile.Wallet;
                if (root.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
                {
                    data.MainCoinPool = mainCoinPool.Server;
                    if (root.IsMining)
                    {
                        data.MainCoinPoolDelay = root.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false);
                    }
                    if (mainCoinPool.IsUserMode)
                    {
                        IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId);
                        data.MainCoinWallet = mainCoinPoolProfile.UserName;
                    }
                }
                else
                {
                    data.MainCoinPool = string.Empty;
                }
                if (root.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
                {
                    if (root.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
                    {
                        data.Kernel = kernel.GetFullName();
                        if (root.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput))
                        {
                            data.IsFoundOneGpuShare        = !string.IsNullOrEmpty(kernelOutput.FoundOneShare);
                            data.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare);
                            data.IsRejectOneGpuShare       = !string.IsNullOrEmpty(kernelOutput.RejectOneShare);
                        }
                        ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
                        data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                        if (coinKernelProfile.IsDualCoinEnabled)
                        {
                            if (root.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                            {
                                data.DualCoinCode = dualCoin.Code;
                                ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId());
                                data.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                                if (root.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                                {
                                    data.DualCoinPool = dualCoinPool.Server;
                                    if (root.IsMining)
                                    {
                                        data.DualCoinPoolDelay = root.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true);
                                    }
                                    if (dualCoinPool.IsUserMode)
                                    {
                                        IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId);
                                        data.DualCoinWallet = dualCoinPoolProfile.UserName;
                                    }
                                }
                                else
                                {
                                    data.DualCoinPool = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (root.IsMining)
            {
                var mineContext = root.LockedMineContext;
                if (mineContext != null)
                {
                    data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount;
                    data.MineStartedOn          = mineContext.CreatedOn;
                    data.KernelCommandLine      = mineContext.CommandLine;
                }
                // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.LockedMineContext.MainCoin)
                {
                    _sLastSpeedMainCoin = root.LockedMineContext.MainCoin;
                    Guid       coinId     = root.LockedMineContext.MainCoin.GetId();
                    IGpusSpeed gpuSpeeds  = NTMinerRoot.Instance.GpusSpeed;
                    IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                    data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value;
                    ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                    data.MainCoinTotalShare  = share.TotalShareCount;
                    data.MainCoinRejectShare = share.RejectShareCount;
                }
                else
                {
                    _sLastSpeedMainCoin = root.LockedMineContext.MainCoin;
                }
                if (root.LockedMineContext is IDualMineContext dualMineContext)
                {
                    // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                    if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin)
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                        Guid       coinId     = dualMineContext.DualCoin.GetId();
                        IGpusSpeed gpuSpeeds  = NTMinerRoot.Instance.GpusSpeed;
                        IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                        data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value;
                        ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                        data.DualCoinTotalShare  = share.TotalShareCount;
                        data.DualCoinRejectShare = share.RejectShareCount;
                    }
                    else
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                    }
                }
            }
            return(data);
        }
Exemple #14
0
        private void Link()
        {
            VirtualRoot.BuildCmdPath <RegCmdHereCommand>(path: message => {
                try {
                    Cmd.RegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "添加windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerContext), "添加windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.BuildCmdPath <UnRegCmdHereCommand>(path: message => {
                try {
                    Cmd.UnRegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "移除windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerContext), "移除windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.BuildEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None,
                                                         path: message => {
                Power.PreventSleep(MinerProfile.IsPreventDisplaySleep);
            }, location: this.GetType());
            #region 挖矿开始时将无份额内核重启份额计数置0
            int      shareCount           = 0;
            DateTime shareOn              = DateTime.Now;
            DateTime highSpeedOn          = DateTime.Now;
            DateTime overClockHighSpeedOn = DateTime.Now;
            VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole,
                                                          path: message => {
                // 将无份额内核重启份额计数置0
                shareCount           = 0;
                highSpeedOn          = DateTime.Now;
                overClockHighSpeedOn = DateTime.Now;
                if (!message.MineContext.IsRestart)
                {
                    // 当不是内核重启时更新shareOn,如果是内核重启不用更新shareOn从而给不干扰无内核矿机重启的逻辑
                    shareOn = DateTime.Now;
                }
            }, location: this.GetType());
            #endregion
            #region 每20秒钟检查是否需要重启
            VirtualRoot.BuildEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None,
                                                          path: message => {
                #region 低算力重启电脑
                if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue)
                {
                    var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId);
                    if (coinProfile.IsLowSpeedRestartComputer && coinProfile.LowSpeed != 0 && coinProfile.LowSpeedRestartComputerMinutes > 0)
                    {
                        IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId);
                        if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) >= message.BornOn)
                        {
                            if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.LowSpeed) >= coinProfile.LowSpeed)
                            {
                                highSpeedOn = message.BornOn;
                            }
                        }
                        if (highSpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) < message.BornOn)
                        {
                            string coinCode = string.Empty;
                            if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin))
                            {
                                coinCode = coin.Code;
                            }
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedRestartComputerMinutes}分钟低于{coinProfile.LowSpeed}重启电脑", toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                            {
                                VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                            }
                            return;
                        }
                    }
                    else
                    {
                        highSpeedOn = message.BornOn;
                    }
                }
                #endregion

                #region 低算力重新应用超频
                if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue)
                {
                    var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId);
                    if (coinProfile.IsLowSpeedReOverClock && coinProfile.OverClockLowSpeed != 0 && coinProfile.LowSpeedReOverClockMinutes > 0)
                    {
                        IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId);
                        if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) >= message.BornOn)
                        {
                            if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.OverClockLowSpeed) >= coinProfile.OverClockLowSpeed)
                            {
                                overClockHighSpeedOn = message.BornOn;
                            }
                        }
                        if (overClockHighSpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) < message.BornOn)
                        {
                            string coinCode = string.Empty;
                            if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin))
                            {
                                coinCode = coin.Code;
                            }
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedReOverClockMinutes}分钟低于{coinProfile.OverClockLowSpeed}重新应用超频", toConsole: true);
                            VirtualRoot.Execute(new CoinOverClockCommand(MinerProfile.CoinId));
                        }
                    }
                    else
                    {
                        overClockHighSpeedOn = message.BornOn;
                    }
                }
                #endregion

                #region 周期重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes)
                        {
                            string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑";
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                            {
                                VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                            }
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel && LockedMineContext.MineStartedOn != DateTime.MinValue)
                    {
                        DateTime dt = GetKernelRestartBaseOnTime();
                        if ((DateTime.Now - dt).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes)
                        {
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true);
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 无份额重启内核
                try {
                    if (IsMining && this.LockedMineContext.MainCoin != null)
                    {
                        int totalShare       = 0;
                        bool restartComputer = MinerProfile.NoShareRestartComputerMinutes > 0 && MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                        bool restartKernel   = MinerProfile.NoShareRestartKernelMinutes > 0 && MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                        if (restartComputer || restartKernel)
                        {
                            ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId());
                            totalShare = mainCoinShare.TotalShareCount;
                            if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                            {
                                ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                totalShare += dualCoinShare.TotalShareCount;
                            }
                            // 如果份额没有增加
                            if (shareCount == totalShare)
                            {
                                // 重启电脑,基于MineStartedOn
                                bool isRestartComputerMinutes = (DateTime.Now - this.LockedMineContext.MineStartedOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                                if (restartComputer && isRestartComputerMinutes)
                                {
                                    if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                                    {
                                        VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                                    }
                                    string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑";
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true);
                                    VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                                    return;    // 退出
                                }
                                // 重启内核,如果MineRestartedOn不是DateTime.MineValue则基于MineRestartedOn
                                DateTime dt = GetKernelRestartBaseOnTime();
                                bool isRestartKernelMinutes = (DateTime.Now - dt).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                                if (restartKernel && isRestartKernelMinutes)
                                {
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true);
                                    RestartMine();
                                    return;    // 退出
                                }
                            }
                            if (totalShare > shareCount)
                            {
                                shareCount = totalShare;
                                shareOn    = DateTime.Now;
                            }
                        }
Exemple #15
0
        public SpeedDto CreateSpeedDto()
        {
            INTMinerContext ntminerContext = NTMinerContext.Instance;
            IWorkProfile    workProfile    = ntminerContext.MinerProfile;
            string          localIps       = VirtualRoot.FormatLocalIps(out string macAddress);
            Guid            mineContextId  = Guid.Empty;

            if (ntminerContext.CurrentMineContext != null)
            {
                mineContextId = ntminerContext.CurrentMineContext.Id;
            }
            SpeedDto speedDto = new SpeedDto {
                MineContextId   = mineContextId,
                MainCoinSpeedOn = DateTime.MinValue,
                DualCoinSpeedOn = DateTime.MinValue,
                IsAutoDisableWindowsFirewall = workProfile.IsAutoDisableWindowsFirewall,
                IsDisableAntiSpyware         = workProfile.IsDisableAntiSpyware,
                IsDisableUAC                = workProfile.IsDisableUAC,
                IsDisableWAU                = workProfile.IsDisableWAU,
                Is1080PillEnabled           = workProfile.Is1080PillEnabled,
                IsPreventDisplaySleep       = workProfile.IsPreventDisplaySleep,
                IsAutoReboot                = workProfile.IsAutoReboot,
                LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp,
                KernelSelfRestartCount      = 0,
                IsAutoBoot            = workProfile.IsAutoBoot,
                IsAutoStart           = workProfile.IsAutoStart,
                AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds,
                Version                        = EntryAssemblyInfo.CurrentVersionStr,
                BootOn                         = ntminerContext.CreatedOn,
                MineStartedOn                  = null,
                IsMining                       = ntminerContext.IsMining,
                MineWorkId                     = Guid.Empty,
                MineWorkName                   = string.Empty,
                MinerName                      = workProfile.MinerName,
                GpuInfo                        = ntminerContext.GpuSetInfo,
                ClientId                       = NTMinerContext.Id,
                MACAddress                     = macAddress,
                LocalIp                        = localIps,
                MainCoinCode                   = string.Empty,
                MainCoinWallet                 = string.Empty,
                MainCoinTotalShare             = 0,
                MainCoinRejectShare            = 0,
                MainCoinSpeed                  = 0,
                DualCoinCode                   = string.Empty,
                DualCoinTotalShare             = 0,
                DualCoinRejectShare            = 0,
                DualCoinSpeed                  = 0,
                DualCoinPool                   = string.Empty,
                DualCoinWallet                 = string.Empty,
                IsDualCoinEnabled              = false,
                Kernel                         = string.Empty,
                MainCoinPool                   = string.Empty,
                OSName                         = Windows.OS.Instance.WindowsEdition,
                GpuDriver                      = ntminerContext.GpuSet.DriverVersion,
                GpuType                        = ntminerContext.GpuSet.GpuType,
                OSVirtualMemoryMb              = VirtualRoot.DriveSet.OSVirtualMemoryMb,
                TotalPhysicalMemoryMb          = (int)(Windows.Ram.Instance.TotalPhysicalMemory / NTKeyword.IntM),
                KernelCommandLine              = string.Empty,
                DiskSpace                      = VirtualRoot.DriveSet.ToDiskSpaceString(),
                IsAutoRestartKernel            = workProfile.IsAutoRestartKernel,
                AutoRestartKernelTimes         = workProfile.AutoRestartKernelTimes,
                IsNoShareRestartKernel         = workProfile.IsNoShareRestartKernel,
                NoShareRestartKernelMinutes    = workProfile.NoShareRestartKernelMinutes,
                IsNoShareRestartComputer       = workProfile.IsNoShareRestartComputer,
                NoShareRestartComputerMinutes  = workProfile.NoShareRestartComputerMinutes,
                IsPeriodicRestartComputer      = workProfile.IsPeriodicRestartComputer,
                PeriodicRestartComputerHours   = workProfile.PeriodicRestartComputerHours,
                IsPeriodicRestartKernel        = workProfile.IsPeriodicRestartKernel,
                PeriodicRestartKernelHours     = workProfile.PeriodicRestartKernelHours,
                PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes,
                PeriodicRestartKernelMinutes   = workProfile.PeriodicRestartKernelMinutes,
                IsAutoStartByCpu               = workProfile.IsAutoStartByCpu,
                IsAutoStopByCpu                = workProfile.IsAutoStopByCpu,
                CpuGETemperatureSeconds        = workProfile.CpuGETemperatureSeconds,
                CpuLETemperatureSeconds        = workProfile.CpuLETemperatureSeconds,
                CpuStartTemperature            = workProfile.CpuStartTemperature,
                CpuStopTemperature             = workProfile.CpuStopTemperature,
                MainCoinPoolDelay              = string.Empty,
                DualCoinPoolDelay              = string.Empty,
                MinerIp                        = string.Empty,
                IsFoundOneGpuShare             = false,
                IsGotOneIncorrectGpuShare      = false,
                IsRejectOneGpuShare            = false,
                CpuPerformance                 = ntminerContext.CpuPackage.Performance,
                CpuTemperature                 = ntminerContext.CpuPackage.Temperature,
                IsRaiseHighCpuEvent            = workProfile.IsRaiseHighCpuEvent,
                HighCpuPercent                 = workProfile.HighCpuBaseline,
                HighCpuSeconds                 = workProfile.HighCpuSeconds,
                IsOuterUserEnabled             = workProfile.IsOuterUserEnabled,
                ReportOuterUserId              = NTMinerRegistry.GetOuterUserId(),
                IsLowSpeedRestartComputer      = false,
                LowSpeedRestartComputerMinutes = 0,
                LowSpeed                       = 0,
                IsLowSpeedReOverClock          = false,
                LowSpeedReOverClockMinutes     = 0,
                OverClockLowSpeed              = 0,
                GpuTable                       = ntminerContext.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray()
            };

            if (workProfile.MineWork != null)
            {
                speedDto.MineWorkId   = workProfile.MineWork.GetId();
                speedDto.MineWorkName = workProfile.MineWork.Name;
            }
            #region 当前选中的币种是什么
            if (ntminerContext.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin))
            {
                speedDto.MainCoinCode = mainCoin.Code;
                ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId());
                speedDto.MainCoinWallet            = coinProfile.Wallet;
                speedDto.IsLowSpeedRestartComputer = coinProfile.IsLowSpeedRestartComputer;
                speedDto.LowSpeed = coinProfile.LowSpeed;
                speedDto.LowSpeedRestartComputerMinutes = coinProfile.LowSpeedRestartComputerMinutes;
                speedDto.IsLowSpeedReOverClock          = coinProfile.IsLowSpeedReOverClock;
                speedDto.LowSpeedReOverClockMinutes     = coinProfile.LowSpeedReOverClockMinutes;
                speedDto.OverClockLowSpeed = coinProfile.OverClockLowSpeed;
                if (ntminerContext.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
                {
                    speedDto.MainCoinPool = mainCoinPool.Server;
                    if (ntminerContext.IsMining)
                    {
                        speedDto.MainCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false);
                    }
                    if (mainCoinPool.IsUserMode)
                    {
                        IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId);
                        speedDto.MainCoinWallet = mainCoinPoolProfile.UserName;
                    }
                }
                else
                {
                    speedDto.MainCoinPool = string.Empty;
                }
                if (ntminerContext.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
                {
                    if (ntminerContext.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
                    {
                        speedDto.Kernel = kernel.GetFullName();
                        if (ntminerContext.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput))
                        {
                            speedDto.IsFoundOneGpuShare        = !string.IsNullOrEmpty(kernelOutput.FoundOneShare);
                            speedDto.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare);
                            speedDto.IsRejectOneGpuShare       = !string.IsNullOrEmpty(kernelOutput.RejectOneShare);
                        }
                        ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
                        speedDto.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                        if (coinKernelProfile.IsDualCoinEnabled)
                        {
                            if (ntminerContext.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                            {
                                speedDto.DualCoinCode = dualCoin.Code;
                                ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId());
                                speedDto.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                                if (ntminerContext.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                                {
                                    speedDto.DualCoinPool = dualCoinPool.Server;
                                    if (ntminerContext.IsMining)
                                    {
                                        speedDto.DualCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true);
                                    }
                                    if (dualCoinPool.IsUserMode)
                                    {
                                        IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId);
                                        speedDto.DualCoinWallet = dualCoinPoolProfile.UserName;
                                    }
                                }
                                else
                                {
                                    speedDto.DualCoinPool = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (ntminerContext.IsMining)
            {
                var mineContext = ntminerContext.LockedMineContext;
                if (mineContext != null)
                {
                    speedDto.KernelSelfRestartCount = mineContext.KernelSelfRestartCount;
                    if (mineContext.MineStartedOn != DateTime.MinValue)
                    {
                        speedDto.MineStartedOn = mineContext.MineStartedOn;
                    }
                    speedDto.KernelCommandLine = mineContext.CommandLine;
                }
                // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == ntminerContext.LockedMineContext.MainCoin)
                {
                    _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin;
                    Guid       coinId     = ntminerContext.LockedMineContext.MainCoin.GetId();
                    IGpusSpeed gpuSpeeds  = ntminerContext.GpusSpeed;
                    IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId);
                    speedDto.MainCoinSpeed   = totalSpeed.MainCoinSpeed.Value;
                    speedDto.MainCoinSpeedOn = totalSpeed.MainCoinSpeed.SpeedOn;
                    ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId);
                    speedDto.MainCoinTotalShare  = share.TotalShareCount;
                    speedDto.MainCoinRejectShare = share.RejectShareCount;
                }
                else
                {
                    _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin;
                }
                if (ntminerContext.LockedMineContext is IDualMineContext dualMineContext)
                {
                    // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                    if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin)
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                        Guid       coinId     = dualMineContext.DualCoin.GetId();
                        IGpusSpeed gpuSpeeds  = ntminerContext.GpusSpeed;
                        IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId);
                        speedDto.DualCoinSpeed   = totalSpeed.DualCoinSpeed.Value;
                        speedDto.DualCoinSpeedOn = totalSpeed.DualCoinSpeed.SpeedOn;
                        ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId);
                        speedDto.DualCoinTotalShare  = share.TotalShareCount;
                        speedDto.DualCoinRejectShare = share.RejectShareCount;
                    }
                    else
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                    }
                }
            }
            return(speedDto);
        }
Exemple #16
0
        private static void PickGpuSpeed(INTMinerRoot root, string input, IKernel kernel, ICoin coin, bool isDual)
        {
            string gpuSpeedPattern = kernel.GpuSpeedPattern;

            if (isDual)
            {
                gpuSpeedPattern = kernel.DualGpuSpeedPattern;
            }
            if (string.IsNullOrEmpty(gpuSpeedPattern))
            {
                return;
            }
            var             now     = DateTime.Now;
            Regex           regex   = new Regex(gpuSpeedPattern);
            MatchCollection matches = regex.Matches(input);

            if (matches.Count > 0)
            {
                GpusSpeed gpuSpeeds = (GpusSpeed)NTMinerRoot.Current.GpusSpeed;

                foreach (Match match in matches)
                {
                    string gpuText      = match.Groups["gpu"].Value;
                    string gpuSpeedText = match.Groups["gpuSpeed"].Value;
                    string gpuSpeedUnit = match.Groups["gpuSpeedUnit"].Value;

                    int    gpu;
                    double gpuSpeed;
                    if (int.TryParse(gpuText, out gpu) && double.TryParse(gpuSpeedText, out gpuSpeed))
                    {
                        long      gpuSpeedL    = gpuSpeed.ToLong(gpuSpeedUnit);
                        IGpuSpeed gpuSpeedItem = gpuSpeeds.First(a => a.Gpu.Index == gpu);
                        gpuSpeeds.SetCurrentSpeed(gpuSpeedItem.Clone());
                        if (isDual)
                        {
                            gpuSpeedItem.DualCoinSpeed.Value   = gpuSpeedL;
                            gpuSpeedItem.DualCoinSpeed.SpeedOn = now;
                        }
                        else
                        {
                            gpuSpeedItem.MainCoinSpeed.Value   = gpuSpeedL;
                            gpuSpeedItem.MainCoinSpeed.SpeedOn = now;
                        }
                        Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: isDual, gpuSpeed: gpuSpeedItem));
                    }
                }
                string totalSpeedPattern = kernel.DualTotalSpeedPattern;
                if (isDual)
                {
                    totalSpeedPattern = kernel.DualTotalSpeedPattern;
                }
                if (string.IsNullOrEmpty(totalSpeedPattern))
                {
                    // 求和分算力
                    IGpuSpeed totalGpuSpeed = gpuSpeeds.First(a => a.Gpu.Index == root.GpuAllId);
                    gpuSpeeds.SetCurrentSpeed(totalGpuSpeed.Clone());
                    if (isDual)
                    {
                        totalGpuSpeed.DualCoinSpeed.Value   = gpuSpeeds.Where(a => a.Gpu.Index != root.GpuAllId).Sum(a => a.DualCoinSpeed.Value);
                        totalGpuSpeed.DualCoinSpeed.SpeedOn = now;
                    }
                    else
                    {
                        totalGpuSpeed.MainCoinSpeed.Value   = gpuSpeeds.Where(a => a.Gpu.Index != root.GpuAllId).Sum(a => a.MainCoinSpeed.Value);;
                        totalGpuSpeed.MainCoinSpeed.SpeedOn = now;
                    }
                    Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: isDual, gpuSpeed: totalGpuSpeed));
                }
            }
        }
Exemple #17
0
        private static void PickTotalSpeed(INTMinerRoot root, string input, IKernel kernel, ICoin coin, bool isDual)
        {
            string totalSpeedPattern = kernel.TotalSpeedPattern;

            if (isDual)
            {
                totalSpeedPattern = kernel.DualTotalSpeedPattern;
            }
            if (string.IsNullOrEmpty(totalSpeedPattern))
            {
                return;
            }
            Match match = Regex.Match(input, totalSpeedPattern);

            if (match.Success)
            {
                string totalSpeedText = match.Groups["totalSpeed"].Value;
                string totalSpeedUnit = match.Groups["totalSpeedUnit"].Value;

                double totalSpeed;
                if (double.TryParse(totalSpeedText, out totalSpeed))
                {
                    long      totalSpeedL   = totalSpeed.ToLong(totalSpeedUnit);
                    var       now           = DateTime.Now;
                    GpusSpeed gpuSpeeds     = (GpusSpeed)NTMinerRoot.Current.GpusSpeed;
                    IGpuSpeed totalGpuSpeed = gpuSpeeds.First(a => a.Gpu.Index == root.GpuAllId);
                    gpuSpeeds.SetCurrentSpeed(totalGpuSpeed.Clone());
                    if (isDual)
                    {
                        totalGpuSpeed.DualCoinSpeed.Value   = totalSpeedL;
                        totalGpuSpeed.DualCoinSpeed.SpeedOn = now;
                    }
                    else
                    {
                        totalGpuSpeed.MainCoinSpeed.Value   = totalSpeedL;
                        totalGpuSpeed.MainCoinSpeed.SpeedOn = now;
                    }
                    Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: isDual, gpuSpeed: totalGpuSpeed));
                    string gpuSpeedPattern = kernel.GpuSpeedPattern;
                    if (isDual)
                    {
                        gpuSpeedPattern = kernel.DualGpuSpeedPattern;
                    }
                    if (string.IsNullOrEmpty(gpuSpeedPattern))
                    {
                        // 平分总算力
                        long gpuSpeedL = totalSpeedL / root.GpuSet.Count;
                        foreach (var item in gpuSpeeds)
                        {
                            if (item.Gpu.Index != root.GpuAllId)
                            {
                                gpuSpeeds.SetCurrentSpeed(item.Clone());
                                if (isDual)
                                {
                                    item.DualCoinSpeed.Value   = gpuSpeedL;
                                    item.DualCoinSpeed.SpeedOn = now;
                                }
                                else
                                {
                                    item.MainCoinSpeed.Value   = gpuSpeedL;
                                    item.MainCoinSpeed.SpeedOn = now;
                                }
                                Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: isDual, gpuSpeed: item));
                            }
                        }
                    }
                }
            }
        }
        public SpeedCharts()
        {
            InitializeComponent();
            ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources);

            if (Design.IsInDesignMode)
            {
                return;
            }
            Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId;

            VirtualRoot.On <GpuSpeedChangedEvent>("显卡算力变更后刷新算力图界面", LogEnum.DevConsole,
                                                  action: (message) => {
                UIThread.Execute(() => {
                    if (mainCoinId != NTMinerRoot.Current.MinerProfile.CoinId)
                    {
                        mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId;
                        foreach (var speedChartVm in Vm.SpeedChartVms)
                        {
                            SeriesCollection series       = speedChartVm.Series;
                            SeriesCollection seriesShadow = speedChartVm.SeriesShadow;
                            foreach (var item in series)
                            {
                                item.Values.Clear();
                            }
                            foreach (var item in seriesShadow)
                            {
                                item.Values.Clear();
                            }
                        }
                    }
                    IGpuSpeed gpuSpeed = message.Source;
                    int index          = gpuSpeed.Gpu.Index;
                    if (Vm.SpeedChartVms.ContainsKey(index))
                    {
                        SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[index];
                        SeriesCollection series          = speedChartVm.Series;
                        SeriesCollection seriesShadow    = speedChartVm.SeriesShadow;
                        DateTime now = DateTime.Now;
                        if (gpuSpeed.MainCoinSpeed != null && series.Count > 0)
                        {
                            IChartValues chartValues = series[0].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                            chartValues = seriesShadow[0].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                        }
                        if (gpuSpeed.DualCoinSpeed != null && series.Count > 1)
                        {
                            IChartValues chartValues = series[1].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                            chartValues = seriesShadow[1].Values;
                            chartValues.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                            {
                                chartValues.RemoveAt(0);
                            }
                        }

                        speedChartVm.SetAxisLimits(now);
                    }
                });
            }).AddToCollection(_handlers);

            Vm.ItemsPanelColumns = 1;
            this.Unloaded       += (object sender, RoutedEventArgs e) => {
                foreach (var handler in _handlers)
                {
                    VirtualRoot.UnPath(handler);
                }
                foreach (var item in Vm.SpeedChartVms)
                {
                    item.Series       = null;
                    item.SeriesShadow = null;
                    item.AxisX        = null;
                    item.AxisY        = null;
                    item.AxisXShadow  = null;
                    item.AxisYShadow  = null;
                }
                _chartDic.Clear();
            };
            SolidColorBrush White = new SolidColorBrush(Colors.White);

            Vm.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                if (e.PropertyName == nameof(Vm.CurrentSpeedChartVm))
                {
                    SpeedChartViewModel currentItem = Vm.CurrentSpeedChartVm;
                    if (currentItem != null)
                    {
                        foreach (var item in _chartDic.Values)
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                        CartesianChart chart;
                        if (!_chartDic.ContainsKey(currentItem))
                        {
                            chart = new CartesianChart()
                            {
                                DisableAnimations = true,
                                Hoverable         = false,
                                DataTooltip       = null,
                                Background        = White,
                                Padding           = new Thickness(4, 0, 0, 0),
                                Visibility        = Visibility.Visible
                            };
                            chart.Series = currentItem.SeriesShadow;
                            chart.AxisX  = currentItem.AxisXShadow;
                            chart.AxisY  = currentItem.AxisYShadow;
                            _chartDic.Add(currentItem, chart);
                            DetailsGrid.Children.Add(chart);
                        }
                        else
                        {
                            chart            = _chartDic[currentItem];
                            chart.Visibility = Visibility.Visible;
                        }
                    }
                }
            };

            Vm.SetCurrentSpeedChartVm(Vm.SpeedChartVms.FirstOrDefault());

            if (MinerProfileViewModel.Current.CoinVm != null)
            {
                Guid coinId = MinerProfileViewModel.Current.CoinId;
                foreach (var item in NTMinerRoot.Current.GpuSet)
                {
                    List <IGpuSpeed>    gpuSpeedHistory = item.GetGpuSpeedHistory();
                    SpeedChartViewModel speedChartVm    = Vm.SpeedChartVms[item.Index];
                    SeriesCollection    series          = speedChartVm.Series;
                    SeriesCollection    seriesShadow    = speedChartVm.SeriesShadow;
                    DateTime            now             = DateTime.Now;
                    foreach (var gpuSpeed in gpuSpeedHistory)
                    {
                        if (gpuSpeed.MainCoinSpeed != null && series.Count > 0)
                        {
                            series[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                            seriesShadow[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.MainCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.MainCoinSpeed.Value
                            });
                        }
                        if (gpuSpeed.DualCoinSpeed != null && series.Count > 1)
                        {
                            series[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                            seriesShadow[0].Values.Add(new MeasureModel()
                            {
                                DateTime = gpuSpeed.DualCoinSpeed.SpeedOn,
                                Value    = gpuSpeed.DualCoinSpeed.Value
                            });
                        }
                    }
                    IChartValues values = series[0].Values;
                    if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                    {
                        series[0].Values.RemoveAt(0);
                    }
                    values = seriesShadow[0].Values;
                    if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now)
                    {
                        seriesShadow[0].Values.RemoveAt(0);
                    }
                    speedChartVm.SetAxisLimits(now);
                }
            }
        }
Exemple #19
0
 public void Update(IGpuSpeed data)
 {
     this.MainCoinSpeed = data.MainCoinSpeed;
     this.DualCoinSpeed = data.DualCoinSpeed;
 }
Exemple #20
0
        private static void PickRejectOneShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string rejectOneShare = kernelOutput.RejectOneShare;

            if (isDual)
            {
                rejectOneShare = kernelOutput.DualRejectOneShare;
            }
            if (string.IsNullOrEmpty(rejectOneShare))
            {
                return;
            }
            if (rejectOneShare.Contains("\n"))
            {
                input = preline + "\n" + input;
            }
            Regex regex = VirtualRoot.GetRegex(rejectOneShare);
            var   match = regex.Match(input);

            if (match.Success)
            {
                if (!isDual)
                {
                    // 决定不支持双挖的单卡份额统计
                    string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                    if (!string.IsNullOrEmpty(gpuText))
                    {
                        if (int.TryParse(gpuText, out int gpuIndex))
                        {
                            if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                            {
                                if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length)
                                {
                                    gpuIndex = mineContext.UseDevices[gpuIndex];
                                }
                            }
                            if (string.IsNullOrEmpty(kernelOutput.FoundOneShare))
                            {
                                root.GpusSpeed.IncreaseFoundShare(gpuIndex);
                            }
                            root.GpusSpeed.IncreaseRejectShare(gpuIndex);
                        }
                    }
                    else if (!string.IsNullOrEmpty(kernelOutput.FoundOneShare))
                    {
                        // 哪个GPU最近找到了一个share就是那个GPU拒绝了一个share
                        var       gpuSpeeds = root.GpusSpeed.AsEnumerable();
                        IGpuSpeed gpuSpeed  = null;
                        foreach (var item in gpuSpeeds)
                        {
                            if (gpuSpeed == null)
                            {
                                gpuSpeed = item;
                            }
                            else if (item.FoundShareOn > gpuSpeed.FoundShareOn)
                            {
                                gpuSpeed = item;
                            }
                        }
                        if (gpuSpeed != null)
                        {
                            var gpuIndex = gpuSpeed.Gpu.Index;
                            root.GpusSpeed.IncreaseRejectShare(gpuIndex);
                        }
                    }
                }
                ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                root.CoinShareSet.UpdateShare(coin.GetId(), null, share.RejectShareCount + 1, DateTime.Now);
            }
        }
Exemple #21
0
 private static void ReportSpeed(INTMinerRoot root) {
     try {
         SpeedData data = new SpeedData {
             MessageId = Guid.NewGuid(),
             MinerName = root.MinerProfile.MinerName,
             ClientId = ClientId.Id,
             Timestamp = DateTime.Now,
             MainCoinCode = string.Empty,
             MainCoinShareDelta = 0,
             MainCoinSpeed = 0,
             DualCoinCode = string.Empty,
             DualCoinShareDelta = 0,
             DualCoinSpeed = 0,
             IsMining = root.IsMining,
             DualCoinPool = string.Empty,
             DualCoinWallet = string.Empty,
             IsDualCoinEnabled = false,
             Kernel = string.Empty,
             MainCoinPool = string.Empty,
             MainCoinWallet = string.Empty
         };
         ICoin mainCoin;
         if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin)) {
             data.MainCoinCode = mainCoin.Code;
             ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId());
             IPool mainCoinPool;
             if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) {
                 data.MainCoinPool = mainCoinPool.Server;
             }
             else {
                 data.MainCoinPool = string.Empty;
             }
             data.MainCoinWallet = coinProfile.Wallet;
             ICoinKernel coinKernel;
             if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) {
                 IKernel kernel;
                 if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) {
                     data.Kernel = kernel.FullName;
                     ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId);
                     data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                     if (coinKernelProfile.IsDualCoinEnabled) {
                         ICoin dualCoin;
                         if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) {
                             data.DualCoinCode = dualCoin.Code;
                             ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId());
                             data.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                             IPool dualCoinPool;
                             if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) {
                                 data.DualCoinPool = dualCoinPool.Server;
                             }
                             else {
                                 data.DualCoinPool = string.Empty;
                             }
                         }
                     }
                 }
             }
         }
         // 如果正在挖矿则报告算力,否则默认报告0算力
         if (root.IsMining) {
             CoinShareData preCoinShare;
             Guid coinId = root.CurrentMineContext.MainCoin.GetId();
             IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed;
             IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId);
             data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value;
             ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
             if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) {
                 preCoinShare = new CoinShareData() {
                     TotalShareCount = share.TotalShareCount
                 };
                 _coinShareDic.Add(coinId, preCoinShare);
                 data.MainCoinShareDelta = share.TotalShareCount;
             }
             else {
                 data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount;
             }
             if (root.CurrentMineContext is IDualMineContext dualMineContext) {
                 if (root.IsMining) {
                     coinId = dualMineContext.DualCoin.GetId();
                     gpuSpeeds = NTMinerRoot.Current.GpusSpeed;
                     totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId);
                     data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value;
                     share = root.CoinShareSet.GetOrCreate(coinId);
                     if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) {
                         preCoinShare = new CoinShareData() {
                             TotalShareCount = share.TotalShareCount
                         };
                         _coinShareDic.Add(coinId, preCoinShare);
                         data.DualCoinShareDelta = share.TotalShareCount;
                     }
                     else {
                         data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount;
                     }
                 }
             }
         }
         Server.ReportService.ReportSpeed(data);
     }
     catch (Exception e) {
         Global.DebugLine(e.Message, ConsoleColor.Red);
         Global.DebugLine(e.StackTrace, ConsoleColor.Red);
     }
 }