protected override void ProcessBenchLinesAlternate(string[] lines)
        {
            var benchSum   = 0d;
            var benchCount = 0;

            foreach (var line in lines)
            {
                BenchLines.Add(line);
                var lowered = line.ToLower();

                var start = lowered.IndexOf(LookForStart, StringComparison.Ordinal);
                if (start <= -1)
                {
                    continue;
                }
                lowered = lowered.Substring(start, lowered.Length - start);
                lowered = lowered.Replace(LookForStart, "");
                var end = lowered.IndexOf(LookForEnd, StringComparison.Ordinal);
                lowered = lowered.Substring(0, end);
                if (double.TryParse(lowered, out var speed))
                {
                    benchSum += speed;
                    benchCount++;
                }
            }

            BenchmarkAlgorithm.BenchmarkSpeed = (benchSum / Math.Max(1, benchCount)) * (1 - DevFee * 0.01);
        }
Exemple #2
0
        protected override void ProcessBenchLinesAlternate(string[] lines)
        {
            // Xmrig reports 2.5s and 60s averages, so prefer to use 60s values for benchmark
            // but fall back on 2.5s values if 60s time isn't hit
            var twoSecTotal   = 0d;
            var sixtySecTotal = 0d;
            var twoSecCount   = 0;
            var sixtySecCount = 0;

            foreach (var line in lines)
            {
                BenchLines.Add(line);
                var lineLowered = line.ToLower();
                if (lineLowered.Contains(_lookForStart.ToLower()))
                {
                    var speeds = Regex.Match(lineLowered, $"{_lookForStart.ToLower()} (.+?) {_lookForEnd.ToLower()}").Groups[1].Value.Split();

                    try
                    {
                        if (double.TryParse(speeds[1], out var sixtySecSpeed))
                        {
                            sixtySecTotal += sixtySecSpeed;
                            ++sixtySecCount;
                        }
                        else if (double.TryParse(speeds[0], out var twoSecSpeed))
                        {
                            // Store 2.5s data in case 60s is never reached
                            twoSecTotal += twoSecSpeed;
                            ++twoSecCount;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Unsupported miner version - " + MiningSetup.MinerPath,
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        BenchmarkSignalFinnished = true;
                        return;
                    }
                }
            }

            if (sixtySecCount > 0 && sixtySecTotal > 0)
            {
                // Run iff 60s averages are reported
                BenchmarkAlgorithm.BenchmarkSpeed = sixtySecTotal / sixtySecCount;
            }
            else if (twoSecCount > 0)
            {
                // Run iff no 60s averages are reported but 2.5s are
                BenchmarkAlgorithm.BenchmarkSpeed = twoSecTotal / twoSecCount;
            }
        }
Exemple #3
0
 protected override void ProcessBenchLinesAlternate(string[] lines)
 {
     foreach (var line in lines)
     {
         if (line != null)
         {
             BenchLines.Add(line);
             var lineLowered = line.ToLower();
             if (lineLowered.Contains(LookForStart))
             {
                 if (IgnoreZero)
                 {
                     var got = GetNumber(lineLowered);
                     if (got != 0)
                     {
                         _benchmarkSum += got;
                         ++_benchmarkReadCount;
                     }
                 }
                 else
                 {
                     _benchmarkSum += GetNumber(lineLowered);
                     ++_benchmarkReadCount;
                 }
             }
             else if (!string.IsNullOrEmpty(SecondaryLookForStart()) && lineLowered.Contains(SecondaryLookForStart()))
             {
                 if (IgnoreZero)
                 {
                     var got = GetNumber(lineLowered, SecondaryLookForStart(), LookForEnd);
                     if (got != 0)
                     {
                         _secondaryBenchmarkSum += got;
                         ++_secondaryBenchmarkReadCount;
                     }
                 }
                 else
                 {
                     _secondaryBenchmarkSum += GetNumber(lineLowered);
                     ++_secondaryBenchmarkReadCount;
                 }
             }
         }
     }
     if (_benchmarkReadCount > 0)
     {
         BenchmarkAlgorithm.BenchmarkSpeed          = _benchmarkSum / _benchmarkReadCount;
         BenchmarkAlgorithm.SecondaryBenchmarkSpeed = _secondaryBenchmarkSum / _secondaryBenchmarkReadCount;
     }
 }
        protected override void ProcessBenchLinesAlternate(string[] lines)
        {
            foreach (var line in lines)
            {
                if (line != null)
                {
                    BenchLines.Add(line);
                    var lineLowered = line.ToLower();
                    BenchmarkParseLine(lineLowered);
                    if (lineLowered.Contains(LookForStart))
                    {
                        var got = GetNumber(lineLowered);
                        if (!IgnoreZero || got > 0)
                        {
                            _benchmarkSum += got;
                            ++_benchmarkReadCount;
                        }
                    }
                    else if (!string.IsNullOrEmpty(SecondaryLookForStart) &&
                             lineLowered.Contains(SecondaryLookForStart))
                    {
                        var got = GetNumber(lineLowered, SecondaryLookForStart, LookForEnd);
                        if (IgnoreZero || got > 0)
                        {
                            _secondaryBenchmarkSum += got;
                            ++_secondaryBenchmarkReadCount;
                        }
                    }
                }
            }

            if (_benchmarkReadCount > 0)
            {
                var speed = _benchmarkSum / _benchmarkReadCount;
                BenchmarkAlgorithm.BenchmarkSpeed = speed;
                if (BenchmarkAlgorithm is DualAlgorithm dualBenchAlgo)
                {
                    var secondarySpeed = _secondaryBenchmarkSum / Math.Max(1, _secondaryBenchmarkReadCount);
                    if (dualBenchAlgo.TuningEnabled)
                    {
                        dualBenchAlgo.SetIntensitySpeedsForCurrent(speed, secondarySpeed);
                    }
                    else
                    {
                        dualBenchAlgo.SecondaryBenchmarkSpeed = secondarySpeed;
                    }
                }
            }
        }
Exemple #5
0
        protected override void ProcessBenchLinesAlternate(string[] lines)
        {
            // Xmrig reports 2.5s and 60s averages, so prefer to use 60s values for benchmark
            // but fall back on 2.5s values if 60s time isn't hit
            var twoSecTotal   = 0d;
            var sixtySecTotal = 0d;
            var twoSecCount   = 0;
            var sixtySecCount = 0;

            foreach (var line in lines)
            {
                BenchLines.Add(line);
                var lineLowered = line.ToLower();
                if (!lineLowered.Contains(LookForStart))
                {
                    continue;
                }
                var speeds = Regex.Match(lineLowered, $"{LookForStart} (.+?) {LookForEnd}").Groups[1].Value.Split();
                if (double.TryParse(speeds[1], out var sixtySecSpeed))
                {
                    sixtySecTotal += sixtySecSpeed;
                    ++sixtySecCount;
                }
                else if (double.TryParse(speeds[0], out var twoSecSpeed))
                {
                    // Store 2.5s data in case 60s is never reached
                    twoSecTotal += twoSecSpeed;
                    ++twoSecCount;
                }
            }

            if (sixtySecCount > 0 && sixtySecTotal > 0)
            {
                // Run iff 60s averages are reported
                BenchmarkAlgorithm.BenchmarkSpeed = sixtySecTotal / sixtySecCount;
            }
            else if (twoSecCount > 0)
            {
                // Run iff no 60s averages are reported but 2.5s are
                BenchmarkAlgorithm.BenchmarkSpeed = twoSecTotal / twoSecCount;
            }
        }
        protected override void ProcessBenchLinesAlternate(string[] lines)
        {
            foreach (var line in lines)
            {
                Helpers.ConsolePrint(MinerTag(), line);
                BenchLines.Add(line);
                var lineLowered = line.ToLower();

                if (lineLowered.Contains("Total:".ToLower()))
                {
                    var st    = lineLowered.IndexOf("Total: ".ToLower());
                    var e     = lineLowered.IndexOf("/s".ToLower());
                    var parse = lineLowered.Substring(st + 7, e - st - 9).Trim().Replace(",", ".");
                    try
                    {
                        speed = Double.Parse(parse, CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        MessageBox.Show("Unsupported miner version - " + MiningSetup.MinerPath,
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        BenchmarkSignalFinnished = true;
                    }

                    if (lineLowered.Contains("kh/s"))
                    {
                        speed *= 1000;
                    }
                    else if (lineLowered.Contains("mh/s"))
                    {
                        speed *= 1000000;
                    }

                    BenchmarkAlgorithm.BenchmarkSpeed = speed;
                }
            }
        }
        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();
            }
        }
Exemple #8
0
        protected override void ProcessBenchLinesAlternate(string[] lines)
        {
            var twoSecTotal   = 0d;
            var sixtySecTotal = 0d;
            var twoSecCount   = 0;
            var sixtySecCount = 0;

            foreach (var line in lines)
            {
                BenchLines.Add(line);
                var lineLowered = line.ToLower();
                if (lineLowered.Contains(_lookForStart.ToLower()))
                {
                    /*
                     * var speeds = Regex.Match(lineLowered, $"{_lookForStart.ToLower()} (.+?) {_lookForEnd.ToLower()}").Groups[1].Value.Split();
                     */
                    var speedStart = lineLowered.IndexOf(_lookForStart);
                    var speed      = lineLowered.Substring(speedStart, lineLowered.Length - speedStart);
                    speed = speed.Replace(_lookForStart, "");
                    speed = speed.Substring(0, speed.IndexOf(_lookForEnd));
                    if (count >= 8 || (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.Lyra2REv3) && count >= 4)) //пропустить первые 8
                    {
                        try
                        {
                            if (double.TryParse(speed, out var sixtySecSpeed))
                            {
                                sixtySecTotal += sixtySecSpeed;
                                ++sixtySecCount;
                            }

                            /*
                             * if (double.TryParse(speeds[1], out var sixtySecSpeed)) {
                             * sixtySecTotal += sixtySecSpeed;
                             ++sixtySecCount;
                             * } else if (double.TryParse(speeds[0], out var twoSecSpeed)) {
                             * // Store 2.5s data in case 60s is never reached
                             * twoSecTotal += twoSecSpeed;
                             ++twoSecCount;
                             * }
                             */
                        }

                        catch
                        {
                            MessageBox.Show("Unsupported miner version - " + MiningSetup.MinerPath,
                                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            BenchmarkSignalFinnished = true;
                            return;
                        }
                    }
                    count++;
                }
            }

            if (sixtySecCount > 0 && sixtySecTotal > 0)
            {
                // Run iff 60s averages are reported
                BenchmarkAlgorithm.BenchmarkSpeed = (sixtySecTotal / sixtySecCount) * 1000;
            }
            else if (twoSecCount > 0)
            {
                // Run iff no 60s averages are reported but 2.5s are
                BenchmarkAlgorithm.BenchmarkSpeed = (twoSecTotal / twoSecCount) * 1000;
            }
        }