// TODO add cancel token protected async Task <Tuple <bool, IEnumerable <string> > > CreateConfigFiles(IEnumerable <DeviceType> deviceTypes, CancellationToken stop) { //var tag = string.Join("_", _miningPairs.Select(pair => $"{pair.Device.DeviceType.ToString()}_{pair.Device.ID}")); //var genPrefix = $"gen_{_algorithmType.ToString()}_{tag}"; var genPrefix = $"gen_{_algorithmType.ToString()}_{_rand.Next().ToString()}"; var deviceTypeIDs = _miningPairs.Select(pair => Tuple.Create(pair.Device.DeviceType, pair.Device.ID)); var enableDeviceFlagsConfigFiles = CommandLineHelpers.GetConfigCmd(genPrefix, deviceTypeIDs); var enableDeviceTypesStr = string.Join(" ", enableDeviceFlagsConfigFiles.Select(pair => $"{pair.Item1} {pair.Item2}")); var configFlagAndFiles = CommandLineHelpers.GetGeneralAndPoolsConf(genPrefix); var configFlagAndFilesStr = string.Join(" ", configFlagAndFiles); // instant non blocking var url = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.NONE); var disableDeviceTypes = CommandLineHelpers.DisableDevCmd(deviceTypes); var currency = AlgorithmName(_algorithmType); var commandLine = $"-o {url} -u {MinerToolkit.DemoUserBTC} --currency {currency} -i 0 --use-nicehash -p x -r x --benchmark 10 --benchwork 60 --benchwait 5 {disableDeviceTypes} {enableDeviceTypesStr} {configFlagAndFilesStr}"; var binPathBinCwdPair = GetBinAndCwdPaths(); var binPath = binPathBinCwdPair.Item1; var binCwd = binPathBinCwdPair.Item2; var envVars = GetEnvironmentVariables(); var configs = enableDeviceFlagsConfigFiles.Select(p => p.Item2); var success = await ConfigHelpers.CreateConfigFiles(configs, binPath, binCwd, commandLine, envVars, stop); var configsFullPath = configs.Select(path => Path.Combine(binCwd, path)); var deleteFiles = Directory.GetFiles(binCwd, "*.*", SearchOption.TopDirectoryOnly).Where(p => p.Contains(genPrefix) && p.Contains("conf")); foreach (var delete in deleteFiles) { try { File.Delete(Path.Combine(binCwd, delete)); } catch (Exception) {} } return(Tuple.Create(success, configsFullPath)); }
// TODO account AMD kernel building public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { // END prepare config block // determine benchmark time // settup times var openCLCodeGenerationWait = _miningDeviceTypes.Contains(DeviceType.AMD) ? 20 : 0; var benchWait = 5; var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 30, 60, 120 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); // in seconds var url = StratumServiceHelpers.GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP); var algo = AlgorithmName(_algorithmType); // this one here might block string deviceConfigParams = ""; try { deviceConfigParams = await PrepareDeviceConfigs(stop); } catch (Exception e) { return(new BenchmarkResult { ErrorMessage = e.Message }); } var disableDeviceTypes = CommandLineHelpers.DisableDevCmd(_miningDeviceTypes); var binPathBinCwdPair = GetBinAndCwdPaths(); var binPath = binPathBinCwdPair.Item1; var binCwd = binPathBinCwdPair.Item2; // API port function might be blocking var apiPort = GetAvaliablePort(); var commandLine = $"-o {url} -u {MinerToolkit.DemoUserBTC} --currency {algo} -i {apiPort} --use-nicehash -p x -r x --benchmark 10 --benchwork {benchmarkTime} --benchwait {benchWait} {deviceConfigParams} {disableDeviceTypes}"; Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}"); var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables()); var benchHashes = 0d; var benchIters = 0; var benchHashResult = 0d; // Not too sure what this is.. var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d)); bp.CheckData = (string data) => { var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark Total:"); var hashrate = hashrateFoundPair.Item1; var found = hashrateFoundPair.Item2; if (found) { benchHashes += hashrate; benchIters++; benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01); } return(new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = found }); }; // always add 10second extra var benchmarkTimeout = TimeSpan.FromSeconds(10 + benchmarkTime + benchWait + openCLCodeGenerationWait); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); return(await t); }