コード例 #1
0
        virtual protected void BenchmarkThreadRoutine(object CommandLine)
        {
            Thread.Sleep(ConfigManager.Instance.GeneralConfig.MinerRestartDelayMS);

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

            try {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                BenchmarkHandle = BenchmarkStartProcess((string)CommandLine);

                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;
                BenchmarkHandle.WaitForExit();
                if (BenchmarkSignalTimedout)
                {
                    throw new Exception("Benchmark timedout");
                }
                if (BenchmarkException != null)
                {
                    throw BenchmarkException;
                }
                if (BenchmarkSignalQuit)
                {
                    throw new Exception("Termined by user request");
                }
                if (BenchmarkSignalHanged)
                {
                    throw new Exception("SGMiner is not responding");
                }
                if (BenchmarkSignalFinnished)
                {
                    //break;
                }
            } catch (Exception ex) {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;

                Helpers.ConsolePrint(MinerTAG(), "Benchmark Exception: " + ex.Message);
                if (BenchmarkComunicator != null && !OnBenchmarkCompleteCalled)
                {
                    OnBenchmarkCompleteCalled = true;
                    BenchmarkComunicator.OnBenchmarkComplete(false, BenchmarkSignalTimedout ? International.GetText("Benchmark_Timedout") : International.GetText("Benchmark_Terminated"));
                }
            } finally {
                BenchmarkProcessStatus = BenchmarkProcessStatus.Success;
                Helpers.ConsolePrint("BENCHMARK", "Final Speed: " + Helpers.FormatSpeedOutput(BenchmarkAlgorithm.BenchmarkSpeed));
                Helpers.ConsolePrint("BENCHMARK", "Benchmark ends");
                if (BenchmarkComunicator != null && !OnBenchmarkCompleteCalled)
                {
                    OnBenchmarkCompleteCalled = true;
                    BenchmarkComunicator.OnBenchmarkComplete(true, "Success");
                }
            }
        }
コード例 #2
0
        protected virtual void BenchmarkThreadRoutine(object commandLine)
        {
            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;

            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                BenchmarkHandle = BenchmarkStartProcess((string)commandLine);

                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;
                var exited = BenchmarkHandle.WaitForExit((BenchmarkTimeoutInSeconds(BenchmarkTimeInSeconds) + 20) * 1000);
                if (BenchmarkSignalTimedout && !TimeoutStandard)
                {
                    throw new Exception("Benchmark timedout");
                }

                if (BenchmarkException != null)
                {
                    throw BenchmarkException;
                }

                if (BenchmarkSignalQuit)
                {
                    throw new Exception("Termined by user request");
                }

                if (BenchmarkSignalHanged || !exited)
                {
                    throw new Exception("Miner is not responding");
                }

                if (BenchmarkSignalFinnished)
                {
                    //break;
                }
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #3
0
        protected override void BenchmarkThreadRoutine(object CommandLine)
        {
            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;

            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                BenchmarkHandle = BenchmarkStartProcess((string)CommandLine);

                BenchmarkThreadRoutineStartSettup();
                BenchmarkTimeInSeconds = 300;
                BenchmarkProcessStatus = BenchmarkProcessStatus.Running;
                var exited = BenchmarkHandle.WaitForExit((BenchmarkTimeoutInSeconds(BenchmarkTimeInSeconds) + 20) * 1000);
                if (BenchmarkSignalTimedout && !TimeoutStandard)
                {
                    throw new Exception("Benchmark timedout");
                }

                if (BenchmarkException != null)
                {
                    throw BenchmarkException;
                }

                if (BenchmarkSignalQuit)
                {
                    throw new Exception("Termined by user request");
                }

                if (BenchmarkSignalHanged || !exited)
                {
                    throw new Exception("Miner is not responding");
                }

                if (BenchmarkSignalFinnished)
                {
                    //break;
                }
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #4
0
        // benchmark stuff

        protected override void BenchmarkThreadRoutine(object CommandLine)
        {
            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

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

            try {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                Helpers.ConsolePrint(MinerTAG(), "Benchmark should end in : " + benchmarkTimeWait + " seconds");
                BenchmarkHandle = BenchmarkStartProcess((string)CommandLine);
                BenchmarkHandle.WaitForExit(benchmarkTimeWait + 2);
                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
                        KillClaymoreMinerBase(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);
                    }
                }
            } catch (Exception ex) {
                BenchmarkThreadRoutineCatch(ex);
            } finally {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;
                // find latest log file
                string latestLogFile = "";
                var    dirInfo       = new DirectoryInfo(this.WorkingDirectory);
                foreach (var file in dirInfo.GetFiles("*_log.txt"))
                {
                    latestLogFile = file.Name;
                    break;
                }
                // read file log
                if (File.Exists(WorkingDirectory + latestLogFile))
                {
                    var lines         = File.ReadAllLines(WorkingDirectory + latestLogFile);
                    var addBenchLines = bench_lines.Count == 0;
                    foreach (var line in lines)
                    {
                        if (line != null)
                        {
                            bench_lines.Add(line);
                            string lineLowered = line.ToLower();
                            if (lineLowered.Contains(LOOK_FOR_START))
                            {
                                if (ignoreZero)
                                {
                                    double got = getNumber(lineLowered);
                                    if (got != 0)
                                    {
                                        benchmark_sum += got;
                                        ++benchmark_read_count;
                                    }
                                }
                                else
                                {
                                    benchmark_sum += getNumber(lineLowered);
                                    ++benchmark_read_count;
                                }
                            }
                            else if (lineLowered.Contains(SecondaryLookForStart()))
                            {
                                if (ignoreZero)
                                {
                                    double got = getNumber(lineLowered, SecondaryLookForStart(), LOOK_FOR_END);
                                    if (got != 0)
                                    {
                                        secondary_benchmark_sum += got;
                                        ++secondary_benchmark_read_count;
                                    }
                                }
                                else
                                {
                                    secondary_benchmark_sum += getNumber(lineLowered);
                                    ++secondary_benchmark_read_count;
                                }
                            }
                        }
                    }
                    if (benchmark_read_count > 0)
                    {
                        BenchmarkAlgorithm.BenchmarkSpeed          = benchmark_sum / benchmark_read_count;
                        BenchmarkAlgorithm.SecondaryBenchmarkSpeed = secondary_benchmark_sum / secondary_benchmark_read_count;
                    }
                }
                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #5
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();
            }
        }
コード例 #6
0
        protected override void BenchmarkThreadRoutine(object commandLine)
        {
            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;

            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                Helpers.ConsolePrint(MinerTag(), "Benchmark should end in : " + _benchmarkTimeWait + " seconds");
                BenchmarkHandle = BenchmarkStartProcess((string)commandLine);
                BenchmarkHandle.WaitForExit(_benchmarkTimeWait + 2);
                var 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;
                var 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)
                    {
                        var imageName = MinerExeName.Replace(".exe", "");
                        // maybe will have to KILL process
                        EndBenchmarkProcces();
                        KillMinerBase(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;
                    }

                    // wait a second reduce CPU load
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;
                // find latest log file
                var latestLogFile = "";
                var dirInfo       = new DirectoryInfo(WorkingDirectory);
                foreach (var file in dirInfo.GetFiles(GetLogFileName()))
                {
                    latestLogFile = file.Name;
                    break;
                }

                // read file log
                if (File.Exists(WorkingDirectory + latestLogFile))
                {
                    var lines     = new string[0];
                    var read      = false;
                    var iteration = 0;
                    while (!read)
                    {
                        if (iteration < 10)
                        {
                            try
                            {
                                lines = File.ReadAllLines(WorkingDirectory + latestLogFile);
                                read  = true;
                                Helpers.ConsolePrint(MinerTag(),
                                                     "Successfully read log after " + iteration + " iterations");
                            }
                            catch (Exception ex)
                            {
                                Helpers.ConsolePrint(MinerTag(), ex.Message);
                                Thread.Sleep(1000);
                            }

                            iteration++;
                        }
                        else
                        {
                            read = true; // Give up after 10s
                            Helpers.ConsolePrint(MinerTag(), "Gave up on iteration " + iteration);
                        }
                    }

                    var addBenchLines = BenchLines.Count == 0;
                    foreach (var line in lines)
                    {
                        if (line != null)
                        {
                            BenchLines.Add(line);
                            var lineLowered = line.ToLower();
                            if (lineLowered.Contains(LookForStart))
                            {
                                _benchmarkSum += GetNumber(lineLowered);
                                ++_benchmarkReadCount;
                            }
                        }
                    }

                    if (_benchmarkReadCount > 0)
                    {
                        BenchmarkAlgorithm.BenchmarkSpeed = _benchmarkSum / _benchmarkReadCount;
                    }
                }

                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #7
0
        protected override void BenchmarkThreadRoutine(object commandLine)
        {
            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;

            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

            try
            {
                try
                {
                    var latestLogFile = GetLogFileName();
                    var dirInfo       = new DirectoryInfo(WorkingDirectory);
                    if (File.Exists(WorkingDirectory + latestLogFile))
                    {
                        var loglines = File.ReadAllLines(WorkingDirectory + latestLogFile);
                    }
                }
                catch
                {
                    Helpers.ConsolePrint("BENCHMARK", "Benchmark skip");
                    return;
                }
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                Helpers.ConsolePrint(MinerTag(), "Benchmark should end in : " + _benchmarkTimeWait + " seconds");
                BenchmarkHandle = BenchmarkStartProcess((string)commandLine);
                BenchmarkHandle.WaitForExit(_benchmarkTimeWait + 2);
                var 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;
                var 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)
                    {
                        var imageName = MinerExeName.Replace(".exe", "");
                        // maybe will have to KILL process
                        KillMinerBase(imageName);
                        //Stop_cpu_ccminer_sgminer_nheqminer(MinerStopType.END);

                        /*
                         * if (ProcessHandle != null)
                         * {
                         *  try { ProcessHandle.Kill(); }
                         *  catch { }
                         * }
                         */
                        int k    = ProcessTag().IndexOf("pid(");
                        int i    = ProcessTag().IndexOf(")|bin");
                        var cpid = ProcessTag().Substring(k + 4, i - k - 4).Trim();
                        int pid  = int.Parse(cpid, CultureInfo.InvariantCulture);
                        KillProcessAndChildren(pid);

                        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;
                    }

                    // wait a second reduce CPU load
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;

                var latestLogFile = GetLogFileName();
                var dirInfo       = new DirectoryInfo(WorkingDirectory);

                // read file log
                Thread.Sleep(1000);
                if (File.Exists(WorkingDirectory + latestLogFile))
                {
                    var lines     = new string[0];
                    var read      = false;
                    var iteration = 0;
                    while (!read)
                    {
                        if (iteration < 10)
                        {
                            try
                            {
                                lines = File.ReadAllLines(WorkingDirectory + latestLogFile);
                                read  = true;
                                Helpers.ConsolePrint(MinerTag(),
                                                     "Successfully read log after " + iteration + " iterations");
                            }
                            catch (Exception ex)
                            {
                                Helpers.ConsolePrint(MinerTag(), ex.Message);
                                Thread.Sleep(1000);
                            }

                            iteration++;
                        }
                        else
                        {
                            read = true; // Give up after 10s
                            Helpers.ConsolePrint(MinerTag(), "Gave up on iteration " + iteration);
                        }
                    }

                    var addBenchLines = BenchLines.Count == 0;
                    foreach (var line in lines)
                    {
                        if (line != null)
                        {
                            if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.MTP))
                            {
                                if (line.Contains("1/1") || line.Contains("0/1"))
                                {
                                    var    st    = line.IndexOf("- ");
                                    var    e     = line.ToLower().IndexOf("h/s");
                                    var    parse = line.Substring(st + 2, e - st - 4).Trim();
                                    double tmp   = Double.Parse(parse, CultureInfo.InvariantCulture);
                                    // save speed

                                    if (line.ToLower().Contains("kh/s"))
                                    {
                                        tmp *= 1000;
                                    }
                                    else if (line.ToLower().Contains("mh/s"))
                                    {
                                        tmp *= 1000000;
                                    }

                                    BenchmarkAlgorithm.BenchmarkSpeed = tmp;
                                    BenchmarkSignalFinnished          = true;
                                }
                            }

                            if (line.Contains("3/3") || line.Contains("2/3"))
                            {
                                var    st    = line.IndexOf("- ");
                                var    e     = line.ToLower().IndexOf("h/s");
                                var    parse = line.Substring(st + 2, e - st - 4).Trim();
                                double tmp   = Double.Parse(parse, CultureInfo.InvariantCulture);
                                // save speed

                                if (line.ToLower().Contains("kh/s"))
                                {
                                    tmp *= 1000;
                                }
                                else if (line.ToLower().Contains("mh/s"))
                                {
                                    tmp *= 1000000;
                                }

                                BenchmarkAlgorithm.BenchmarkSpeed = tmp;
                                BenchmarkSignalFinnished          = true;
                            }
                            if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.Lyra2z))
                            {
                                if (line.Contains("6/6") || line.Contains("5/6"))
                                {
                                    var    st    = line.IndexOf("- ");
                                    var    e     = line.ToLower().IndexOf("h/s");
                                    var    parse = line.Substring(st + 2, e - st - 4).Trim();
                                    double tmp   = Double.Parse(parse, CultureInfo.InvariantCulture);
                                    // save speed

                                    if (line.ToLower().Contains("kh/s"))
                                    {
                                        tmp *= 1000;
                                    }
                                    else if (line.ToLower().Contains("mh/s"))
                                    {
                                        tmp *= 1000000;
                                    }

                                    BenchmarkAlgorithm.BenchmarkSpeed = tmp;
                                    BenchmarkSignalFinnished          = true;
                                }
                            }
                            if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.X16R))
                            {
                                if (line.Contains("6/6") || line.Contains("5/6"))
                                {
                                    var    st    = line.IndexOf("- ");
                                    var    e     = line.ToLower().IndexOf("h/s");
                                    var    parse = line.Substring(st + 2, e - st - 4).Trim();
                                    double tmp   = Double.Parse(parse, CultureInfo.InvariantCulture);
                                    // save speed

                                    if (line.ToLower().Contains("kh/s"))
                                    {
                                        tmp *= 1000;
                                    }
                                    else if (line.ToLower().Contains("mh/s"))
                                    {
                                        tmp *= 1000000;
                                    }

                                    BenchmarkAlgorithm.BenchmarkSpeed = tmp;
                                    BenchmarkSignalFinnished          = true;
                                }
                            }
                        }
                    }
                }

                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #8
0
        /// <summary>
        /// Thread routine for miners that cannot be scheduled to stop and need speed data read from command line
        /// </summary>
        /// <param name="commandLine"></param>
        /// <param name="benchmarkTimeWait"></param>
        protected void BenchmarkThreadRoutineAlternate(object commandLine, int benchmarkTimeWait)
        {
            CleanAllOldLogs();

            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

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

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                Helpers.ConsolePrint(MinerTag(), "Benchmark should end in : " + benchmarkTimeWait + " seconds");
                BenchmarkHandle = BenchmarkStartProcess((string)commandLine);
                BenchmarkHandle.WaitForExit(benchmarkTimeWait + 2);
                var 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;
                var 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)
                    {
                        var 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;
                    }
                    // wait a second reduce CPU load
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;
                // find latest log file
                var latestLogFile = "";
                var dirInfo       = new DirectoryInfo(WorkingDirectory);
                foreach (var file in dirInfo.GetFiles("*_log.txt"))
                {
                    latestLogFile = file.Name;
                    break;
                }
                BenchmarkHandle.WaitForExit(10000);
                // read file log
                if (File.Exists(WorkingDirectory + latestLogFile))
                {
                    var lines = File.ReadAllLines(WorkingDirectory + latestLogFile);
                    ProcessBenchLinesAlternate(lines);
                }
                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #9
0
        protected override void BenchmarkThreadRoutine(object commandLine)
        {
            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;

            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS * 3); // increase wait for sgminer

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                BenchmarkHandle = BenchmarkStartProcess((string)commandLine);
                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;
                //while (true)
                //{
                //    var outdata = BenchmarkHandle.StandardOutput.ReadLine();

                //    BenchmarkOutputErrorDataReceivedImpl(outdata);
                //    // terminate process situations
                //    if (BenchmarkSignalQuit
                //        || BenchmarkSignalFinnished
                //        || BenchmarkSignalHanged
                //        || BenchmarkSignalTimedout
                //        || BenchmarkException != null)
                //    {
                //EndBenchmarkProcces();
                // this is safe in a benchmark

                var exited = BenchmarkHandle.WaitForExit((BenchmarkTimeoutInSeconds(BenchmarkTimeInSeconds) + 20) * 1000);

                if (!exited)
                {
                    KillSgminer();
                }

                if (BenchmarkSignalTimedout)
                {
                    throw new Exception("Benchmark timedout");
                }
                if (BenchmarkException != null)
                {
                    throw BenchmarkException;
                }
                if (BenchmarkSignalQuit)
                {
                    throw new Exception("Termined by user request");
                }
                if (BenchmarkSignalHanged || !exited)
                {
                    throw new Exception("SGMiner is not responding");
                }
                if (BenchmarkSignalFinnished)
                {
                    //break;
                }
                //    }
                //    else
                //    {
                //        // wait a second reduce CPU load
                //        Thread.Sleep(1000);
                //    }
                //}
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #10
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;

            try
            {
                Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
                Helpers.ConsolePrint(MinerTAG(), "Benchmark should end in : " + benchmarkTimeWait + " seconds");
                BenchmarkHandle = BenchmarkStartProcess((string)CommandLine);
                BenchmarkHandle.WaitForExit(benchmarkTimeWait + 2);
                Stopwatch _benchmarkTimer = new Stopwatch();
                _benchmarkTimer.Reset();
                _benchmarkTimer.Start();
                BenchmarkProcessStatus = BenchmarkProcessStatus.Running;
                bool keepRunning = true;
                while (keepRunning && IsActiveProcess(BenchmarkHandle.Id))
                {
                    if (_benchmarkTimer.Elapsed.TotalSeconds >= (benchmarkTimeWait + 2) ||
                        BenchmarkSignalQuit ||
                        BenchmarkSignalFinnished ||
                        BenchmarkSignalHanged ||
                        BenchmarkSignalTimedout ||
                        BenchmarkException != null)
                    {
                        string imageName = MinerExeName.Replace(".exe", "");
                        // maybe will have to KILL process
                        KillMinerBase(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);
                    }
                }
            }
            catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
            }
            finally
            {
                BenchmarkAlgorithm.BenchmarkSpeed = 0;
                // find latest log file
                Thread.Sleep(1000);
                string latestLogFile = "";
                var    dirInfo       = new DirectoryInfo(WorkingDirectory);
                foreach (var file in dirInfo.GetFiles("*_log.txt"))
                {
                    latestLogFile = file.Name;
                    break;
                }
                // read file log
                if (File.Exists(WorkingDirectory + latestLogFile))
                {
                    var lines     = new string[0];
                    var read      = false;
                    var iteration = 0;
                    while (!read)
                    {
                        if (iteration < 10)
                        {
                            try
                            {
                                lines = File.ReadAllLines(WorkingDirectory + latestLogFile);
                                read  = true;
                                Helpers.ConsolePrint(MinerTAG(), "Successfully read log after " + iteration.ToString() + " iterations");
                            }
                            catch (Exception ex)
                            {
                                Helpers.ConsolePrint(MinerTAG(), ex.Message);
                                Thread.Sleep(1000);
                            }
                            iteration++;
                        }
                        else
                        {
                            read = true;  // Give up after 10s
                            Helpers.ConsolePrint(MinerTAG(), "Gave up on iteration " + iteration.ToString());
                        }
                    }

                    var addBenchLines = bench_lines.Count == 0;
                    foreach (var line in lines)
                    {
                        if (line != null)
                        {
                            bench_lines.Add(line);
                            string lineLowered = line.ToLower();
                            if (lineLowered.Contains(LOOK_FOR_START))
                            {
                                benchmark_sum += GetNumber(lineLowered);
                                ++benchmark_read_count;
                            }
                        }
                    }
                    if (benchmark_read_count > 0)
                    {
                        BenchmarkAlgorithm.BenchmarkSpeed = benchmark_sum / benchmark_read_count;
                    }
                }
                BenchmarkThreadRoutineFinish();
            }
        }
コード例 #11
0
        protected override void BenchmarkThreadRoutine(object commandLine)
        {
            BenchmarkSignalQuit      = false;
            BenchmarkSignalHanged    = false;
            BenchmarkSignalFinnished = false;
            BenchmarkException       = null;


            Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);

            Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
            Helpers.ConsolePrint(MinerTAG(), "Benchmark should end in : " + _benchmarkTimeWait + " seconds");

            BenchmarkHandle = BenchmarkStartProcess((string)commandLine);
            BenchmarkHandle.WaitForExit(_benchmarkTimeWait + 2);

            var benchmarkTimer = new Stopwatch();

            benchmarkTimer.Reset();
            benchmarkTimer.Start();
            BenchmarkProcessStatus = BenchmarkProcessStatus.Running;

            var           keepRunning = true;
            List <double> speed       = new List <double>();

            try
            {
                while (keepRunning && IsActiveProcess(BenchmarkHandle.Id))
                {
                    Task <APIData> AD = GetSummaryAsync();
                    Task.WaitAll(AD);

                    speed.Add(AD.Result.Speed);

                    //string outdata = BenchmarkHandle.StandardOutput.ReadLine();
                    //BenchmarkOutputErrorDataReceivedImpl(outdata);
                    // terminate process situations
                    if (benchmarkTimer.Elapsed.TotalSeconds >= (_benchmarkTimeWait + 2) ||
                        BenchmarkSignalQuit ||
                        BenchmarkSignalFinnished ||
                        BenchmarkSignalHanged ||
                        BenchmarkSignalTimedout ||
                        BenchmarkException != null)
                    {
                        var imageName = MinerExeName.Replace(".exe", "");
                        // maybe will have to KILL process
                        KillMinerBase(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;
                    }

                    // wait a second reduce CPU load
                    Thread.Sleep(1000);
                }
            }catch (Exception ex)
            {
                BenchmarkThreadRoutineCatch(ex);
                Helpers.ConsolePrint("Benchmark Error:", " " + ex.ToString());
            }
            finally
            {
                if (speed.Count == 0)
                {
                    Helpers.ConsolePrint("Benchmark Error:", " Benchmarks returned 0");
                }
                else
                {
                    BenchmarkAlgorithm.BenchmarkSpeed = 0;
                    BenchmarkAlgorithm.BenchmarkSpeed = speed.Average();
                }
                BenchmarkThreadRoutineFinish();
            }
        }