コード例 #1
0
        public override APIData GetSummary()
        {
            APIData ad = new APIData(MiningSetup.CurrentAlgorithmType);

            if (database == null)
            {
                try {
                    database = new ProspectorDatabase(WorkingDirectory + "info.db");
                } catch (Exception e) { Helpers.ConsolePrint(MinerTAG(), e.ToString()); }
            }
            else
            {
                foreach (var pair in MiningSetup.MiningPairs)
                {
                    if (database != null)
                    {
                        ad.Speed += database.QueryLastSpeed(deviceIDString(pair.Device.ID, pair.Device.DeviceType));
                    }
                }
            }
            // check if speed zero
            if (ad.Speed == 0)
            {
                _currentMinerReadStatus = MinerAPIReadStatus.READ_SPEED_ZERO;
            }

            return(ad);
        }
コード例 #2
0
        /// <summary>
        /// The BenchmarkThreadRoutine
        /// </summary>
        /// <param name="CommandLine">The <see cref="object"/></param>
        protected override void BenchmarkThreadRoutine(object CommandLine)
        {
            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;

            var startTime = DateTime.Now;

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                Helpers.ConsolePrint(MinerTAG(), "Benchmark should end in : " + benchmarkTimeWait + " seconds");
                BenchmarkHandle = BenchmarkStartProcess((string)CommandLine);
                Stopwatch _benchmarkTimer = new Stopwatch();
                _benchmarkTimer.Reset();
                _benchmarkTimer.Start();
                //BenchmarkThreadRoutineStartSettup();
                // wait a little longer then the benchmark routine if exit false throw
                //var timeoutTime = BenchmarkTimeoutInSeconds(BenchmarkTimeInSeconds);
                //var exitSucces = BenchmarkHandle.WaitForExit(timeoutTime * 1000);
                // don't use wait for it breaks everything
                BenchmarkProcessStatus = BenchmarkProcessStatus.Running;
                bool keepRunning = true;
                while (keepRunning && IsActiveProcess(BenchmarkHandle.Id))
                {
                    //string outdata = BenchmarkHandle.StandardOutput.ReadLine();
                    //BenchmarkOutputErrorDataReceivedImpl(outdata);
                    // terminate process situations
                    if (_benchmarkTimer.Elapsed.TotalSeconds >= (benchmarkTimeWait + 2) ||
                        BenchmarkSignalQuit ||
                        BenchmarkSignalFinnished ||
                        BenchmarkSignalHanged ||
                        BenchmarkSignalTimedout ||
                        BenchmarkException != null)
                    {
                        string imageName = MinerExeName.Replace(".exe", "");
                        // maybe will have to KILL process
                        KillProspectorClaymoreMinerBase(imageName);
                        if (BenchmarkSignalTimedout)
                        {
                            throw new Exception("Benchmark timedout");
                        }
                        if (BenchmarkException != null)
                        {
                            throw BenchmarkException;
                        }
                        if (BenchmarkSignalQuit)
                        {
                            throw new Exception("Termined by user request");
                        }
                        if (BenchmarkSignalFinnished)
                        {
                            break;
                        }
                        keepRunning = false;
                        break;
                    }
                    else
                    {
                        // wait a second reduce CPU load
                        Thread.Sleep(1000);
                    }
                }
                BenchmarkHandle.WaitForExit(20 * 1000);  // Wait up to 20s for exit
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;

                if (database == null)
                {
                    try
                    {
                        database = new ProspectorDatabase(WorkingDirectory + "info.db");
                    }
                    catch (Exception e) { Helpers.ConsolePrint(MinerTAG(), e.ToString()); }
                }

                var session      = database.LastSession();
                var sessionStart = Convert.ToDateTime(session.start);
                if (sessionStart < startTime)
                {
                    throw new Exception("Session not recorded!");
                }

                var hashrates = database.QuerySpeedsForSession(session.id);

                double speed     = 0;
                int    speedRead = 0;
                foreach (var hashrate in hashrates)
                {
                    if (hashrate.coin == MiningSetup.MinerName && hashrate.rate > 0)
                    {
                        speed += hashrate.rate;
                        speedRead++;
                    }
                }

                BenchmarkAlgorithm.BenchmarkSpeed = (speed / speedRead) * (1 - DevFee);

                BenchmarkThreadRoutineFinish();
            }
        }