private string CreateCommandLine(string username) { // API port function might be blocking _apiPort = GetAvaliablePort(); // instant non blocking var url = StratumServiceHelpers.GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP); var algo = PluginSupportedAlgorithms.AlgorithmName(_algorithmType); var commandLine = $"--algo={algo} --url={url} --user={username} --api-bind={_apiPort} {_extraLaunchParameters}"; return(commandLine); }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { var benchmarkTime = MinerPluginToolkitV1.Configs.MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 20, 60, 120 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); // in seconds var algo = PluginSupportedAlgorithms.AlgorithmName(_algorithmType); var commandLine = $"--algo={algo} --benchmark --time-limit {benchmarkTime} {_extraLaunchParameters}"; var binPathBinCwdPair = GetBinAndCwdPaths(); var binPath = binPathBinCwdPair.Item1; var binCwd = binPathBinCwdPair.Item2; Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}"); var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables()); double benchHashesSum = 0; double benchHashResult = 0; int benchIters = 0; var foundBench = false; bp.CheckData = (string data) => { if (!data.Contains("Total:")) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, 0) }, Success = false } } ; var hashrateFoundPairAvg = MinerToolkit.TryGetHashrateAfter(data, "H, "); var hashrateAvg = hashrateFoundPairAvg.Item1; var foundAvg = hashrateFoundPairAvg.Item2; if (!foundAvg) { var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark: "); var hashrate = hashrateFoundPair.Item1; foundBench = hashrateFoundPair.Item2; if (foundBench && hashrate != 0) { benchHashResult = hashrate * (1 - DevFee * 0.01); return(new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = benchHashResult != 0 }); } } // sum and return benchHashesSum += hashrateAvg; benchIters++; benchHashResult = (benchHashesSum / benchIters) * (1 - DevFee * 0.01); return(new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = foundBench }); }; var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); return(await t); }